久久ER99热精品一区二区-久久精品99国产精品日本-久久精品免费一区二区三区-久久综合九色综合欧美狠狠

新聞中心

EEPW首頁 > 嵌入式系統 > 設計應用 > 89C52與LCD1602

89C52與LCD1602

作者: 時間:2016-11-29 來源:網絡 收藏
這兩天看了下C51的資料,熟悉一下語句,51的資源都還沒看,就急著寫了個這程序 ,很生硬的,總算是LCD1602工作并顯示起來了,

難點1:時序,難點2:LCD1602的11條指令;

本文引用地址:http://cqxgywz.com/article/201611/323375.htm

時序對了,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);}}//-------------------------------------------


關鍵詞: 89C52LCD160

評論


技術專區

關閉