標(biāo)題: LCD1602顯示單片機(jī)源碼 [打印本頁(yè)]

作者: gugu    時(shí)間: 2015-3-24 23:08
標(biāo)題: LCD1602顯示單片機(jī)源碼
這幾天精神狀態(tài)不佳,今天才出成果,LCD1602 顯示,由于使用的是字符型的LCD,所以無(wú)法顯示漢字,只能是字符,好了,代碼來(lái)襲~~
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit LCDE=P2^7;
sbit RS=P2^6;
sbit RW=P2^5;
uchar code table1[]="x=1,y=1";   //顯示第一行內(nèi)容
uchar code table2[]="x=2,y=2";           //顯示第二行內(nèi)容

void LCD_write_com(uchar com);          //寫(xiě)指令
void LCD_write_dat(uchar dat);           //寫(xiě)數(shù)據(jù)
void delay(uint z);
void init();


void LCD_write_com(uchar com)
{
RS=0;                  
P0=com;
delay(5);
LCDE=1;
delay(5);
LCDE=0;

}

void LCD_write_dat(uchar dat)
{
RS=1;
P0=dat;
delay(5);
LCDE=1;
delay(5);
LCDE=0;
}
void init()
{
RW=0;
LCD_write_com(0x38);         //數(shù)據(jù)總線8位,顯示2行,5*7點(diǎn)陣每字符
LCD_write_com(0x0c);         //顯示功能開(kāi),無(wú)光標(biāo)
LCD_write_com(0x06);          //光標(biāo)設(shè)置
LCD_write_com(0x80+0x10);  //數(shù)據(jù)指針位置
LCD_write_com(0x01);                   //清屏
}

void delay(uchar z)
{uint a,b;
for(a=z;a>0;a--)
for(b=110;b>0;b--);}

void main()
{uchar a;
init();
LCD_write_com(0x80);
for(a=0;a<7;a++)
{
LCD_write_dat(table1[a]);
delay(30);
}
LCD_write_com(0x80+0x40);
for(a=0;a<7;a++)
{LCD_write_dat(table2[a]);
delay(30);
}
delay(4500);
for(a=0;a<20;a++)
{
LCD_write_com(0x18);
delay(150);
}


}





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1