stm32f103c8t6 oled 8x16 new
Dependencies: mbed SSD1306_128x64_I2C
main.cpp@0:6fad8ac3cad2, 2021-03-06 (annotated)
- Committer:
- caa45040
- Date:
- Sat Mar 06 11:18:03 2021 +0000
- Revision:
- 0:6fad8ac3cad2
stm32f103c8t6 oled 8x16 n
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
caa45040 | 0:6fad8ac3cad2 | 1 | // |
caa45040 | 0:6fad8ac3cad2 | 2 | // 128*64 |
caa45040 | 0:6fad8ac3cad2 | 3 | // 303 oled 8*16 |
caa45040 | 0:6fad8ac3cad2 | 4 | // |
caa45040 | 0:6fad8ac3cad2 | 5 | |
caa45040 | 0:6fad8ac3cad2 | 6 | #include "mbed.h" |
caa45040 | 0:6fad8ac3cad2 | 7 | #include "SSD1306.h" |
caa45040 | 0:6fad8ac3cad2 | 8 | #include "font_8x8.h" |
caa45040 | 0:6fad8ac3cad2 | 9 | |
caa45040 | 0:6fad8ac3cad2 | 10 | DigitalOut myled(LED1); |
caa45040 | 0:6fad8ac3cad2 | 11 | |
caa45040 | 0:6fad8ac3cad2 | 12 | #define ADDR (0x3c<<1) // address |
caa45040 | 0:6fad8ac3cad2 | 13 | //#define ADDR (0x3d<<1) // address |
caa45040 | 0:6fad8ac3cad2 | 14 | |
caa45040 | 0:6fad8ac3cad2 | 15 | //I2C i2c(I2C_SDA, I2C_SCL); |
caa45040 | 0:6fad8ac3cad2 | 16 | I2C i2c(PB_7, PB_6); // STM32F103C8 |
caa45040 | 0:6fad8ac3cad2 | 17 | |
caa45040 | 0:6fad8ac3cad2 | 18 | // Host PC Communication channels |
caa45040 | 0:6fad8ac3cad2 | 19 | //Serial pc(USBTX, USBRX); // tx, rx |
caa45040 | 0:6fad8ac3cad2 | 20 | Serial pc(PA_9, PA_10); // tx, rx 103 |
caa45040 | 0:6fad8ac3cad2 | 21 | |
caa45040 | 0:6fad8ac3cad2 | 22 | // Instantiate OLED |
caa45040 | 0:6fad8ac3cad2 | 23 | SSD1306 oled(i2c, ADDR); |
caa45040 | 0:6fad8ac3cad2 | 24 | |
caa45040 | 0:6fad8ac3cad2 | 25 | char ddff[8*4]; |
caa45040 | 0:6fad8ac3cad2 | 26 | |
caa45040 | 0:6fad8ac3cad2 | 27 | void char11(int row,int com,int cha) |
caa45040 | 0:6fad8ac3cad2 | 28 | { |
caa45040 | 0:6fad8ac3cad2 | 29 | |
caa45040 | 0:6fad8ac3cad2 | 30 | int char_index1; |
caa45040 | 0:6fad8ac3cad2 | 31 | |
caa45040 | 0:6fad8ac3cad2 | 32 | char_index1 = cha-0x20; |
caa45040 | 0:6fad8ac3cad2 | 33 | |
caa45040 | 0:6fad8ac3cad2 | 34 | int ii; |
caa45040 | 0:6fad8ac3cad2 | 35 | |
caa45040 | 0:6fad8ac3cad2 | 36 | for (ii = 0;ii<(8*2);ii++) {ddff[ii]=0;} // オールクリア |
caa45040 | 0:6fad8ac3cad2 | 37 | for (ii =0;ii<8;ii++){ |
caa45040 | 0:6fad8ac3cad2 | 38 | ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 0) & 1)<<0; //1bit 1 |
caa45040 | 0:6fad8ac3cad2 | 39 | ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 0) & 1)<<1; //1bit 2 |
caa45040 | 0:6fad8ac3cad2 | 40 | ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 1) & 1)<<2; //2bit 3 |
caa45040 | 0:6fad8ac3cad2 | 41 | ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 1) & 1)<<3; //2bit 4 |
caa45040 | 0:6fad8ac3cad2 | 42 | ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 2) & 1)<<4; //3bit 5 |
caa45040 | 0:6fad8ac3cad2 | 43 | ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 2) & 1)<<5; //3bit 6 |
caa45040 | 0:6fad8ac3cad2 | 44 | ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 3) & 1)<<6; //4bit 7 |
caa45040 | 0:6fad8ac3cad2 | 45 | ddff[ii+ 0] = ddff[ii+ 0] | ((font_8x8[char_index1][ii] >> 3) & 1)<<7; //4bit 8 |
caa45040 | 0:6fad8ac3cad2 | 46 | ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 4) & 1)<<0; //5bit 1 |
caa45040 | 0:6fad8ac3cad2 | 47 | ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 4) & 1)<<1; //5bit 2 |
caa45040 | 0:6fad8ac3cad2 | 48 | ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 5) & 1)<<2; //6bit 3 |
caa45040 | 0:6fad8ac3cad2 | 49 | ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 5) & 1)<<3; //6bit 4 |
caa45040 | 0:6fad8ac3cad2 | 50 | ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 6) & 1)<<4; //7bit 5 |
caa45040 | 0:6fad8ac3cad2 | 51 | ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 6) & 1)<<5; //7bit 6 |
caa45040 | 0:6fad8ac3cad2 | 52 | ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 7) & 1)<<6; //8bit 7 |
caa45040 | 0:6fad8ac3cad2 | 53 | ddff[ii+ 8] = ddff[ii+ 8] | ((font_8x8[char_index1][ii] >> 7) & 1)<<7; //8bit 8 |
caa45040 | 0:6fad8ac3cad2 | 54 | }//for |
caa45040 | 0:6fad8ac3cad2 | 55 | |
caa45040 | 0:6fad8ac3cad2 | 56 | oled.writeBitmap((uint8_t*) ddff, |
caa45040 | 0:6fad8ac3cad2 | 57 | row, (row + 2 - 1), //y |
caa45040 | 0:6fad8ac3cad2 | 58 | com, (com + 8 - 1)); //x |
caa45040 | 0:6fad8ac3cad2 | 59 | |
caa45040 | 0:6fad8ac3cad2 | 60 | } //end chr11 |
caa45040 | 0:6fad8ac3cad2 | 61 | |
caa45040 | 0:6fad8ac3cad2 | 62 | int main() { |
caa45040 | 0:6fad8ac3cad2 | 63 | int ii; |
caa45040 | 0:6fad8ac3cad2 | 64 | pc.baud(9600); |
caa45040 | 0:6fad8ac3cad2 | 65 | |
caa45040 | 0:6fad8ac3cad2 | 66 | char ss1[]="Hello World !"; |
caa45040 | 0:6fad8ac3cad2 | 67 | ii=0; |
caa45040 | 0:6fad8ac3cad2 | 68 | while(ss1[ii]!=0){ |
caa45040 | 0:6fad8ac3cad2 | 69 | // y x 文字 |
caa45040 | 0:6fad8ac3cad2 | 70 | char11(0,ii*8,ss1[ii]);ii++; |
caa45040 | 0:6fad8ac3cad2 | 71 | } |
caa45040 | 0:6fad8ac3cad2 | 72 | pc.printf("Printed something\r"); |
caa45040 | 0:6fad8ac3cad2 | 73 | } |