ST7527 3线式串口驱动程序,3-Line 8-bit SPI Program
/* Includes ------------------------------------------------------------------*/ #include <intrins.h> #include "STC11.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ sbit CS = P3^5; //片选 sbit RST = P2^0; //复位 sbit SCL = P3^7; //Clock信号 sbit SDA = P3^6; //数据 /* Private macro -------------------------------------------------------------*/ #define LcdXPixel (80) #define LcdYPixel (80) #define CONTRAST (100) #define STARTSEG (0) /* Private variables ---------------------------------------------------------*/ u8 code ComTable[]={9,8,7,6,5,4,3,2,1,0}; u8 code nAsciiDot6X8[]; u8 code BMP1[]; u8 code driveric[]="IC:ST7527"; u8 code str1[]="LCDBBS.NET"; /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ void DelayMS(u16 MS) { //For 40M STC89C516 : usn=9 us=182 //For 22.1184 STC11F60 : usn=45 us=182 u8 us,usn,i; while(MS!=0) { usn = 45; while(usn!=0) { us=182; while (us!=0){us--;}; usn--; } for(i=0;i<3;i++); MS--; } } static void LcdWrCmd( u8 CommandByte ) { u8 i; CS = 0; for(i=0;i<8;i++) { SCL = 0; if(CommandByte&0x80) SDA = 1; else SDA = 0; _nop_(); _nop_(); _nop_(); SCL = 1; _nop_(); _nop_(); _nop_(); CommandByte = CommandByte<<1; } CS = 1; } static void LcdWrByte( u8 bbyte ) { u8 i; for(i=0;i<8;i++) { SCL = 0; if(bbyte&0x80) SDA = 1; else SDA = 0; _nop_(); _nop_(); _nop_(); SCL = 1; _nop_(); _nop_(); _nop_(); bbyte = bbyte<<1; } } void LCD_FillScreen( u8 FillData ) { u16 i,j; for(i=0;i<(LcdYPixel/8);i++) { LcdWrCmd(0x30); //指令集切换 H[1:0]=00 CS = 0; LcdWrByte(0x40|ComTable[i]); //Set Page Address LcdWrByte( (STARTSEG>>4) | 0xF0 ); //Set Column Address(H) LcdWrByte( (STARTSEG&0x0F)|0xE0 ); //Set Column Address(L) LcdWrByte( (LcdXPixel>>8) |0x70 ); //Set No. of Data Bytes(H) LcdWrByte( ( (LcdXPixel&0xFF) >>4)|0x60 ); //Set No. of Data Bytes(M) LcdWrByte( (LcdXPixel&0x0F) |0x50 ); //Set No. of Data Bytes(L) & Start for(j=0;j<LcdXPixel;j++) { LcdWrByte( FillData ); } CS = 1; } } void LCD_Initial(void) { DelayMS(10); RST = 0; DelayMS(10); RST = 1; DelayMS(10); LcdWrCmd(0x31); //MX=1=S131->S0, MY=0=C0->C79, PD=0=active, H[1:0]=01 LcdWrCmd(0x47); //Power Control, VC VR VF turn on DelayMS(300); LcdWrCmd(0x30); //MX=1=S131->S0, MY=0=C0->C79, PD=0=active, H[1:0]=00 LcdWrCmd(0x04); //Set Vop Rang, PRS=0, V0 programming range LOW LcdWrCmd(0x31); //MX=1=S131->S0, MY=0=C0->C79, PD=0=active, H[1:0]=01 LcdWrCmd(0x11); //Set Bias = 1/10 LcdWrCmd(0x65); //Set Booster = x6 LcdWrCmd(0x80|CONTRAST); //Set Vop LcdWrCmd(0x32); //MX=1=S131->S0, MY=0=C0->C79, PD=0=active, H[1:0]=10 LcdWrCmd(0x04); //Set Partial Screen Mode = Disable LcdWrCmd(0x30); //MX=1=S131->S0, MY=0=C0->C79, PD=0=active, H[1:0]=00 LcdWrCmd(0x0C); //Display ON, Normal display DelayMS(10); } //-----------------------------------------6x8字符------------------------------------- //显示ASICC字符的函数 void LCD_PutChar6X8(u8 col,u8 page,u8 Order) { u8 i; u16 x; x = (Order-0x20)*0x06; //ASICC字符从0x20开始,每个6 byte LcdWrCmd(0x30); //指令集切换 H[1:0]=00 CS = 0; LcdWrByte(0x40|ComTable[page]); //Set Page Address LcdWrByte( ((col+STARTSEG)>>4) | 0xF0 ); //Set Column Address(H) LcdWrByte( ((col+STARTSEG)&0x0F)|0xE0 ); //Set Column Address(L) LcdWrByte( (6>>8) |0x70 ); //Set No. of Data Bytes(H) LcdWrByte( ( (6&0xFF) >>4)|0x60 ); //Set No. of Data Bytes(M) LcdWrByte( (6&0x0F) |0x50 ); //Set No. of Data Bytes(L) & Start for(i=0;i<6;i++) { LcdWrByte( nAsciiDot6X8[x] ); x++; } CS = 1; } //显示字符串的函数 void LCD_PutStr6X8(u8 col,u8 page,u8 *puts) { while(*puts != '\0') //判断字符串时候显示完毕 { if(col>(LcdXPixel-6)) //判断行末空间是否足够放一个字符,自动换行 { page=page+1; col=0; } if(page>(LcdYPixel/8-1)) //到了屏幕最下角,自动返回左上角 { page=0; col=0; } LCD_PutChar6X8(col,page,*puts); puts++; col=col+6; //下一个字符6列之后 } } //显示全屏图片 void LCD_PutBmp( u8 *puts ) { u16 i,j; u16 X=0; for(i=0;i<(LcdYPixel/8);i++) //可以用sizeof(ComTable) { LcdWrCmd(0x30); //指令集切换 H[1:0]=00 CS = 0; LcdWrByte(0x40|ComTable[i]); //Set Page Address LcdWrByte( (STARTSEG>>4) | 0xF0 ); //Set Column Address(H) LcdWrByte( (STARTSEG&0x0F)|0xE0 ); //Set Column Address(L) LcdWrByte( (LcdXPixel>>8) |0x70 ); //Set No. of Data Bytes(H) LcdWrByte( ( (LcdXPixel&0xFF) >>4)|0x60 ); //Set No. of Data Bytes(M) LcdWrByte( (LcdXPixel&0x0F) |0x50 ); //Set No. of Data Bytes(L) & Start for(j=0;j<LcdXPixel;j++) { LcdWrByte( puts[X] ); X++; } CS = 1; } } void Main( void ) { P2M0 = 0x01 ; //设置IO口推挽输出 P2M1 = 0x00 ; P3M0 = 0xE0 ; P3M1 = 0x00 ; LCD_Initial(); while(1) { LCD_PutBmp(BMP1); LCD_PutStr6X8(3,7,driveric); LCD_PutStr6X8(3,8,str1); while(1); } } // ------------------ ASCII字模的数据表 ------------------------ // // 码表从0x20~0x7e // // 字库: LcmZimo_xiaoqi\Asc5x8E.dot 纵向取模上高位 // // 备注: 取模后是5x8,手动在最后补了一列0x00凑成6x8 // // -------------------------------------------------------------- // u8 code nAsciiDot6X8[]={ // ASCII 0x00,0x00,0x00,0x00,0x00,0x00, // - - 0x00,0x00,0xFA,0x00,0x00,0x00, // -!- 0x00,0xE0,0x00,0xE0,0x00,0x00, // -"- 0x28,0xFE,0x28,0xFE,0x28,0x00, // -#- 0x24,0x74,0xDE,0x54,0x48,0x00, // -$- 0xC4,0xC8,0x10,0x26,0x46,0x00, // -%- 0x6C,0x92,0x6A,0x04,0x0A,0x00, // -&- 0x00,0x20,0xC0,0x80,0x00,0x00, // -'- 0x00,0x38,0x44,0x82,0x00,0x00, // -(- 0x00,0x82,0x44,0x38,0x00,0x00, // -)- 0x44,0x28,0xFE,0x28,0x44,0x00, // -*- 0x10,0x10,0xFE,0x10,0x10,0x00, // -+- 0x02,0x0C,0x08,0x00,0x00,0x00, // -,- 0x10,0x10,0x10,0x10,0x10,0x00, // --- 0x00,0x06,0x06,0x00,0x00,0x00, // -.- 0x04,0x08,0x10,0x20,0x40,0x00, // -/- 0x7C,0x8A,0x92,0xA2,0x7C,0x00, // -0- 0x00,0x42,0xFE,0x02,0x00,0x00, // -1- 0x46,0x8A,0x92,0x92,0x62,0x00, // -2- 0x84,0x82,0x92,0xB2,0xCC,0x00, // -3- 0x18,0x28,0x48,0xFE,0x08,0x00, // -4- 0xE4,0xA2,0xA2,0xA2,0x9C,0x00, // -5- 0x3C,0x52,0x92,0x92,0x8C,0x00, // -6- 0x80,0x8E,0x90,0xA0,0xC0,0x00, // -7- 0x6C,0x92,0x92,0x92,0x6C,0x00, // -8- 0x62,0x92,0x92,0x94,0x78,0x00, // -9- 0x00,0x6C,0x6C,0x00,0x00,0x00, // -:- 0x02,0x6C,0x6C,0x00,0x00,0x00, // -;- 0x10,0x28,0x44,0x82,0x00,0x00, // -<- 0x28,0x28,0x28,0x28,0x28,0x00, // -=- 0x00,0x82,0x44,0x28,0x10,0x00, // ->- 0x40,0x80,0x9A,0xA0,0x40,0x00, // -?- 0x7C,0x82,0xBA,0xAA,0x7A,0x00, // -@- 0x3E,0x48,0x88,0x48,0x3E,0x00, // -A- 0xFE,0x92,0x92,0x92,0x6C,0x00, // -B- 0x7C,0x82,0x82,0x82,0x44,0x00, // -C- 0xFE,0x82,0x82,0x82,0x7C,0x00, // -D- 0xFE,0x92,0x92,0x92,0x82,0x00, // -E- 0xFE,0x90,0x90,0x90,0x80,0x00, // -F- 0x7C,0x82,0x8A,0x8A,0x4E,0x00, // -G- 0xFE,0x10,0x10,0x10,0xFE,0x00, // -H- 0x00,0x82,0xFE,0x82,0x00,0x00, // -I- 0x04,0x02,0x82,0xFC,0x80,0x00, // -J- 0xFE,0x10,0x28,0x44,0x82,0x00, // -K- 0xFE,0x02,0x02,0x02,0x02,0x00, // -L- 0xFE,0x40,0x30,0x40,0xFE,0x00, // -M- 0xFE,0x20,0x10,0x08,0xFE,0x00, // -N- 0x7C,0x82,0x82,0x82,0x7C,0x00, // -O- 0xFE,0x90,0x90,0x90,0x60,0x00, // -P- 0x7C,0x82,0x8A,0x84,0x7A,0x00, // -Q- 0xFE,0x90,0x98,0x94,0x62,0x00, // -R- 0x64,0x92,0x92,0x92,0x4C,0x00, // -S- 0x80,0x80,0xFE,0x80,0x80,0x00, // -T- 0xFC,0x02,0x02,0x02,0xFC,0x00, // -U- 0xF8,0x04,0x02,0x04,0xF8,0x00, // -V- 0xFE,0x04,0x18,0x04,0xFE,0x00, // -W- 0xC6,0x28,0x10,0x28,0xC6,0x00, // -X- 0xC0,0x20,0x1E,0x20,0xC0,0x00, // -Y- 0x86,0x8A,0x92,0xA2,0xC2,0x00, // -Z- 0xFE,0xFE,0x82,0x82,0x00,0x00, // -[- 0x40,0x20,0x10,0x08,0x04,0x00, // -\- 0x00,0x82,0x82,0xFE,0xFE,0x00, // -]- 0x20,0x40,0xFE,0x40,0x20,0x00, // -^- 0x10,0x38,0x54,0x10,0x10,0x00, // -_- 0x00,0x00,0x80,0x40,0x20,0x00, // -`- 0x24,0x2A,0x2A,0x1C,0x02,0x00, // -a- 0xFE,0x14,0x22,0x22,0x1C,0x00, // -b- 0x1C,0x22,0x22,0x22,0x10,0x00, // -c- 0x1C,0x22,0x22,0x14,0xFE,0x00, // -d- 0x1C,0x2A,0x2A,0x2A,0x10,0x00, // -e- 0x10,0x7E,0x90,0x90,0x40,0x00, // -f- 0x19,0x25,0x25,0x25,0x1E,0x00, // -g- 0xFE,0x10,0x20,0x20,0x1E,0x00, // -h- 0x00,0x00,0x9E,0x00,0x00,0x00, // -i- 0x00,0x01,0x11,0x9E,0x00,0x00, // -j- 0xFE,0x08,0x14,0x22,0x02,0x00, // -k- 0x00,0x82,0xFE,0x02,0x00,0x00, // -l- 0x1E,0x20,0x1E,0x20,0x1E,0x00, // -m- 0x20,0x1E,0x20,0x20,0x1E,0x00, // -n- 0x1C,0x22,0x22,0x22,0x1C,0x00, // -o- 0x3F,0x24,0x24,0x24,0x18,0x00, // -p- 0x18,0x24,0x24,0x24,0x3F,0x00, // -q- 0x20,0x1E,0x20,0x20,0x10,0x00, // -r- 0x12,0x2A,0x2A,0x2A,0x24,0x00, // -s- 0x20,0xFC,0x22,0x22,0x24,0x00, // -t- 0x3C,0x02,0x02,0x3C,0x02,0x00, // -u- 0x38,0x04,0x02,0x04,0x38,0x00, // -v- 0x3C,0x02,0x3C,0x02,0x3C,0x00, // -w- 0x22,0x14,0x08,0x14,0x22,0x00, // -x- 0x39,0x05,0x05,0x09,0x3E,0x00, // -y- 0x22,0x26,0x2A,0x32,0x22,0x00, // -z- 0x10,0x6C,0x82,0x00,0x00,0x00, // -{- 0x00,0x00,0xEE,0x00,0x00,0x00, // -|- 0x00,0x00,0x82,0x6C,0x10,0x00, // -}- 0x10,0x20,0x10,0x08,0x10,0x00, // -~- 0xAA,0x54,0xAA,0x54,0xAA,0x00, // -- }; u8 code BMP1[]={ /*-- 宽度x高度=80x80 --*/ 0xFF,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x81,0x83,0x83,0x86,0x8E,0x8C,0x8C,0x98,0x98,0x98,0x98,0x98, 0x98,0x98,0x8C,0x8C,0x8E,0x86,0x83,0x83,0x81,0x80,0x80,0x80,0x80,0x80,0x80,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x77,0xFF,0x98,0x8C,0xFF,0x77,0x00,0x00,0x00,0x7F,0xFF, 0x86,0xB0,0xFF,0x7F,0x00,0x31,0x3B,0x0E,0x0E,0x3B,0x31,0x00,0x00,0x77,0xFF,0x98, 0x8C,0xFF,0x77,0x00,0x00,0x00,0x7F,0xFF,0x86,0xB0,0xFF,0x7F,0x00,0x00,0x00,0x00, 0x00,0x07,0x3F,0x78,0xE0,0x80,0x00,0x00,0x18,0x3C,0x3C,0x18,0x00,0x00,0x00,0x00, 0x00,0x18,0x3C,0x3C,0x18,0x00,0x00,0x80,0xE0,0x78,0x3F,0x07,0x00,0x00,0x00,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x01,0x00,0x80, 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0x81, 0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00, 0x00,0xF0,0xFE,0x0F,0x03,0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, 0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x03,0x0F,0xFE,0xF0,0x00,0x00,0x00,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x08,0x08,0xF8,0x48,0x48, 0x48,0x48,0x4F,0x40,0x00,0x00,0x00,0x00,0xFF,0x80,0x98,0xE7,0x00,0x4C,0x74,0xC4, 0x5F,0x44,0x44,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xC0,0xE0,0x60,0x30,0x38,0x18,0x18,0x0C,0x0C,0x0C,0x0C,0x0C, 0x0C,0x0C,0x18,0x18,0x38,0x30,0x60,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x30,0x80,0x80,0xA0,0x98,0x80,0xA0, 0x98,0x80,0x80,0x20,0x18,0x00,0x00,0x00,0xF8,0x40,0x40,0x80,0x00,0x40,0x40,0x40, 0xF8,0x40,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0x07,0x0E,0x0C,0x18,0x38,0x30,0x30,0x60,0x60,0x60,0x60,0x60, 0x60,0x60,0x30,0x30,0x38,0x18,0x0C,0x0E,0x07,0x01,0x00,0x00,0x00,0x00,0x00,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x1F,0xFF,0xE0,0x80,0x00,0x00,0x01,0x60,0xF0,0xF0,0x60,0x00,0x00,0x00,0x00, 0x00,0x60,0xF0,0xF0,0x60,0x01,0x00,0x00,0x80,0xE0,0xFF,0x1F,0x00,0x00,0x00,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0xC0,0xF8,0x3C,0x0F,0x03,0x01,0xC0,0x70,0x18,0x0C,0x0C,0x06,0x06,0x06,0x06, 0x06,0x0C,0x0C,0x18,0x70,0xC0,0x01,0x03,0x0F,0x3C,0xF8,0xC0,0x00,0x00,0x00,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xE0,0x60,0x60,0x30,0x30,0x30,0x30,0x30, 0x30,0x30,0x60,0x60,0xE0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, 0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF, };
本文出自 LcdBBS,转载时请注明出处及相应链接。