سلام.بعداز یه عالمه تلاش تونستم یه کتابخونه برای ماژول oledبنویسم.فقط دقت کنید که هربار که میخوایید روoledچیزی نشون بدید یه ارایه 1024 خونه ای میخواید که تو هر خونه یه مقدار8بیتی که مربوط به هشتا پیکسل پشت سر هم روبه پایین است که 0یعنی پیکسل خاموش وبلعکس.یعنی اولدر ستون اول به هشت پیکسل زیر هم مقدارمیده بعد میره سراغ ستون دوم ودوباره کار قبلی ووقتی به ستون 128 رسد میره هشت پیکسل پایین تر وبعد دوباره کارهاراانجام میده
کد:
#include <18f452.h> #FUSES NOWDT //No Watch Dog Timer #FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale #FUSES NOBROWNOUT //No brownout reset #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O #use delay(xtal=8000000) #use i2c(Master,Fast,sda=PIN_D0,scl=PIN_D1) #define cs_low output_low(pin_d2) #define dc_low output_low(pin_d3) #define contrast 0x81 #define edo 0xa4 #define normaldisplay 0xa6 #define displayon 0xaf #define displayoff 0xae #define addressingmode 0x20 #define columnaddress 0x21 #define pageaddress 0x22 #define startline 0x40 #define segmentremap 0xa0 #define multiplex 0xa8 #define scandir 0xc0 #define offset 0xd3 #define compin 0xda #define freq 0xd5 #define precharge 0xd9 #define vcom 0xdb int8 buffer[1024]; void oled_init(int8 command){ i2c_start(); i2c_write(0x78); i2c_write(0x00); i2c_write(command); i2c_stop(); } void oled_setcommand(){ oled_init(displayoff); oled_init(freq); oled_init(0xf0); oled_init(multiplex); oled_init(0x3f); oled_init(offset); oled_init(0x00); oled_init(startline); oled_init(addressingmode); oled_init(0x00); oled_init(segmentremap ); oled_init(scandir); oled_init(compin); oled_init(0x12); oled_init(contrast); oled_init(0x7f); oled_init(precharge); oled_init(0xf1); oled_init(vcom); oled_init(0x30); oled_init(edo); oled_init(normaldisplay); oled_init(displayon); } void oled_column(void){ oled_init(columnaddress); oled_init(0); oled_init(127); } void oled_page(void){ oled_init(pageaddress); oled_init(0); oled_init(7); } void oled_write(void){ oled_column(); oled_page(); i2c_start(); i2c_write(0x78); i2c_write(0x40); for(int16 i=0;i<1024;i++){ i2c_write(buffer[i]); } i2c_stop(); } void oled_clear(void){ oled_column(); oled_page(); i2c_start(); i2c_write(0x78); i2c_write(0x40); for(int16 i=0;i<1024;i++){ i2c_write(0x00); } i2c_stop(); } void main() { cs_low; dc_low; oled_setcommand(); while(TRUE) { oled_write(); delay_ms(1000); oled_clear(); } }
دیدگاه