首页资源分类应用技术消费电子 > SSD1306代码测试通过

SSD1306代码测试通过

已有 445025个资源

下载专区

文档信息举报收藏

标    签:SSD1306

分    享:

文档简介

SSD1306  测试通过

文档预览

//*********IC:SSD1306 //*********Time:4_w //*********engr_li@163.com #include #include "font.h" sbit A0=P3^0; sbit SDA=P3^1; sbit SCL=P3^2; void Delay(unsigned int t) { while(t) { t--; } } void Write_Com(unsigned char Com) { unsigned char i; A0=0; for(i=0;i<8;i++) { SCL=0; SDA=0X80&Com; Delay(2); SCL=1; Com=Com<<1; } } void Write_Data(unsigned char Data) { unsigned char i; A0=1; for(i=0;i<8;i++) { SCL=0; SDA=0X80&Data; Delay(2); SCL=1; Data=Data<<1; } } //********地址设置 void Set_Colume(unsigned char Colume) { Write_Com(0x10|(Colume>>4)); Write_Com(0x0f&Colume); } void Set_Line(unsigned char Line) { Write_Com(0x40|Line); } void Set_Page(unsigned char Page) { Write_Com(0xb0|Page); } //***************电压设置 void Set_Constast(unsigned char Constast) { Write_Com(0x81); Write_Com(Constast); } //***************设置扫面数据地址递增方向 void Set_Direction(unsigned char Direction) { Write_Com(0x20); Write_Com(Direction); } //************初始化 void Init_SSD1306() { Delay(1000);//等待电压稳定 Write_Com(0xAE);//关闭显示 Set_Colume(0); Set_Line(0); Set_Page(0); Set_Constast(0xcf);//设置对比度 Write_Com(0xA1);//设置SEG扫描方向 Write_Com(0xA6);//正常显示 Write_Com(0xA8); Write_Com(0x3F);//1/64Duty Write_Com(0xC8);//Com扫面方向 Write_Com(0xD3); Write_Com(0x00);//设置垂直移动 Write_Com(0xD5); Write_Com(0x00);//设置时钟驱动 Write_Com(0xD9); Write_Com(0xF1);//设置翻转相位?? Write_Com(0xDA); Write_Com(0x12);//设置COM配置 Write_Com(0xDB); Write_Com(0x30);//设置VCOM Write_Com(0x8D); Write_Com(0x10);//倍压设置 Write_Com(0xAF);//开显示 } void Display_Pic(unsigned char *P) { unsigned char i; unsigned char j; Set_Colume(0); Set_Line(0); Set_Page(0); for(i=0;i<8;i++) { Set_Colume(0); Set_Line(0); Set_Page(i); for(j=0;j<128;j++) { Write_Data(*P); P++; } } } void Display_H(unsigned char Data0,unsigned char Data1) { unsigned char i; unsigned char j; Set_Colume(0); Set_Line(0); Set_Page(0); for(i=0;i<8;i++) { Set_Colume(0); Set_Line(0); Set_Page(i); for(j=0;j<64;j++) { Write_Data(Data0); Write_Data(Data1); } } } void Display_Chinese(unsigned char *p) { unsigned char i; unsigned char j; unsigned char k; for(j=0;j<4;j++) { for(k=0;k<8;k++) { Set_Page(j); Set_Line(0); Set_Colume(k*16); for(i=0;i<16;i++) { Write_Data(*p); p++; } Set_Page(j+1); Set_Line(0); Set_Colume(k*16); for(i=0;i<16;i++) { Write_Data(*p); p++; } } } } //***********主函数 void main() { Init_SSD1306(); while(1) { Display_H(0xff,0x00); Delay(65530); Display_H(0x00,0xff); Delay(65530); Display_H(0x55,0x55); Delay(65530); Display_H(0xaa,0xaa); Delay(65530); Display_Pic(Pic); Delay(65530); Display_Pic(Word); Delay(65530); } }

Top_arrow
回到顶部
EEWORLD下载中心所有资源均来自网友分享,如有侵权,请发送举报邮件到客服邮箱bbs_service@eeworld.com.cn 或通过站内短信息或QQ:273568022联系管理员 高员外,我们会尽快处理。