这两天看了下C51的材料,了解一下句子,51的资源都还没看,就急着写了个这程序 ,很僵硬的,总算是LCD1602作业并显现起来了,
难点1:时序,难点2:LCD1602的11条指令;
时序对了,LCD1602基本上就能显现了:(LCD1602的老是忙等候,所以把忙等候改成10MS延时程序了);
下面是程序:
//------------------------------------------- #include#include #define dataport P0#define uchar unsigned char#define uint unsigned int// sbit RS =P2^4;// sbit RW =P2^3;// sbit En =P2^2;sbit RS=P2^0;sbit RW=P2^1;sbit En=P2^2;void delay_ms(uchar time){uchar i,j;for(i=time;i>0;i--){for(j=85;j>0;j--){;}}}/*/----------------------------------------- 忙等void read_bf(void){En=0;RS=0;RW=1;dataport=0xff;_nop_();_nop_();_nop_();En=1;while(dataport&0x80) ;En=0;} */bit lcd_bf(){bit result;RS=0;RW=1;En=1;_nop_();_nop_();_nop_();result=(bit)(P0&0x80);En=0;return result;}//-----------------------------------------写指令void write_command(uchar command){// read_bf();// while(lcd_bz());delay_ms(10);RW=0;RS=0;En=0;_nop_();_nop_(); dataport=command;_nop_();_nop_();_nop_();En=1;_nop_();_nop_();En=0;}//------------------------------------------写数据void write_data(uchar data_){// read_bf();// while(lcd_bz());delay_ms(10);RW=0;RS=1;En=0;_nop_();_nop_();dataport=data_;_nop_(); _nop_();_nop_();En=1;_nop_();_nop_();En=0;}//-------------------------------------------初始化void init_lcd(void){ delay_ms(15);write_command(0x38);delay_ms(5);write_command(0x38);delay_ms(5);write_command(0x38);while(lcd_bf());write_command(0x38); //8位数据双行57// while(lcd_bf());// write_command(0x08); //关显现while(lcd_bf());write_command(0x01); //清显现while(lcd_bf());write_command(0x06);while(lcd_bf());write_command(0x0c);}void lcd_disp(uchar addr,uchar a_data){write_command(addr);write_data(a_data);} //-------------------------------------------主函数void main(){// uchar ch[8]= {0x53,0x54,0x43,0x38,0x39,0x43,0x35,0x32};uchar ch[6]={"hello!"} ;uchar ch_1[16]={" 1234567890abcde"} ;uchar i,j,k;init_lcd();for(i=0;i<16;i++)lcd_disp(0x80+i,ch[i]) ;for(k=0;k<16;k++)lcd_disp(0xc0+k,ch_1[k]);for (i=0;i<16;i++)write_command(0x07) ;while(1){for(j=0;j<10;j++){write_command(0x1c); //右移delay_ms(500);}delay_ms(500);for(k=0;k<10;k++){ write_command(0x18); //左移delay_ms(500);}delay_ms(500);}}//-------------------------------------------