student project
Dependencies: mbed
Fork of myiot by
I2C_SSD1306Z.cpp@5:f6a5fc6e1ddd, 2016-06-23 (annotated)
- Committer:
- William_HO
- Date:
- Thu Jun 23 05:17:36 2016 +0000
- Revision:
- 5:f6a5fc6e1ddd
- Parent:
- 0:94c1a94c5a47
Added an IAP example to read device ID and serial number.; For feature implement.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ittraining | 0:94c1a94c5a47 | 1 | // |
ittraining | 0:94c1a94c5a47 | 2 | // SSD1306Z LCD Driver: 0.96" lcd LY096BG30 |
ittraining | 0:94c1a94c5a47 | 3 | // |
ittraining | 0:94c1a94c5a47 | 4 | // Interface: I2C |
ittraining | 0:94c1a94c5a47 | 5 | // pin1: Vcc |
ittraining | 0:94c1a94c5a47 | 6 | // pin2: Gnd |
ittraining | 0:94c1a94c5a47 | 7 | // pin3: SCL |
ittraining | 0:94c1a94c5a47 | 8 | // pin4: SDA |
ittraining | 0:94c1a94c5a47 | 9 | |
ittraining | 0:94c1a94c5a47 | 10 | #include "mbed.h" |
ittraining | 0:94c1a94c5a47 | 11 | #include "I2C_SSD1306Z.h" |
ittraining | 0:94c1a94c5a47 | 12 | #include "Font8x16.h" |
ittraining | 0:94c1a94c5a47 | 13 | #include "Font5x7.h" |
ittraining | 0:94c1a94c5a47 | 14 | |
ittraining | 0:94c1a94c5a47 | 15 | |
ittraining | 0:94c1a94c5a47 | 16 | //I2C i2c(I2C_SDA, I2C_SCL); |
ittraining | 0:94c1a94c5a47 | 17 | extern I2C i2c; |
ittraining | 0:94c1a94c5a47 | 18 | |
ittraining | 0:94c1a94c5a47 | 19 | char DisplayBuffer[128*8]; |
ittraining | 0:94c1a94c5a47 | 20 | |
ittraining | 0:94c1a94c5a47 | 21 | #if 1 |
ittraining | 0:94c1a94c5a47 | 22 | |
ittraining | 0:94c1a94c5a47 | 23 | void lcdWriteCommand(uint8_t lcd_Command) |
ittraining | 0:94c1a94c5a47 | 24 | { |
ittraining | 0:94c1a94c5a47 | 25 | |
ittraining | 0:94c1a94c5a47 | 26 | char data[2]; |
ittraining | 0:94c1a94c5a47 | 27 | data[0]=0x0; |
ittraining | 0:94c1a94c5a47 | 28 | data[1]=lcd_Command; |
ittraining | 0:94c1a94c5a47 | 29 | // I2C_writeBytes(LCD_I2C_PORT, LCD_I2C_SLA, 0x00, 1, data); |
ittraining | 0:94c1a94c5a47 | 30 | // i2c_write_data_block(LCD_I2C_SLA, 0x00, data,1); |
ittraining | 0:94c1a94c5a47 | 31 | i2c.write(LCD_I2C_SLA, data, 2, 0); |
ittraining | 0:94c1a94c5a47 | 32 | |
ittraining | 0:94c1a94c5a47 | 33 | } |
ittraining | 0:94c1a94c5a47 | 34 | |
ittraining | 0:94c1a94c5a47 | 35 | void lcdWriteData(uint8_t lcd_Data) |
ittraining | 0:94c1a94c5a47 | 36 | { |
ittraining | 0:94c1a94c5a47 | 37 | |
ittraining | 0:94c1a94c5a47 | 38 | char data[2]; |
ittraining | 0:94c1a94c5a47 | 39 | data[0]=0x40; |
ittraining | 0:94c1a94c5a47 | 40 | data[1]=lcd_Data; |
ittraining | 0:94c1a94c5a47 | 41 | // I2C_writeBytes(LCD_I2C_PORT, LCD_I2C_SLA, 0x40, 1, data); |
ittraining | 0:94c1a94c5a47 | 42 | //i2c_write_data_block(LCD_I2C_SLA, 0x40,data,1); |
ittraining | 0:94c1a94c5a47 | 43 | i2c.write(LCD_I2C_SLA, data, 2, 0); |
ittraining | 0:94c1a94c5a47 | 44 | } |
ittraining | 0:94c1a94c5a47 | 45 | |
ittraining | 0:94c1a94c5a47 | 46 | #else |
ittraining | 0:94c1a94c5a47 | 47 | |
ittraining | 0:94c1a94c5a47 | 48 | void lcdWriteCommand(uint8_t lcd_Command) |
ittraining | 0:94c1a94c5a47 | 49 | { |
ittraining | 0:94c1a94c5a47 | 50 | uint8_t data[1]; |
ittraining | 0:94c1a94c5a47 | 51 | data[0]=lcd_Command; |
ittraining | 0:94c1a94c5a47 | 52 | // I2C_writeBytes(LCD_I2C_PORT, LCD_I2C_SLA, 0x00, 1, data); |
ittraining | 0:94c1a94c5a47 | 53 | i2c_write_data_block(LCD_I2C_SLA, 0x00, data,1); |
ittraining | 0:94c1a94c5a47 | 54 | |
ittraining | 0:94c1a94c5a47 | 55 | } |
ittraining | 0:94c1a94c5a47 | 56 | |
ittraining | 0:94c1a94c5a47 | 57 | void lcdWriteData(uint8_t lcd_Data) |
ittraining | 0:94c1a94c5a47 | 58 | { |
ittraining | 0:94c1a94c5a47 | 59 | uint8_t data[1]; |
ittraining | 0:94c1a94c5a47 | 60 | data[0]=lcd_Data; |
ittraining | 0:94c1a94c5a47 | 61 | // I2C_writeBytes(LCD_I2C_PORT, LCD_I2C_SLA, 0x40, 1, data); |
ittraining | 0:94c1a94c5a47 | 62 | i2c_write_data_block(LCD_I2C_SLA, 0x40,data,1); |
ittraining | 0:94c1a94c5a47 | 63 | } |
ittraining | 0:94c1a94c5a47 | 64 | |
ittraining | 0:94c1a94c5a47 | 65 | #endif |
ittraining | 0:94c1a94c5a47 | 66 | |
ittraining | 0:94c1a94c5a47 | 67 | void lcdSetAddr(uint8_t column, uint8_t page) |
ittraining | 0:94c1a94c5a47 | 68 | { |
ittraining | 0:94c1a94c5a47 | 69 | lcdWriteCommand(0xb0+page); // set page address |
ittraining | 0:94c1a94c5a47 | 70 | lcdWriteCommand(0x10 | ((column & 0xf0) >> 4)); // set column address MSB |
ittraining | 0:94c1a94c5a47 | 71 | lcdWriteCommand(0x00 | (column & 0x0f) ); // set column address LSB |
ittraining | 0:94c1a94c5a47 | 72 | } |
ittraining | 0:94c1a94c5a47 | 73 | |
ittraining | 0:94c1a94c5a47 | 74 | void Init_LCD(void) |
ittraining | 0:94c1a94c5a47 | 75 | { |
ittraining | 0:94c1a94c5a47 | 76 | lcdWriteCommand(0xae); //display off |
ittraining | 0:94c1a94c5a47 | 77 | lcdWriteCommand(0x20); //Set Memory Addressing Mode |
ittraining | 0:94c1a94c5a47 | 78 | lcdWriteCommand(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid |
ittraining | 0:94c1a94c5a47 | 79 | lcdWriteCommand(0xb0); //Set Page Start Address for Page Addressing Mode,0-7 |
ittraining | 0:94c1a94c5a47 | 80 | lcdWriteCommand(0xc8); //Set COM Output Scan Direction |
ittraining | 0:94c1a94c5a47 | 81 | lcdWriteCommand(0x00);//---set low column address |
ittraining | 0:94c1a94c5a47 | 82 | lcdWriteCommand(0x10);//---set high column address |
ittraining | 0:94c1a94c5a47 | 83 | lcdWriteCommand(0x40);//--set start line address |
ittraining | 0:94c1a94c5a47 | 84 | lcdWriteCommand(0x81);//--set contrast control register |
ittraining | 0:94c1a94c5a47 | 85 | lcdWriteCommand(0x7f); |
ittraining | 0:94c1a94c5a47 | 86 | lcdWriteCommand(0xa1);//--set segment re-map 0 to 127 |
ittraining | 0:94c1a94c5a47 | 87 | lcdWriteCommand(0xa6);//--set normal display |
ittraining | 0:94c1a94c5a47 | 88 | lcdWriteCommand(0xa8);//--set multiplex ratio(1 to 64) |
ittraining | 0:94c1a94c5a47 | 89 | lcdWriteCommand(0x3F);// |
ittraining | 0:94c1a94c5a47 | 90 | lcdWriteCommand(0xa4);//0xa4,Output follows RAM content;0xa5,Output ignores RAM content |
ittraining | 0:94c1a94c5a47 | 91 | lcdWriteCommand(0xd3);//-set display offset |
ittraining | 0:94c1a94c5a47 | 92 | lcdWriteCommand(0x00);//-not offset |
ittraining | 0:94c1a94c5a47 | 93 | lcdWriteCommand(0xd5);//--set display clock divide ratio/oscillator frequency |
ittraining | 0:94c1a94c5a47 | 94 | lcdWriteCommand(0xf0);//--set divide ratio |
ittraining | 0:94c1a94c5a47 | 95 | lcdWriteCommand(0xd9);//--set pre-charge period |
ittraining | 0:94c1a94c5a47 | 96 | lcdWriteCommand(0x22); // |
ittraining | 0:94c1a94c5a47 | 97 | lcdWriteCommand(0xda);//--set com pins hardware configuration |
ittraining | 0:94c1a94c5a47 | 98 | lcdWriteCommand(0x12); |
ittraining | 0:94c1a94c5a47 | 99 | lcdWriteCommand(0xdb);//--set vcomh |
ittraining | 0:94c1a94c5a47 | 100 | lcdWriteCommand(0x20);//0x20,0.77xVcc |
ittraining | 0:94c1a94c5a47 | 101 | lcdWriteCommand(0x8d);//--set DC-DC enable |
ittraining | 0:94c1a94c5a47 | 102 | lcdWriteCommand(0x14);// |
ittraining | 0:94c1a94c5a47 | 103 | lcdWriteCommand(0xaf);//--turn on lcd panel |
ittraining | 0:94c1a94c5a47 | 104 | } |
ittraining | 0:94c1a94c5a47 | 105 | |
ittraining | 0:94c1a94c5a47 | 106 | void clear_LCD(void) |
ittraining | 0:94c1a94c5a47 | 107 | { |
ittraining | 0:94c1a94c5a47 | 108 | int16_t x, Y; |
ittraining | 0:94c1a94c5a47 | 109 | for (Y=0;Y<LCD_Ymax/8;Y++) |
ittraining | 0:94c1a94c5a47 | 110 | { |
ittraining | 0:94c1a94c5a47 | 111 | lcdSetAddr(0, Y); |
ittraining | 0:94c1a94c5a47 | 112 | for (x=0;x<LCD_Xmax;x++) |
ittraining | 0:94c1a94c5a47 | 113 | lcdWriteData(0x00); |
ittraining | 0:94c1a94c5a47 | 114 | } |
ittraining | 0:94c1a94c5a47 | 115 | } |
ittraining | 0:94c1a94c5a47 | 116 | |
ittraining | 0:94c1a94c5a47 | 117 | // print char function using Font5x7 |
ittraining | 0:94c1a94c5a47 | 118 | void printC_5x7 (int16_t x, int16_t y, unsigned char ascii_code) |
ittraining | 0:94c1a94c5a47 | 119 | { |
ittraining | 0:94c1a94c5a47 | 120 | uint8_t i; |
ittraining | 0:94c1a94c5a47 | 121 | if (x<(LCD_Xmax-5) && y<(LCD_Ymax-7)) { |
ittraining | 0:94c1a94c5a47 | 122 | if (ascii_code<0x20) ascii_code=0x20; |
ittraining | 0:94c1a94c5a47 | 123 | else if (ascii_code>0x7F) ascii_code=0x20; |
ittraining | 0:94c1a94c5a47 | 124 | for (i=0;i<5;i++) { |
ittraining | 0:94c1a94c5a47 | 125 | lcdSetAddr((LCD_Xmax+1-x-i), (y/8)); |
ittraining | 0:94c1a94c5a47 | 126 | lcdWriteData(Font5x7[(ascii_code-0x20)*5+5-i]); |
ittraining | 0:94c1a94c5a47 | 127 | } |
ittraining | 0:94c1a94c5a47 | 128 | } |
ittraining | 0:94c1a94c5a47 | 129 | } |
ittraining | 0:94c1a94c5a47 | 130 | |
ittraining | 0:94c1a94c5a47 | 131 | void print_C(uint8_t Line, uint8_t Col, char ascii) |
ittraining | 0:94c1a94c5a47 | 132 | { |
ittraining | 0:94c1a94c5a47 | 133 | uint8_t j, i, tmp; |
ittraining | 0:94c1a94c5a47 | 134 | for (j=0;j<2;j++) { |
ittraining | 0:94c1a94c5a47 | 135 | lcdSetAddr(Col*8, Line*2+j); |
ittraining | 0:94c1a94c5a47 | 136 | for (i=0;i<8;i++) { |
ittraining | 0:94c1a94c5a47 | 137 | tmp=Font8x16[(ascii-0x20)*16+j*8+i]; |
ittraining | 0:94c1a94c5a47 | 138 | lcdWriteData(tmp); |
ittraining | 0:94c1a94c5a47 | 139 | } |
ittraining | 0:94c1a94c5a47 | 140 | } |
ittraining | 0:94c1a94c5a47 | 141 | } |
ittraining | 0:94c1a94c5a47 | 142 | |
ittraining | 0:94c1a94c5a47 | 143 | void print_Line(uint8_t line, char text[]) |
ittraining | 0:94c1a94c5a47 | 144 | { |
ittraining | 0:94c1a94c5a47 | 145 | uint8_t Col; |
ittraining | 0:94c1a94c5a47 | 146 | for (Col=0; Col<strlen(text); Col++) |
ittraining | 0:94c1a94c5a47 | 147 | print_C(line, Col, text[Col]); |
ittraining | 0:94c1a94c5a47 | 148 | } |
ittraining | 0:94c1a94c5a47 | 149 | |
ittraining | 0:94c1a94c5a47 | 150 | void printS(int16_t x, int16_t y, char text[]) |
ittraining | 0:94c1a94c5a47 | 151 | { |
ittraining | 0:94c1a94c5a47 | 152 | int8_t i; |
ittraining | 0:94c1a94c5a47 | 153 | for (i=0;i<strlen(text);i++) |
ittraining | 0:94c1a94c5a47 | 154 | print_C(x+i*8, y,text[i]); |
ittraining | 0:94c1a94c5a47 | 155 | } |
ittraining | 0:94c1a94c5a47 | 156 | |
ittraining | 0:94c1a94c5a47 | 157 | void printS_5x7(int16_t x, int16_t y, char text[]) |
ittraining | 0:94c1a94c5a47 | 158 | { |
ittraining | 0:94c1a94c5a47 | 159 | uint8_t i; |
ittraining | 0:94c1a94c5a47 | 160 | for (i=0;i<strlen(text);i++) { |
ittraining | 0:94c1a94c5a47 | 161 | printC_5x7(x,y,text[i]); |
ittraining | 0:94c1a94c5a47 | 162 | x=x+5; |
ittraining | 0:94c1a94c5a47 | 163 | } |
ittraining | 0:94c1a94c5a47 | 164 | } |
ittraining | 0:94c1a94c5a47 | 165 | |
ittraining | 0:94c1a94c5a47 | 166 | void draw_Pixel(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor) |
ittraining | 0:94c1a94c5a47 | 167 | { |
ittraining | 0:94c1a94c5a47 | 168 | if (fgColor!=0) |
ittraining | 0:94c1a94c5a47 | 169 | DisplayBuffer[x+y/8*LCD_Xmax] |= (0x01<<(y%8)); |
ittraining | 0:94c1a94c5a47 | 170 | else |
ittraining | 0:94c1a94c5a47 | 171 | DisplayBuffer[x+y/8*LCD_Xmax] &= (0xFE<<(y%8)); |
ittraining | 0:94c1a94c5a47 | 172 | |
ittraining | 0:94c1a94c5a47 | 173 | lcdSetAddr(x, y/8); |
ittraining | 0:94c1a94c5a47 | 174 | lcdWriteData(DisplayBuffer[x+y/8*LCD_Xmax]); |
ittraining | 0:94c1a94c5a47 | 175 | } |
ittraining | 0:94c1a94c5a47 | 176 | |
ittraining | 0:94c1a94c5a47 | 177 | void draw_Bmp8x8(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 178 | { |
ittraining | 0:94c1a94c5a47 | 179 | uint8_t t,i,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 180 | if (x<(LCD_Xmax-7) && y<(LCD_Ymax-7)) // boundary check |
ittraining | 0:94c1a94c5a47 | 181 | for (i=0;i<8;i++){ |
ittraining | 0:94c1a94c5a47 | 182 | kx=x+i; |
ittraining | 0:94c1a94c5a47 | 183 | t=bitmap[i]; |
ittraining | 0:94c1a94c5a47 | 184 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 185 | ky=y+k; |
ittraining | 0:94c1a94c5a47 | 186 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 187 | } |
ittraining | 0:94c1a94c5a47 | 188 | } |
ittraining | 0:94c1a94c5a47 | 189 | } |
ittraining | 0:94c1a94c5a47 | 190 | |
ittraining | 0:94c1a94c5a47 | 191 | void draw_Bmp32x8(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 192 | { |
ittraining | 0:94c1a94c5a47 | 193 | uint8_t t,i,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 194 | if (x<(LCD_Xmax-7) && y<(LCD_Ymax-7)) // boundary check |
ittraining | 0:94c1a94c5a47 | 195 | for (i=0;i<32;i++){ |
ittraining | 0:94c1a94c5a47 | 196 | kx=x+i; |
ittraining | 0:94c1a94c5a47 | 197 | t=bitmap[i]; |
ittraining | 0:94c1a94c5a47 | 198 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 199 | ky=y+k; |
ittraining | 0:94c1a94c5a47 | 200 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 201 | } |
ittraining | 0:94c1a94c5a47 | 202 | } |
ittraining | 0:94c1a94c5a47 | 203 | } |
ittraining | 0:94c1a94c5a47 | 204 | |
ittraining | 0:94c1a94c5a47 | 205 | void draw_Bmp120x8(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 206 | { |
ittraining | 0:94c1a94c5a47 | 207 | uint8_t t,i,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 208 | if (x<(LCD_Xmax-7) && y<(LCD_Ymax-7)) // boundary check |
ittraining | 0:94c1a94c5a47 | 209 | for (i=0;i<120;i++){ |
ittraining | 0:94c1a94c5a47 | 210 | kx=x+i; |
ittraining | 0:94c1a94c5a47 | 211 | t=bitmap[i]; |
ittraining | 0:94c1a94c5a47 | 212 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 213 | ky=y+k; |
ittraining | 0:94c1a94c5a47 | 214 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 215 | } |
ittraining | 0:94c1a94c5a47 | 216 | } |
ittraining | 0:94c1a94c5a47 | 217 | } |
ittraining | 0:94c1a94c5a47 | 218 | |
ittraining | 0:94c1a94c5a47 | 219 | void draw_Bmp8x16(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 220 | { |
ittraining | 0:94c1a94c5a47 | 221 | uint8_t t,i,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 222 | if (x<(LCD_Xmax-7) && y<(LCD_Ymax-7)) // boundary check |
ittraining | 0:94c1a94c5a47 | 223 | for (i=0;i<8;i++){ |
ittraining | 0:94c1a94c5a47 | 224 | kx=x+i; |
ittraining | 0:94c1a94c5a47 | 225 | t=bitmap[i]; |
ittraining | 0:94c1a94c5a47 | 226 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 227 | ky=y+k; |
ittraining | 0:94c1a94c5a47 | 228 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 229 | } |
ittraining | 0:94c1a94c5a47 | 230 | t=bitmap[i+8]; |
ittraining | 0:94c1a94c5a47 | 231 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 232 | ky=y+k+8; |
ittraining | 0:94c1a94c5a47 | 233 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 234 | } |
ittraining | 0:94c1a94c5a47 | 235 | } |
ittraining | 0:94c1a94c5a47 | 236 | } |
ittraining | 0:94c1a94c5a47 | 237 | |
ittraining | 0:94c1a94c5a47 | 238 | void draw_Bmp16x8(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 239 | { |
ittraining | 0:94c1a94c5a47 | 240 | uint8_t t,i,k,kx,ky; |
ittraining | 0:94c1a94c5a47 | 241 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-7)) // boundary check |
ittraining | 0:94c1a94c5a47 | 242 | for (i=0;i<16;i++) |
ittraining | 0:94c1a94c5a47 | 243 | { |
ittraining | 0:94c1a94c5a47 | 244 | kx=x+i; |
ittraining | 0:94c1a94c5a47 | 245 | t=bitmap[i]; |
ittraining | 0:94c1a94c5a47 | 246 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 247 | ky=y+k; |
ittraining | 0:94c1a94c5a47 | 248 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 249 | } |
ittraining | 0:94c1a94c5a47 | 250 | } |
ittraining | 0:94c1a94c5a47 | 251 | } |
ittraining | 0:94c1a94c5a47 | 252 | |
ittraining | 0:94c1a94c5a47 | 253 | void draw_Bmp16x16(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 254 | { |
ittraining | 0:94c1a94c5a47 | 255 | uint8_t t,i,j,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 256 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-15)) // boundary check |
ittraining | 0:94c1a94c5a47 | 257 | for (j=0;j<2; j++){ |
ittraining | 0:94c1a94c5a47 | 258 | for (i=0;i<16;i++) { |
ittraining | 0:94c1a94c5a47 | 259 | kx=x+i; |
ittraining | 0:94c1a94c5a47 | 260 | t=bitmap[i+j*16]; |
ittraining | 0:94c1a94c5a47 | 261 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 262 | ky=y+j*8+k; |
ittraining | 0:94c1a94c5a47 | 263 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 264 | } |
ittraining | 0:94c1a94c5a47 | 265 | } |
ittraining | 0:94c1a94c5a47 | 266 | } |
ittraining | 0:94c1a94c5a47 | 267 | } |
ittraining | 0:94c1a94c5a47 | 268 | |
ittraining | 0:94c1a94c5a47 | 269 | void draw_Bmp16x24(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 270 | { |
ittraining | 0:94c1a94c5a47 | 271 | uint8_t t,i,j,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 272 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-15)) // boundary check |
ittraining | 0:94c1a94c5a47 | 273 | for (j=0;j<3; j++){ |
ittraining | 0:94c1a94c5a47 | 274 | for (i=0;i<16;i++) { |
ittraining | 0:94c1a94c5a47 | 275 | kx=x+i; |
ittraining | 0:94c1a94c5a47 | 276 | t=bitmap[i+j*16]; |
ittraining | 0:94c1a94c5a47 | 277 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 278 | ky=y+j*8+k; |
ittraining | 0:94c1a94c5a47 | 279 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 280 | } |
ittraining | 0:94c1a94c5a47 | 281 | } |
ittraining | 0:94c1a94c5a47 | 282 | } |
ittraining | 0:94c1a94c5a47 | 283 | } |
ittraining | 0:94c1a94c5a47 | 284 | |
ittraining | 0:94c1a94c5a47 | 285 | void draw_Bmp16x32(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 286 | { |
ittraining | 0:94c1a94c5a47 | 287 | uint8_t t, i,j,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 288 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-31)) // boundary check |
ittraining | 0:94c1a94c5a47 | 289 | for (j=0;j<4; j++) { |
ittraining | 0:94c1a94c5a47 | 290 | for (i=0;i<16;i++) { |
ittraining | 0:94c1a94c5a47 | 291 | kx=x+i; |
ittraining | 0:94c1a94c5a47 | 292 | t=bitmap[i+j*16]; |
ittraining | 0:94c1a94c5a47 | 293 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 294 | ky=y+j*8+k; |
ittraining | 0:94c1a94c5a47 | 295 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 296 | } |
ittraining | 0:94c1a94c5a47 | 297 | } |
ittraining | 0:94c1a94c5a47 | 298 | } |
ittraining | 0:94c1a94c5a47 | 299 | } |
ittraining | 0:94c1a94c5a47 | 300 | |
ittraining | 0:94c1a94c5a47 | 301 | void draw_Bmp16x40(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 302 | { |
ittraining | 0:94c1a94c5a47 | 303 | uint8_t t, i,j,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 304 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-31)) // boundary check |
ittraining | 0:94c1a94c5a47 | 305 | for (j=0;j<5; j++) { |
ittraining | 0:94c1a94c5a47 | 306 | for (i=0;i<16;i++) { |
ittraining | 0:94c1a94c5a47 | 307 | kx=x+i; |
ittraining | 0:94c1a94c5a47 | 308 | t=bitmap[i+j*16]; |
ittraining | 0:94c1a94c5a47 | 309 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 310 | ky=y+j*8+k; |
ittraining | 0:94c1a94c5a47 | 311 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 312 | } |
ittraining | 0:94c1a94c5a47 | 313 | } |
ittraining | 0:94c1a94c5a47 | 314 | } |
ittraining | 0:94c1a94c5a47 | 315 | } |
ittraining | 0:94c1a94c5a47 | 316 | |
ittraining | 0:94c1a94c5a47 | 317 | void draw_Bmp16x48(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 318 | { |
ittraining | 0:94c1a94c5a47 | 319 | uint8_t t,i,j,k,kx,ky; |
ittraining | 0:94c1a94c5a47 | 320 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-47)) // boundary check |
ittraining | 0:94c1a94c5a47 | 321 | for (j=0;j<6; j++) { |
ittraining | 0:94c1a94c5a47 | 322 | k=x; |
ittraining | 0:94c1a94c5a47 | 323 | for (i=0;i<16;i++) { |
ittraining | 0:94c1a94c5a47 | 324 | kx=x+i; |
ittraining | 0:94c1a94c5a47 | 325 | t=bitmap[i+j*16]; |
ittraining | 0:94c1a94c5a47 | 326 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 327 | ky=y+j*8+k; |
ittraining | 0:94c1a94c5a47 | 328 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 329 | } |
ittraining | 0:94c1a94c5a47 | 330 | } |
ittraining | 0:94c1a94c5a47 | 331 | } |
ittraining | 0:94c1a94c5a47 | 332 | } |
ittraining | 0:94c1a94c5a47 | 333 | |
ittraining | 0:94c1a94c5a47 | 334 | void draw_Bmp16x64(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 335 | { |
ittraining | 0:94c1a94c5a47 | 336 | uint8_t t,i,j,k,kx,ky; |
ittraining | 0:94c1a94c5a47 | 337 | if (x<(LCD_Xmax-15) && y==0) // boundary check |
ittraining | 0:94c1a94c5a47 | 338 | for (j=0;j<8; j++) { |
ittraining | 0:94c1a94c5a47 | 339 | k=x; |
ittraining | 0:94c1a94c5a47 | 340 | for (i=0;i<16;i++) { |
ittraining | 0:94c1a94c5a47 | 341 | kx=x+i; |
ittraining | 0:94c1a94c5a47 | 342 | t=bitmap[i+j*16]; |
ittraining | 0:94c1a94c5a47 | 343 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 344 | ky=y+j*8+k; |
ittraining | 0:94c1a94c5a47 | 345 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 346 | } |
ittraining | 0:94c1a94c5a47 | 347 | } |
ittraining | 0:94c1a94c5a47 | 348 | } |
ittraining | 0:94c1a94c5a47 | 349 | } |
ittraining | 0:94c1a94c5a47 | 350 | |
ittraining | 0:94c1a94c5a47 | 351 | void draw_Bmp32x16(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 352 | { |
ittraining | 0:94c1a94c5a47 | 353 | uint8_t t,i,jx,jy,k,kx,ky; |
ittraining | 0:94c1a94c5a47 | 354 | if (x<(LCD_Xmax-31) && y<(LCD_Ymax-15)) // boundary check |
ittraining | 0:94c1a94c5a47 | 355 | for (jy=0;jy<2;jy++) |
ittraining | 0:94c1a94c5a47 | 356 | for (jx=0;jx<2;jx++) { |
ittraining | 0:94c1a94c5a47 | 357 | k=x; |
ittraining | 0:94c1a94c5a47 | 358 | for (i=0;i<16;i++) { |
ittraining | 0:94c1a94c5a47 | 359 | kx=x+jx*16+i; |
ittraining | 0:94c1a94c5a47 | 360 | t=bitmap[i+jx*16+jy*32]; |
ittraining | 0:94c1a94c5a47 | 361 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 362 | ky=y+jy*8+k; |
ittraining | 0:94c1a94c5a47 | 363 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 364 | } |
ittraining | 0:94c1a94c5a47 | 365 | } |
ittraining | 0:94c1a94c5a47 | 366 | } |
ittraining | 0:94c1a94c5a47 | 367 | } |
ittraining | 0:94c1a94c5a47 | 368 | |
ittraining | 0:94c1a94c5a47 | 369 | void draw_Bmp32x32(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 370 | { |
ittraining | 0:94c1a94c5a47 | 371 | uint8_t t,i,jx,jy,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 372 | if (x<(LCD_Xmax-31) && y<(LCD_Ymax-31)) // boundary check |
ittraining | 0:94c1a94c5a47 | 373 | for (jy=0;jy<4;jy++) |
ittraining | 0:94c1a94c5a47 | 374 | for (jx=0;jx<2;jx++) { |
ittraining | 0:94c1a94c5a47 | 375 | k=x; |
ittraining | 0:94c1a94c5a47 | 376 | for (i=0;i<16;i++) { |
ittraining | 0:94c1a94c5a47 | 377 | kx=x+jx*16+i; |
ittraining | 0:94c1a94c5a47 | 378 | t=bitmap[i+jx*16+jy*32]; |
ittraining | 0:94c1a94c5a47 | 379 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 380 | ky=y+jy*8+k; |
ittraining | 0:94c1a94c5a47 | 381 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 382 | } |
ittraining | 0:94c1a94c5a47 | 383 | } |
ittraining | 0:94c1a94c5a47 | 384 | } |
ittraining | 0:94c1a94c5a47 | 385 | } |
ittraining | 0:94c1a94c5a47 | 386 | |
ittraining | 0:94c1a94c5a47 | 387 | void draw_Bmp32x48(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 388 | { |
ittraining | 0:94c1a94c5a47 | 389 | uint8_t t,i,jx,jy,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 390 | if (x<(LCD_Xmax-31) && y<(LCD_Ymax-47)) // boundary check |
ittraining | 0:94c1a94c5a47 | 391 | for (jy=0;jy<6;jy++) |
ittraining | 0:94c1a94c5a47 | 392 | for (jx=0;jx<2;jx++) { |
ittraining | 0:94c1a94c5a47 | 393 | k=x; |
ittraining | 0:94c1a94c5a47 | 394 | for (i=0;i<16;i++) { |
ittraining | 0:94c1a94c5a47 | 395 | kx=x+jx*16+i; |
ittraining | 0:94c1a94c5a47 | 396 | t=bitmap[i+jx*16+jy*32]; |
ittraining | 0:94c1a94c5a47 | 397 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 398 | ky=y+jy*8+k; |
ittraining | 0:94c1a94c5a47 | 399 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 400 | } |
ittraining | 0:94c1a94c5a47 | 401 | } |
ittraining | 0:94c1a94c5a47 | 402 | } |
ittraining | 0:94c1a94c5a47 | 403 | } |
ittraining | 0:94c1a94c5a47 | 404 | |
ittraining | 0:94c1a94c5a47 | 405 | void draw_Bmp32x64(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 406 | { |
ittraining | 0:94c1a94c5a47 | 407 | uint8_t t,i,jx,jy,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 408 | if (x<(LCD_Xmax-31) && y==0) // boundary check |
ittraining | 0:94c1a94c5a47 | 409 | for (jy=0;jy<8;jy++) |
ittraining | 0:94c1a94c5a47 | 410 | for (jx=0;jx<2;jx++) { |
ittraining | 0:94c1a94c5a47 | 411 | k=x; |
ittraining | 0:94c1a94c5a47 | 412 | for (i=0;i<16;i++) { |
ittraining | 0:94c1a94c5a47 | 413 | kx=x+jx*16+i; |
ittraining | 0:94c1a94c5a47 | 414 | t=bitmap[i+jx*16+jy*32]; |
ittraining | 0:94c1a94c5a47 | 415 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 416 | ky=y+jy*8+k; |
ittraining | 0:94c1a94c5a47 | 417 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 418 | } |
ittraining | 0:94c1a94c5a47 | 419 | } |
ittraining | 0:94c1a94c5a47 | 420 | } |
ittraining | 0:94c1a94c5a47 | 421 | } |
ittraining | 0:94c1a94c5a47 | 422 | |
ittraining | 0:94c1a94c5a47 | 423 | void draw_Bmp64x64(int16_t x, int16_t y, uint16_t fgColor, uint16_t bgColor, unsigned char bitmap[]) |
ittraining | 0:94c1a94c5a47 | 424 | { |
ittraining | 0:94c1a94c5a47 | 425 | uint8_t t, i,jx,jy,k, kx,ky; |
ittraining | 0:94c1a94c5a47 | 426 | if (x<(LCD_Xmax-63) && y==0) // boundary check |
ittraining | 0:94c1a94c5a47 | 427 | for (jy=0;jy<8;jy++) |
ittraining | 0:94c1a94c5a47 | 428 | for (jx=0;jx<4;jx++) { |
ittraining | 0:94c1a94c5a47 | 429 | k=x; |
ittraining | 0:94c1a94c5a47 | 430 | for (i=0;i<16;i++) { |
ittraining | 0:94c1a94c5a47 | 431 | kx=x+jx*16+i; |
ittraining | 0:94c1a94c5a47 | 432 | t=bitmap[i+jx*16+jy*64]; |
ittraining | 0:94c1a94c5a47 | 433 | for (k=0;k<8;k++) { |
ittraining | 0:94c1a94c5a47 | 434 | ky=y+jy*8+k; |
ittraining | 0:94c1a94c5a47 | 435 | if (t&(0x01<<k)) draw_Pixel(kx,ky,fgColor,bgColor); |
ittraining | 0:94c1a94c5a47 | 436 | } |
ittraining | 0:94c1a94c5a47 | 437 | } |
ittraining | 0:94c1a94c5a47 | 438 | } |
ittraining | 0:94c1a94c5a47 | 439 | } |
ittraining | 0:94c1a94c5a47 | 440 | |
ittraining | 0:94c1a94c5a47 | 441 | void draw_LCD(unsigned char *buffer) |
ittraining | 0:94c1a94c5a47 | 442 | { |
ittraining | 0:94c1a94c5a47 | 443 | uint8_t x,y; |
ittraining | 0:94c1a94c5a47 | 444 | for (x=0; x<LCD_Xmax; x++) { |
ittraining | 0:94c1a94c5a47 | 445 | for (y=0; y<(LCD_Ymax/8); y++) { |
ittraining | 0:94c1a94c5a47 | 446 | lcdSetAddr(x ,y); |
ittraining | 0:94c1a94c5a47 | 447 | lcdWriteData(buffer[x+y*LCD_Xmax]); |
ittraining | 0:94c1a94c5a47 | 448 | } |
ittraining | 0:94c1a94c5a47 | 449 | } |
ittraining | 0:94c1a94c5a47 | 450 | } |
ittraining | 0:94c1a94c5a47 | 451 |