////////////////////////////////////////////////////////////////////////// #includeunsigned char code Text_1 []="0123456789abcdef";//16位字符 unsigned char code Text_2 []="0123456789ABCDEF";//16位字符 void LCD_MS(ms) { unsigned int x,y; for(x=ms;x>0;x--) for(y=60;y>0;y--); } void Write_595(unsigned char Data) { unsigned char j; SH_CP=0; ST_CP=1; for (j=0;j<8;j++) { Data=Data<<1; DS_595=CY; SH_CP=1; LCD_MS(1); SH_CP=0; } ST_CP=0; LCD_MS(1); ST_CP=1; LCD_MS(1); ST_CP=0 ; } void LCD_Write_Com(unsigned char LCD_Com)//LCD写命令 { LCD_RS=0; LCD_EN=1; Write_595(LCD_Com); LCD_MS(5); LCD_EN=0; } void LCD_Write_Data(unsigned char LCD_Data)//LCD写数据 { LCD_RS=1; LCD_EN=1; Write_595(LCD_Data); LCD_MS(5); LCD_EN=0; } void LCD_INIT()//LCD初始化 { LCD_Write_Com(0x38); LCD_Write_Com(0x01); LCD_Write_Com(0x06); LCD_Write_Com(0x0C); LCD_Write_Com(0x80); } void LCD_CLS()//LCD清屏 { LCD_Write_Com(0x0C); LCD_Write_Com(0x80); } void LCD_Glint(unsigned char LCD_Line, unsigned char Addess)//光标闪烁位置 { unsigned char Line; if(LCD_Line==1)Line=0x80; if(LCD_Line==2)Line=(0x80+0x40); LCD_Write_Com(0x0d); LCD_Write_Com(Line+(Addess-1)); } void LCD_Text()//显示预设字符 { unsigned char num; LCD_CLS(); for(num=0;num<16;num++) { LCD_Write_Data(Text_1[num]); //第一行 LCD_MS(1); } LCD_Write_Com(0x80+0x40); for(num=0;num<16;num++) { LCD_Write_Data(Text_2[num]); //第二行 LCD_MS(1); } } ///////////////////////////////////////////////////////// #ifndef __LCD1602_H__ #define __LCD1602_H__ #include sbit LCD_RS=P1^7; sbit LCD_EN=P1^6; sbit LCD_BG=P1^2;//74HC595_P12 sbit SH_CP=P1^3;//74HC595_P11 sbit DS_595=P1^5;//74HC595_P14 sbit ST_CP=P1^4;//74HC595_P12 /* ISIS仿真 sbit LCD_RS=P0^0; sbit LCD_EN=P0^1; sbit SH_CP=P0^2;//74HC595_P11 sbit DS_595=P0^3;//74HC595_P14 sbit ST_CP=P0^4;//74HC595_P12 */ void LCD_Write_Com(unsigned char LCD_Com); /*LCD写入命令*/ void LCD_INIT(); /*LCD初始化*/ void LCD_CLS(); /*LCD清屏*/ void LCD_Glint(unsigned char Line, unsigned char Addess); /*光标闪烁位置*/ void LCD_Text(); /*显示预设字符*/ #endif /////////////////////////////////////////////////////////////
上一篇:STC12C5A60S2单片机PWM程序
下一篇:HOLTEK单片机-秒表
推荐阅读最新更新时间:2024-03-16 14:26