为了节省端口,1602液晶我也改为595来驱动了,一共有2个文件都在下面,程序自己测试通过,在你自己的使用中只需要修正端口即可.
//////////////////////////////////////////////////////////////////////////#include <LCD1602.H>unsigned 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__#includesbit LCD_RS=P1^7; sbit LCD_EN=P1^6;sbit LCD_BG=P1^2;//74HC595_P12sbit SH_CP=P1^3;//74HC595_P11sbit DS_595=P1^5;//74HC595_P14sbit ST_CP=P1^4;//74HC595_P12/* ISIS仿真sbit LCD_RS=P0^0; sbit LCD_EN=P0^1;sbit SH_CP=P0^2;//74HC595_P11sbit DS_595=P0^3;//74HC595_P14sbit 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/////////////////////////////////////////////////////////////