![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
Dependencies: mbed SDFileSystem
main.cpp@2:514cf0e05a63, 2010-07-08 (annotated)
- Committer:
- nucho
- Date:
- Thu Jul 08 05:19:52 2010 +0000
- Revision:
- 2:514cf0e05a63
- Parent:
- 1:d2f06e666bc9
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:061ea0ce0fd7 | 1 | #include "mbed.h" |
nucho | 0:061ea0ce0fd7 | 2 | #include "SDFileSystem.h" |
nucho | 0:061ea0ce0fd7 | 3 | |
nucho | 0:061ea0ce0fd7 | 4 | #define DATA_SIZE 128*128 |
nucho | 0:061ea0ce0fd7 | 5 | |
nucho | 0:061ea0ce0fd7 | 6 | SDFileSystem sd(p5, p6, p7, p8, "sd");// mosi, miso, sclk, cs, name |
nucho | 0:061ea0ce0fd7 | 7 | |
nucho | 0:061ea0ce0fd7 | 8 | DigitalOut CS(p21); |
nucho | 0:061ea0ce0fd7 | 9 | DigitalOut A0(p22); |
nucho | 0:061ea0ce0fd7 | 10 | DigitalOut E(p23); |
nucho | 0:061ea0ce0fd7 | 11 | DigitalOut WRB(p24); |
nucho | 0:061ea0ce0fd7 | 12 | DigitalOut RES(p25); |
nucho | 0:061ea0ce0fd7 | 13 | |
nucho | 0:061ea0ce0fd7 | 14 | BusOut P1(p10, p11, p12, p13, p14, p15, p16, p17); |
nucho | 0:061ea0ce0fd7 | 15 | |
nucho | 0:061ea0ce0fd7 | 16 | Timer t; |
nucho | 0:061ea0ce0fd7 | 17 | |
nucho | 0:061ea0ce0fd7 | 18 | void WriteCOM(unsigned char a) { |
nucho | 0:061ea0ce0fd7 | 19 | CS=0; |
nucho | 0:061ea0ce0fd7 | 20 | E=1; |
nucho | 0:061ea0ce0fd7 | 21 | A0=0; |
nucho | 0:061ea0ce0fd7 | 22 | P1=a; |
nucho | 0:061ea0ce0fd7 | 23 | WRB=0; |
nucho | 0:061ea0ce0fd7 | 24 | WRB=1; |
nucho | 0:061ea0ce0fd7 | 25 | CS=1; |
nucho | 0:061ea0ce0fd7 | 26 | } |
nucho | 0:061ea0ce0fd7 | 27 | |
nucho | 0:061ea0ce0fd7 | 28 | void WriteDAT(unsigned char b) { |
nucho | 0:061ea0ce0fd7 | 29 | CS=0; |
nucho | 0:061ea0ce0fd7 | 30 | E=1; |
nucho | 0:061ea0ce0fd7 | 31 | A0=1; |
nucho | 0:061ea0ce0fd7 | 32 | P1=b; |
nucho | 0:061ea0ce0fd7 | 33 | WRB=0; |
nucho | 0:061ea0ce0fd7 | 34 | WRB=1; |
nucho | 0:061ea0ce0fd7 | 35 | CS=1; |
nucho | 0:061ea0ce0fd7 | 36 | } |
nucho | 0:061ea0ce0fd7 | 37 | |
nucho | 0:061ea0ce0fd7 | 38 | void init_lcd(void) { |
nucho | 0:061ea0ce0fd7 | 39 | RES=1; |
nucho | 0:061ea0ce0fd7 | 40 | wait_ms(100); |
nucho | 0:061ea0ce0fd7 | 41 | RES=0; |
nucho | 0:061ea0ce0fd7 | 42 | wait_ms(100); |
nucho | 0:061ea0ce0fd7 | 43 | RES=1; |
nucho | 0:061ea0ce0fd7 | 44 | wait_ms(120); |
nucho | 0:061ea0ce0fd7 | 45 | |
nucho | 0:061ea0ce0fd7 | 46 | WriteCOM(0x01); |
nucho | 0:061ea0ce0fd7 | 47 | wait_ms(50); |
nucho | 0:061ea0ce0fd7 | 48 | |
nucho | 0:061ea0ce0fd7 | 49 | WriteCOM(0x11);//SLEEP OUT |
nucho | 0:061ea0ce0fd7 | 50 | wait_ms(200); |
nucho | 0:061ea0ce0fd7 | 51 | |
nucho | 0:061ea0ce0fd7 | 52 | WriteCOM(0xFF); |
nucho | 0:061ea0ce0fd7 | 53 | WriteDAT(0x40); |
nucho | 0:061ea0ce0fd7 | 54 | WriteDAT(0x03); |
nucho | 0:061ea0ce0fd7 | 55 | WriteDAT(0x1A); |
nucho | 0:061ea0ce0fd7 | 56 | |
nucho | 0:061ea0ce0fd7 | 57 | WriteCOM(0xd9); |
nucho | 0:061ea0ce0fd7 | 58 | WriteDAT(0x60); |
nucho | 0:061ea0ce0fd7 | 59 | WriteCOM(0xc7); |
nucho | 0:061ea0ce0fd7 | 60 | WriteDAT(0x90); |
nucho | 0:061ea0ce0fd7 | 61 | wait_ms(200); |
nucho | 0:061ea0ce0fd7 | 62 | |
nucho | 0:061ea0ce0fd7 | 63 | WriteCOM(0xB1); |
nucho | 0:061ea0ce0fd7 | 64 | WriteDAT(0x04); |
nucho | 0:061ea0ce0fd7 | 65 | WriteDAT(0x25); |
nucho | 0:061ea0ce0fd7 | 66 | WriteDAT(0x18); |
nucho | 0:061ea0ce0fd7 | 67 | |
nucho | 0:061ea0ce0fd7 | 68 | WriteCOM(0xB2); |
nucho | 0:061ea0ce0fd7 | 69 | WriteDAT(0x04); |
nucho | 0:061ea0ce0fd7 | 70 | WriteDAT(0x25); |
nucho | 0:061ea0ce0fd7 | 71 | WriteDAT(0x18); |
nucho | 0:061ea0ce0fd7 | 72 | |
nucho | 0:061ea0ce0fd7 | 73 | WriteCOM(0xB3); |
nucho | 0:061ea0ce0fd7 | 74 | WriteDAT(0x04); |
nucho | 0:061ea0ce0fd7 | 75 | WriteDAT(0x25); |
nucho | 0:061ea0ce0fd7 | 76 | WriteDAT(0x18); |
nucho | 0:061ea0ce0fd7 | 77 | WriteDAT(0x04); |
nucho | 0:061ea0ce0fd7 | 78 | WriteDAT(0x25); |
nucho | 0:061ea0ce0fd7 | 79 | WriteDAT(0x18); |
nucho | 0:061ea0ce0fd7 | 80 | |
nucho | 0:061ea0ce0fd7 | 81 | WriteCOM(0xB4); |
nucho | 0:061ea0ce0fd7 | 82 | WriteDAT(0x03); |
nucho | 0:061ea0ce0fd7 | 83 | |
nucho | 0:061ea0ce0fd7 | 84 | WriteCOM(0xB6); |
nucho | 0:061ea0ce0fd7 | 85 | WriteDAT(0x15); |
nucho | 0:061ea0ce0fd7 | 86 | WriteDAT(0x02); |
nucho | 0:061ea0ce0fd7 | 87 | |
nucho | 0:061ea0ce0fd7 | 88 | WriteCOM(0xC0);// POWER CONTROL 1 GVDD&VCI1 |
nucho | 0:061ea0ce0fd7 | 89 | WriteDAT(0x02); |
nucho | 0:061ea0ce0fd7 | 90 | WriteDAT(0x70); |
nucho | 0:061ea0ce0fd7 | 91 | |
nucho | 0:061ea0ce0fd7 | 92 | WriteCOM(0xC1);// POWER CONTROL 2 GVDD&VCI1 |
nucho | 0:061ea0ce0fd7 | 93 | WriteDAT(0x07); |
nucho | 0:061ea0ce0fd7 | 94 | |
nucho | 0:061ea0ce0fd7 | 95 | WriteCOM(0xC2);// POWER CONTROL 3 GVDD&VCI1 |
nucho | 0:061ea0ce0fd7 | 96 | WriteDAT(0x01); |
nucho | 0:061ea0ce0fd7 | 97 | WriteDAT(0x01); |
nucho | 0:061ea0ce0fd7 | 98 | |
nucho | 0:061ea0ce0fd7 | 99 | WriteCOM(0xC3);// POWER CONTROL 4 GVDD&VCI1 |
nucho | 0:061ea0ce0fd7 | 100 | WriteDAT(0x02); |
nucho | 0:061ea0ce0fd7 | 101 | WriteDAT(0x07); |
nucho | 0:061ea0ce0fd7 | 102 | |
nucho | 0:061ea0ce0fd7 | 103 | WriteCOM(0xC4);// POWER CONTROL 5 GVDD&VCI1 |
nucho | 0:061ea0ce0fd7 | 104 | WriteDAT(0x02); |
nucho | 0:061ea0ce0fd7 | 105 | WriteDAT(0x04); |
nucho | 0:061ea0ce0fd7 | 106 | |
nucho | 0:061ea0ce0fd7 | 107 | WriteCOM(0xFC);// POWER CONTROL 6 GVDD&VCI1 |
nucho | 0:061ea0ce0fd7 | 108 | WriteDAT(0x11); |
nucho | 0:061ea0ce0fd7 | 109 | WriteDAT(0x17); |
nucho | 0:061ea0ce0fd7 | 110 | |
nucho | 0:061ea0ce0fd7 | 111 | WriteCOM(0xC5);//VCOMH&VCOML |
nucho | 0:061ea0ce0fd7 | 112 | WriteDAT(0x3c); |
nucho | 0:061ea0ce0fd7 | 113 | WriteDAT(0x4f); |
nucho | 0:061ea0ce0fd7 | 114 | |
nucho | 0:061ea0ce0fd7 | 115 | WriteCOM(0x36);//MV,MX,MY,RGB |
nucho | 0:061ea0ce0fd7 | 116 | WriteDAT(0x88); |
nucho | 0:061ea0ce0fd7 | 117 | |
nucho | 0:061ea0ce0fd7 | 118 | |
nucho | 0:061ea0ce0fd7 | 119 | WriteCOM(0x3a);//GAMMA SET BY REGISTER |
nucho | 0:061ea0ce0fd7 | 120 | WriteDAT(0x05); |
nucho | 0:061ea0ce0fd7 | 121 | |
nucho | 0:061ea0ce0fd7 | 122 | //***********************GAMMA************************* |
nucho | 0:061ea0ce0fd7 | 123 | WriteCOM(0xE0); |
nucho | 0:061ea0ce0fd7 | 124 | WriteDAT(0x06); |
nucho | 0:061ea0ce0fd7 | 125 | WriteDAT(0x0E); |
nucho | 0:061ea0ce0fd7 | 126 | WriteDAT(0x05); |
nucho | 0:061ea0ce0fd7 | 127 | WriteDAT(0x20); |
nucho | 0:061ea0ce0fd7 | 128 | WriteDAT(0x27); |
nucho | 0:061ea0ce0fd7 | 129 | WriteDAT(0x23); |
nucho | 0:061ea0ce0fd7 | 130 | WriteDAT(0x1C); |
nucho | 0:061ea0ce0fd7 | 131 | WriteDAT(0x21); |
nucho | 0:061ea0ce0fd7 | 132 | WriteDAT(0x20); |
nucho | 0:061ea0ce0fd7 | 133 | WriteDAT(0x1C); |
nucho | 0:061ea0ce0fd7 | 134 | WriteDAT(0x26); |
nucho | 0:061ea0ce0fd7 | 135 | WriteDAT(0x2F); |
nucho | 0:061ea0ce0fd7 | 136 | WriteDAT(0x00); |
nucho | 0:061ea0ce0fd7 | 137 | WriteDAT(0x03); |
nucho | 0:061ea0ce0fd7 | 138 | WriteDAT(0x00); |
nucho | 0:061ea0ce0fd7 | 139 | WriteDAT(0x24); |
nucho | 0:061ea0ce0fd7 | 140 | |
nucho | 0:061ea0ce0fd7 | 141 | WriteCOM(0xE1); |
nucho | 0:061ea0ce0fd7 | 142 | WriteDAT(0x06); |
nucho | 0:061ea0ce0fd7 | 143 | WriteDAT(0x10); |
nucho | 0:061ea0ce0fd7 | 144 | WriteDAT(0x05); |
nucho | 0:061ea0ce0fd7 | 145 | WriteDAT(0x21); |
nucho | 0:061ea0ce0fd7 | 146 | WriteDAT(0x27); |
nucho | 0:061ea0ce0fd7 | 147 | WriteDAT(0x22); |
nucho | 0:061ea0ce0fd7 | 148 | WriteDAT(0x1C); |
nucho | 0:061ea0ce0fd7 | 149 | WriteDAT(0x21); |
nucho | 0:061ea0ce0fd7 | 150 | WriteDAT(0x1F); |
nucho | 0:061ea0ce0fd7 | 151 | WriteDAT(0x1D); |
nucho | 0:061ea0ce0fd7 | 152 | WriteDAT(0x27); |
nucho | 0:061ea0ce0fd7 | 153 | WriteDAT(0x2F); |
nucho | 0:061ea0ce0fd7 | 154 | WriteDAT(0x05); |
nucho | 0:061ea0ce0fd7 | 155 | WriteDAT(0x03); |
nucho | 0:061ea0ce0fd7 | 156 | WriteDAT(0x00); |
nucho | 0:061ea0ce0fd7 | 157 | WriteDAT(0x3F); |
nucho | 0:061ea0ce0fd7 | 158 | |
nucho | 0:061ea0ce0fd7 | 159 | //***************************RAM ADDRESS******************* |
nucho | 0:061ea0ce0fd7 | 160 | WriteCOM(0x2A); |
nucho | 0:061ea0ce0fd7 | 161 | WriteDAT(0x00); |
nucho | 0:061ea0ce0fd7 | 162 | WriteDAT(0x02); |
nucho | 0:061ea0ce0fd7 | 163 | WriteDAT(0x00); |
nucho | 0:061ea0ce0fd7 | 164 | WriteDAT(0x81); |
nucho | 0:061ea0ce0fd7 | 165 | |
nucho | 0:061ea0ce0fd7 | 166 | WriteCOM(0x2B); |
nucho | 0:061ea0ce0fd7 | 167 | WriteDAT(0x00); |
nucho | 0:061ea0ce0fd7 | 168 | WriteDAT(0x03); |
nucho | 0:061ea0ce0fd7 | 169 | WriteDAT(0x00); |
nucho | 0:061ea0ce0fd7 | 170 | WriteDAT(0x82); |
nucho | 0:061ea0ce0fd7 | 171 | |
nucho | 0:061ea0ce0fd7 | 172 | WriteCOM(0x29); |
nucho | 0:061ea0ce0fd7 | 173 | wait_ms(100); |
nucho | 0:061ea0ce0fd7 | 174 | |
nucho | 0:061ea0ce0fd7 | 175 | WriteCOM(0x2C); |
nucho | 0:061ea0ce0fd7 | 176 | } |
nucho | 0:061ea0ce0fd7 | 177 | |
nucho | 0:061ea0ce0fd7 | 178 | int main() { |
nucho | 0:061ea0ce0fd7 | 179 | FILE *fpi; |
nucho | 0:061ea0ce0fd7 | 180 | int i; |
nucho | 0:061ea0ce0fd7 | 181 | unsigned char idat; |
nucho | 0:061ea0ce0fd7 | 182 | unsigned char dat,dat2; |
nucho | 0:061ea0ce0fd7 | 183 | |
nucho | 0:061ea0ce0fd7 | 184 | init_lcd(); |
nucho | 0:061ea0ce0fd7 | 185 | |
nucho | 0:061ea0ce0fd7 | 186 | if ((fpi=fopen("/sd/sample.bmp", "rb")) == NULL) { |
nucho | 2:514cf0e05a63 | 187 | fprintf(stderr, "input file open error\n"); |
nucho | 0:061ea0ce0fd7 | 188 | exit(1); |
nucho | 0:061ea0ce0fd7 | 189 | } |
nucho | 0:061ea0ce0fd7 | 190 | |
nucho | 0:061ea0ce0fd7 | 191 | for (i=0;i<0x36;i++)//bitmap headder throw |
nucho | 0:061ea0ce0fd7 | 192 | fread(&idat, sizeof(unsigned char), 1, fpi); |
nucho | 0:061ea0ce0fd7 | 193 | |
nucho | 0:061ea0ce0fd7 | 194 | for (i=0; i<DATA_SIZE; i++) { |
nucho | 0:061ea0ce0fd7 | 195 | fread(&dat, sizeof(unsigned char), 1, fpi); |
nucho | 0:061ea0ce0fd7 | 196 | fread(&dat2, sizeof(unsigned char), 1, fpi); |
nucho | 0:061ea0ce0fd7 | 197 | |
nucho | 0:061ea0ce0fd7 | 198 | dat2 = (dat2 << 1) | (dat >> 7); |
nucho | 0:061ea0ce0fd7 | 199 | dat = ((dat & 0x60) << 1) | (dat & 0x1F); |
nucho | 0:061ea0ce0fd7 | 200 | |
nucho | 0:061ea0ce0fd7 | 201 | WriteDAT(dat2); |
nucho | 0:061ea0ce0fd7 | 202 | WriteDAT(dat); |
nucho | 0:061ea0ce0fd7 | 203 | } |
nucho | 1:d2f06e666bc9 | 204 | fclose(fpi); |
nucho | 0:061ea0ce0fd7 | 205 | } |