新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 74HC595驅動LCD1602程序

74HC595驅動LCD1602程序

作者: 時間:2016-11-29 來源:網(wǎng)絡 收藏
為了節(jié)約端口,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寫數(shù)據(jù) { 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_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/////////////////////////////////////////////////////////////


關鍵詞: 74HC595LCD160

評論


技術專區(qū)

關閉