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