在LCD1602上面顯示"I LOVE MCU!"和"I LOVE MCU!"
#include
//#define uchar unsigned char;
sbit RS = P1^2; //位定義,液晶的數(shù)據(jù)/命令選擇
sbit RW = P1^1; //位定義,液晶的讀寫選擇
sbit EN = P1^0; //位定義,液晶使能信號
//#define LCDPORT P2 //液晶的數(shù)據(jù)口
unsigned char code table[]="I LOVE MCU!"; //在CODE區(qū)定義一個用于顯示的常量字符串
unsigned char code table1[]="www.zstudy.com"; //在CODE區(qū)定義一個用于顯示的常量字符串
void delay(unsigned int ms); //延時函數(shù)
unsigned char num;
void write_com(unsigned char com)
{
RS=0;
P2=com;
delay(20);
EN=1;
delay(20);
EN=0;
}
void write_data(unsigned char date)
{
RS=1;
P2=date;
delay(20);
EN=1;
delay(20);
EN=0;
}
void init()
{
RW=0;
EN=0;
write_com(0x38);
write_com(0x0f);
write_com(0x06);
write_com(0x01);
}
/******************************************************************************
函數(shù)名稱:main
函數(shù)功能:程序主函數(shù)
入口參數(shù):無
返回值:無
備注:無
*******************************************************************************/
void main(void)
{
init();
write_com(0x80);
for(num=0;num<11;num++)
{
write_data(table[num]);
delay(20);
}
write_com(0x80+0x40);
for(num=0;num<14;num++)
{
write_data(table1[num]);
delay(20);
}
while(1);
}
void delay(unsigned int ms)
{
unsigned char j = 110;
for(;ms > 0;ms--) while(--j);
}