?? testlcd.c
字號(hào):
#include "reg52.h"
#include <intrins.h>
#define uchar unsigned char
typedef bit BOOL ;
sbit rs = P2^6 ;
sbit rw = P3^6 ;
sbit ep = P2^7 ;
void delay(uchar) ;
void lcd_wcmd(uchar) ;
BOOL lcd_bz() ;
void lcd_pos(uchar) ;
void lcd_wdat(uchar) ;
void display(uchar,uchar *) ;
code uchar dis1[] = {" www.52eda.com "} ;
code uchar dis2[] = {"WELCOME TO 52EDA"} ;
void longdelay(uchar s) //長(zhǎng)延時(shí)
{
while(s--)
{
delay(60) ;
}
}
void delay(uchar ms)
{ // 延時(shí)子程序
uchar i ;
while(ms--)
{
for(i = 0 ; i<250;i++) ;
}
}
BOOL lcd_bz()
{ // 測(cè)試LCD忙碌狀態(tài)
BOOL result ;
rs = 0 ;
rw = 1 ;
ep = 1 ;
result = (BOOL)(P0 & 0x80) ;
ep = 0 ;
return result ;
}
void lcd_wcmd(uchar cmd)
{ // 寫入指令數(shù)據(jù)到LCD
while(lcd_bz()) ;
rs = 0 ;
rw = 0 ;
ep = 0 ;
P0 = cmd ;
ep = 1 ;
ep = 0 ;
}
void lcd_pos(uchar pos)
{ //設(shè)定顯示位置
lcd_wcmd(pos | 0x80) ;
}
void lcd_wdat(uchar dat)
{ //寫入字符顯示數(shù)據(jù)到LCD
while(lcd_bz()) ;
rs = 1 ;
rw = 0 ;
ep = 0 ;
P0 = dat ;
ep = 1 ;
ep = 0 ;
}
void lcd_init()
{ //LCD初始化設(shè)定
lcd_wcmd(0x38) ; //function set
delay(1) ;
lcd_wcmd(0x38) ; //function set
delay(1) ;
lcd_wcmd(0x08) ; //display on/off
delay(1) ;
lcd_wcmd(0x01) ; //清除LCD的顯示內(nèi)容
delay(1) ;
lcd_wcmd(0x06) ; //entry mode set
delay(1) ;
lcd_wcmd(0x0c) ; //entry mode set
delay(1) ;
}
/*---------------
函數(shù)名稱:display()
功能 :在LCD上顯示數(shù)組的數(shù)據(jù)
說(shuō)明 :先寫顯示地址,后寫顯示數(shù)據(jù)
調(diào)用 :lcd_wcmd(), lcd_pos()
入口參數(shù):pos 寫入的位置,q指向要寫入的數(shù)據(jù)所在的數(shù)組
返回值 :無(wú)
----------------*/
void display(uchar pos, uchar *q)
{
uchar i ;
//lcd_wcmd(0x01) ; //clear
delay(10) ;
lcd_pos(pos) ;
for(i=0 ;i<16;i++)
{
lcd_wdat(*q) ;
q++ ;
longdelay(2) ;
}
}
main()
{
lcd_init() ; // 初始化LCD
delay(10) ;
display(0x00,dis1) ;
display(0x40,dis2) ;
display(0x14,dis1) ;
display(0x54,dis2) ;
lcd_wcmd(0x07) ; //entry mode set
delay(1) ;
while(1)
{
display(0x00,dis1) ;
/*
display(0x40,dis2) ;
display(0x14,dis1) ;
display(0x54,dis2) ;
*/
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -