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

SSD1303 代码测试通过

已有 445110个资源

下载专区

文档信息举报收藏

标    签:SSD1303

分    享:

文档简介

SSD1303 测试通过

文档预览

/* IC : SSD1305 */ /*Time:8080*****/ /*****engr_li@163.com #include "REG51.h" #include "Font.h" sbit DC = P3^0; sbit CS = P3^3; sbit EN = P3^2; sbit RW = P3^1; sbit RES =P3^4; #define xData P1 unsigned char Brightness=0x015; /*预定义*/ void Write_Command(unsigned char Data); void Write_Data(unsigned char Data); void Set_Column_Address(unsigned char a, unsigned char b); void Set_Row_Address(unsigned char a, unsigned char b); void Set_Contrast_Current(unsigned char d); void Set_Current_Range(unsigned char d); void Set_Remap_Format(unsigned char d); void Set_Start_Line(unsigned char d); void Set_Display_Offset(unsigned char d); void Set_Display_Mode(unsigned char d); void Set_Multiplex_Ratio(unsigned char d); void Set_Master_Config(unsigned char d); void Set_Display_On_Off(unsigned char d); void Set_Phase_Length(unsigned char d); void Set_Frame_Frequency(unsigned char d); void Set_Display_Clock(unsigned char d); void Set_Precharge_Compensation(unsigned char a, unsigned char b); void Set_Precharge_Voltage(unsigned char d); void Set_VCOMH(unsigned char d); void Set_VSL(unsigned char d); void Set_NOP(); void GA_Option(unsigned char d); void Draw_Rectangle(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e); void Copy(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e, unsigned char f); void Fill_RAM(unsigned char a); void Fill_Block(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e); void Checkerboard(); void Grayscale(); void Frame(); void delay(unsigned int i) { while(i) { i--; } } /*写指令*/ void Write_Command(unsigned char Data) { DC=0; CS=0; RW=0; xData=Data; RW=1; CS=1; DC=1; } void Write_Data(unsigned char Data) { DC=1; CS=0; RW=0; xData=Data; RW=1; CS=1; DC=1; } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Instruction Setting //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Set_Column_Address(unsigned char a, unsigned char b) { Write_Command(0x15); // Set Column Address Write_Command(a); // Default => 0x00 Write_Command(b); // Default => 0x3F (Total Columns Devided by 2) } void Set_Row_Address(unsigned char a, unsigned char b) { Write_Command(0x75); // Set Row Address Write_Command(a); // Default => 0x00 Write_Command(b); // Default => 0x4F } void Set_Contrast_Current(unsigned char d) { Write_Command(0x81); // Set Contrast Value Write_Command(d); // Default => 0x40 } void Set_Current_Range(unsigned char d) { Write_Command(0x84|d); // Set Current Range // Default => 0x84 // 0x84 (0x00) => Quarter Current Range // 0x85 (0x01) => Half Current Range // 0x86 (0x02) => Full Current Range } void Set_Remap_Format(unsigned char d) { Write_Command(0xA0); // Set Re-Map & Data Format Write_Command(d); // Default => 0x00 // Column Address 0 Mapped to SEG0 // Disable Nibble Re-Map // Horizontal Address Increment // Scan from COM0 to COM[N-1] // Disable COM Split Odd Even } void Set_Start_Line(unsigned char d) { Write_Command(0xA1); // Set Display Start Line Write_Command(d); // Default => 0x00 } void Set_Display_Offset(unsigned char d) { Write_Command(0xA2); // Set Display Offset Write_Command(d); // Default => 0x00 } void Set_Display_Mode(unsigned char d) { Write_Command(0xA4|d); // Set Display Mode // Default => 0xA4 // 0xA4 (0x00) => Normal Display // 0xA5 (0x01) => Entire Display On, All Pixels Turn On at GS Level 15 // 0xA6 (0x02) => Entire Display Off, All Pixels Turn Off // 0xA7 (0x03) => Inverse Display } void Set_Multiplex_Ratio(unsigned char d) { Write_Command(0xA8); // Set Multiplex Ratio Write_Command(d); // Default => 0x5F } void Set_Master_Config(unsigned char d) { Write_Command(0xAD); // Set Master Configuration Write_Command(0x02|d); // Default => 0x03 // 0x02 (0x00) => Select External VCC Supply // 0x03 (0x01) => Select Internal DC/DC Voltage Converter } void Set_Display_On_Off(unsigned char d) { Write_Command(0xAE|d); // Set Display On/Off // Default => 0xAE // 0xAE (0x00) => Display Off // 0xAF (0x01) => Display On } void Set_Phase_Length(unsigned char d) { Write_Command(0xB1); // Phase 1 & 2 Period Adjustment Write_Command(d); // Default => 0x53 (5 Display Clocks [Phase 2] / 3 Display Clocks [Phase 1]) // D[3:0] => Phase 1 Period in 1~15 Display Clocks // D[7:4] => Phase 2 Period in 1~15 Display Clocks } void Set_Frame_Frequency(unsigned char d) { Write_Command(0xB2); // Set Frame Frequency (Row Period) Write_Command(d); // Default => 0x25 (37 Display Clocks) } void Set_Display_Clock(unsigned char d) { Write_Command(0xB3); // Display Clock Divider/Osciallator Frequency Write_Command(d); // Default => 0x41 // D[3:0] => Display Clock Divider // D[7:4] => Oscillator Frequency } void Set_Precharge_Compensation(unsigned char a, unsigned char b) { Write_Command(0xB4); // Set Pre-Charge Compensation Level Write_Command(b); // Default => 0x00 (No Compensation) if(a == 0x20) { Write_Command(0xB0); // Set Pre-Charge Compensation Enable Write_Command(0x08|a); // Default => 0x08 // 0x08 (0x00) => Disable Pre-Charge Compensation // 0x28 (0x20) => Enable Pre-Charge Compensation } } void Set_Precharge_Voltage(unsigned char d) { Write_Command(0xBC); // Set Pre-Charge Voltage Level Write_Command(d); // Default => 0x10 (Connect to VCOMH) } void Set_VCOMH(unsigned char d) { Write_Command(0xBE); // Set Output Level High Voltage for COM Signal Write_Command(d); // Default => 0x1D (0.81*VREF) } void Set_VSL(unsigned char d) { Write_Command(0xBF); // Set Segment Low Voltage Level Write_Command(0x02|d); // Default => 0x0E // 0x02 (0x00) => Keep VSL Pin Floating // 0x0E (0x0C) => Connect a Capacitor between VSL Pin & VSS } void Set_NOP() { Write_Command(0xE3); // Command for No Operation } //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Graphic Acceleration //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void GA_Option(unsigned char d) { Write_Command(0x23); // Graphic Acceleration Command Options Write_Command(d); // Default => 0x01 // Enable Fill Rectangle // Disable Wrap around in Horizontal Direction During Copying & Scrolling // Disable Reverse Copy } void Draw_Rectangle(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e) { Write_Command(0x24); // Draw Rectangle Write_Command(a); // Column Address of Start Write_Command(c); // Row Address of Start Write_Command(b); // Column Address of End (Total Columns Devided by 2) Write_Command(d); // Row Address of End Write_Command(e); // Gray Scale Level delay(1); } void Copy(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e, unsigned char f) { Write_Command(0x25); // Copy Write_Command(a); // Column Address of Start Write_Command(c); // Row Address of Start Write_Command(b); // Column Address of End (Total Columns Devided by 2) Write_Command(d); // Row Address of End Write_Command(e); // Column Address of New Start Write_Command(f); // Row Address of New Start delay(1); } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Show Regular Pattern (Full Screen) // // a: Two Pixels Data //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Fill_RAM(unsigned char a) { GA_Option(0x01); Draw_Rectangle(0x00,0x3F,0x00,0x5F,a); } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Show Regular Pattern (Partial or Full Screen) // // a: Column Address of Start // b: Column Address of End (Total Columns Devided by 2) // c: Row Address of Start // d: Row Address of End // e: Two Pixels Data //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Fill_Block(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e) { GA_Option(0x01); Draw_Rectangle(a,b,c,d,e); } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Show Checkboard (Full Screen) //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Checkerboard() { unsigned char i,j; Set_Column_Address(0x00,0x3F); Set_Row_Address(0x00,0x5F); for(i=0;i<40;i++) { for(j=0;j<64;j++) { Write_Data(0xF0); } for(j=0;j<64;j++) { Write_Data(0x0F); } } } void Clear() { unsigned char i,j; Set_Column_Address(0x00,0x3F); Set_Row_Address(0x00,0x5F); for(i=0;i<80;i++) { for(j=0;j<128;j++) { Write_Data(0x00); } } } //************************显示横条 竖条 void Dsiplay_HT(unsigned char Data0,unsigned char Data1) { unsigned char i; unsigned char j; Set_Column_Address(0x00,0x3F); Set_Row_Address(0x00,0x5F); for(i=0;i<40;i++) { for(j=0;j<64;j++) { Write_Data(Data0); } for(j=0;j<64;j++) { Write_Data(Data1); } } } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Show Gray Scale Bar (Full Screen) //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Grayscale() { // Level 16 => Column 1~8 Fill_Block(0x00,0x03,0x00,0x3F,0xFF); // Level 15 => Column 9~16 Fill_Block(0x04,0x07,0x00,0x3F,0xEE); // Level 14 => Column 17~24 Fill_Block(0x08,0x0B,0x00,0x3F,0xDD); // Level 13 => Column 25~32 Fill_Block(0x0C,0x0F,0x00,0x3F,0xCC); // Level 12 => Column 33~40 Fill_Block(0x10,0x13,0x00,0x3F,0xBB); // Level 11 => Column 41~48 Fill_Block(0x14,0x17,0x00,0x3F,0xAA); // Level 10 => Column 49~56 Fill_Block(0x18,0x1B,0x00,0x3F,0x99); // Level 9 => Column 57~64 Fill_Block(0x1C,0x1F,0x00,0x3F,0x88); // Level 8 => Column 65~72 Fill_Block(0x20,0x23,0x00,0x3F,0x77); // Level 7 => Column 73~80 Fill_Block(0x24,0x27,0x00,0x3F,0x66); // Level 6 => Column 81~88 Fill_Block(0x28,0x2B,0x00,0x3F,0x55); // Level 5 => Column 89~96 Fill_Block(0x2C,0x2F,0x00,0x3F,0x44); // Level 4 => Column 97~104 Fill_Block(0x30,0x33,0x00,0x3F,0x33); // Level 3 => Column 105~112 Fill_Block(0x34,0x37,0x00,0x3F,0x22); // Level 2 => Column 113~120 Fill_Block(0x38,0x3B,0x00,0x3F,0x11); // Level 1 => Column 121~128 Fill_Block(0x3C,0x3F,0x00,0x3F,0x00); } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Show Frame (Full Screen) //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Frame() { GA_Option(0x00); Draw_Rectangle(0x00,0x3F,0x00,0x3F,0xFF); Fill_Block(0x00,0x00,0x01,0x3E,0x0F); Fill_Block(0x3F,0x3F,0x01,0x3E,0xF0); } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Show Pattern (Partial or Full Screen) // // a: Column Address of Start // b: Column Address of End (Total Columns Devided by 2) // c: Row Address of Start // d: Row Address of End //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Show_Pattern(unsigned char *Data_Pointer, unsigned char a, unsigned char b, unsigned char c, unsigned char d) { unsigned char *Src_Pointer; unsigned char i,j; Src_Pointer=Data_Pointer; Set_Column_Address(a,b); Set_Row_Address(c,d); for(i=0;i<(b-a+1);i++) { for(j=0;j<(d-c+1);j++) { Write_Data(*Src_Pointer); Src_Pointer++; } } } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Show Pattern (Partial or Full Screen) // // a: Column Address of Start // b: Column Address of End (Total Columns Devided by 2) // c: Row Address of Start // d: Row Address of End //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Show_Pattern_Bit(unsigned char *Data_Pointer, unsigned char a, unsigned char b, unsigned char c, unsigned char d) { unsigned char *Src_Pointer; unsigned char i,j; Src_Pointer=Data_Pointer; Set_Column_Address(a,b); Set_Row_Address(c,d); for(i=0;i<(b-a+1);i++) { for(j=0;j<(d-c+1);j++) { Write_Data(*Src_Pointer); for(j = 0;j < 8;j++) { if( (*Src_Pointer)&(0x80>>j) == 0) { Write_Data(0x00); } else if((*Src_Pointer)&(0x80>>j)!= 0) { Write_Data(0x01); } } Src_Pointer++; } } } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Vertical Scrolling (Full Screen) // // a: Scrolling Direction // "0x00" (Upward) // "0x01" (Downward) // b: Set Numbers of Row Scroll per Step // c: Set Time Interval between Each Scroll Step //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Vertical_Scroll(unsigned char a, unsigned char b, unsigned char c) { unsigned int i,j; switch(a) { case 0: for(i=0;i<80;i+=b) { Set_Start_Line(i); for(j=0;j0;i--) { Set_Contrast_Current(i-1); delay(10); } Set_Display_On_Off(0x00); } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Sleep Mode // // "0x01" Enter Sleep Mode // "0x00" Exit Sleep Mode //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Sleep(unsigned char a) { switch(a) { case 0: Set_Display_On_Off(0x00); Set_Display_Mode(0x01); break; case 1: Set_Display_Mode(0x00); Set_Display_On_Off(0x01); break; } } //******************显示图片 void Display_Pic() { unsigned int i; unsigned char j; unsigned char Change_data; unsigned char Data; Set_Column_Address(0x00,0x3F); Set_Row_Address(0x00,0x5F); Set_Start_Line(0x00); //1100 0000 0XC0 for(i=0;i<1024;i++) { Data=Pic[i]; for(j=0;j<4;j++) //0110 0001 Table[k] { //0F F0 00 0F Change_data[j] if((Data&0XC0) == 0x00) { Change_data=0X00; } else if((Data&0XC0) == 0x40) { Change_data=0X0F; } else if((Data&0XC0) == 0xC0) { Change_data=0XFF; } else { Change_data=0XF0; } Write_Data(Change_data); Data=Data<<2; } } } void Display_Pic0() { unsigned int i; unsigned char j; unsigned char Change_data; unsigned char Data; Set_Column_Address(0x00,0x3F); Set_Row_Address(0x00,0x5F); Set_Start_Line(0x00); //1100 0000 0XC0 for(i=0;i<1024;i++) { Data=Pic1[i]; for(j=0;j<4;j++) //0110 0001 Table[k] { //0F F0 00 0F Change_data[j] if((Data&0XC0) == 0x00) { Change_data=0X00; } else if((Data&0XC0) == 0x40) { Change_data=0X0F; } else if((Data&0XC0) == 0xC0) { Change_data=0XFF; } else { Change_data=0XF0; } Write_Data(Change_data); Data=Data<<2; } } } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Gray Scale Table Setting (Full Screen) //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Set_Gray_Scale_Table() { Write_Command(0xB8); // Set Gray Scale Table Write_Command(0x01); // Gray Scale Level 1 Write_Command(0x11); // Gray Scale Level 3 & 2 Write_Command(0x22); // Gray Scale Level 5 & 4 Write_Command(0x32); // Gray Scale Level 7 & 6 Write_Command(0x43); // Gray Scale Level 9 & 8 Write_Command(0x54); // Gray Scale Level 11 & 10 Write_Command(0x65); // Gray Scale Level 13 & 12 Write_Command(0x76); // Gray Scale Level 15 & 14 } //SSD1325 void OLED_Init() { unsigned char i; RES=0; for(i=0;i<200;i++) { delay(200); } RES=1; Set_Display_On_Off(0x00); // Display Off (0x00/0x01) Set_Display_Clock(0x41); // Set Clock as 135 Frames/Sec Set_Multiplex_Ratio(0x3F); // 1/64 Duty (0x0F~0x5F) Set_Display_Offset(0x4c); // Shift Mapping RAM Counter (0x00~0x5F) Set_Start_Line(0x00); // Set Mapping RAM Display Start Line (0x00~0x5F) Set_Master_Config(0x00); // Disable Embedded DC/DC Converter (0x00/0x01) Set_Remap_Format(0x52); // Set Column Address 0 Mapped to SEG0 // Disable Nibble Remap // Horizontal Address Increment // Scan from COM[N-1] to COM0 // Enable COM Split Odd Even Set_Current_Range(0x02); // Set Full Current Range Set_Gray_Scale_Table(); // Set Pulse Width for Gray Scale Table Set_Contrast_Current(Brightness); // Set Scale Factor of Segment Output Current Control Set_Frame_Frequency(0x46); // Set Frame Frequency Set_Phase_Length(0x22); // Set Phase 1 as 2 Clocks & Phase 2 as 2 Clocks Set_Precharge_Voltage(0x10); // Set Pre-Charge Voltage Level Set_Precharge_Compensation(0x20,0x07); // Set Pre-Charge Compensation Set_VCOMH(0x02); // Set High Voltage Level of COM Pin Set_VSL(0x0C); // Set Low Voltage Level of SEG Pin Set_Display_Mode(0x00); // Normal Display Mode (0x00/0x01/0x02/0x03) Fill_RAM(0x00); // Clear Screen Set_Display_On_Off(0x01); // Display On (0x00/0x01) } void Display_Char(unsigned char x,unsigned char Line,unsigned char*p) { unsigned char i; unsigned char j; unsigned char Data; unsigned char Change_data; Set_Column_Address(x,x+8); Set_Row_Address(Line,Line+16); Set_Start_Line(Line); for(i=0;i<16;i++) { Data=*p; Set_Start_Line(Line+i); for(j=0;j<4;j++) //0110 0001 Table[k] { //0F F0 00 0F Change_data[j] if((Data&0XC0) == 0x00) { Change_data=0X00; } else if((Data&0XC0) == 0x40) { Change_data=0X0F; } else if((Data&0XC0) == 0xC0) { Change_data=0XFF; } else { Change_data=0XF0; } Write_Data(Change_data); Data=Data<<2; } p++; } } // void Display_Chinese(unsigned char x,unsigned char Page,unsigned char*p) // { // // } void main() { OLED_Init(); while(1) { Clear(); Display_Pic(); delay(65530); delay(30000); Display_Pic0(); delay(65530); delay(30000); Clear(); } }

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