完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include #include #define uchar unsigned char #define uint unsigned int //数据选择 #define rs_0 PORTA&=~BIT(0) #define rs_1 PORTA|=BIT(0) #define rs_t DDRA|=BIT(0) //使能端 #define lcden_0 PORTA&=~BIT(2) #define lcden_1 PORTA|=BIT(2) #define lcden_t DDRA|=BIT(2) //读写选择 #define rw_0 PORTA&=~BIT(1) #define rw_1 PORTA|=BIT(1) #define rw_t DDRA|=BIT(1) //数据并口 #define binkou PORTB #define binkou_t DDRB=0XFF //并串选择 #define p***_0 PORTD&=~BIT(7) #define p***_1 PORTD|=BIT(7) #define p***_t DDRD|=BIT(7) uchar const table[]={"1286原来是这样啊"}; uchar i; void delay(uint x) { uint i,j; for(i=x;i>0;i--) for(j=1141;j>0;j--); } //写命令 void write_com(uchar com) { rs_0; rw_0; lcden_1; delay(5); binkou=com; delay(5); lcden_0; } //写数据 void write_date(uchar date) { rs_1; rw_0; lcden_1; delay(1); binkou=date; delay(1); lcden_0; } //液晶初始化 void init(void) { rs_t; rw_t; lcden_t; binkou_t; p***_t; p***_1; lcden_0; delay(5); write_com(0x34); delay(5); write_com(0x30); delay(5); write_com(0x01); delay(5); write_com(0x0c); delay(5); write_com(0x06); delay(5); } //位置显示 void lcd_pos(uchar x,uchar y) { uchar pos; if(x==1) {x=0x80;} else if(x==2) {x=0x90;} if(x==3) {x=0x88;} else if(x==4) {x=0x98;} pos=x+y; write_com(pos); } void main(void) { delay(10); init(); lcd_pos(4,0); i=0; while(table[i]!=' |