LCD1602显示C程序LCD1602显示C程序(2008-05-2718:40:44)标签:it#include<>#include<>#defineucharunsignedchar#defineuintunsignedint#defineLcdBusPORTAconstcharrs=0;//LCD端口定义constcharrw=1;constcharen=2;voidLcdIni(void);voidWrOp(uchardat);voidWrDat(uchardat);voidChkBusy(void);main(){LcdIni();WrOp(0x80);WrDat('F');WrDat('L');WrDat('A');WrDat('S');WrDat('H');WrDat('M');WrDat('A');WrDat('N');while(1);}voidLcdIni(){DDRA=0XFF;//设置PA输出PORTA=0XFF;//全部加上上拉电阻DDRC=0XFF;//设置PC为输出PORTC=0XFF;//全部加上上拉电阻WrOp(0x38);WrOp(0x06);//光标加1WrOp(0x0c);//开显示}voidWrOp(uchardat){uchari;ChkBusy();PORTC&=~BIT(rs);//RS=0PORTC&=~BIT(rw);//RW=0PORTC&=~BIT(en);//EN=0PORTA=dat;//送数据PORTC|=BIT(en);//EN=1for(i=1;i;i++);//延时PORTC&=~BIT(en);//EN=0}voidWrDat(uchardat){uchari;ChkBusy();PORTC|=BIT(rs);//rs=1PORTC&=~BIT(rw);//rw=0PORTC&=~BIT(en);//en=0PORTA=dat;//送数据PORTC|=BIT(en);//en=1for(i=1;i;i++);//延时PORTC&=~BIT(en);//en=0}voidChkBusy(){DDRA=0X00;//设置为输入PORTA=0X00;//不设置上拉电阻PORTC&=~BIT(rs);//RS=0PORTC|=BIT(rw);//RW=1PORTC|=BIT(en);//EN=1while(PINA&0x80);//送数据PORTC&=~BIT(en);//en=0DDRA=0xff;//设置为输出}SMC1602A(16*2)模拟口线接线方式连接线图:---------------------------------------------------|LCM-----51|LCM-----51|LCM------51|--------------------------------------------------||DB0-----|DB4-----|RW-------||DB1-----|DB5-----|RS-------||DB2-----|DB6-----|E--------||DB3-----|DB7-----|VLCD接1K电阻到GN
lcd1602显示c程序 来自淘豆网m.daumloan.com转载请标明出处.