|
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int //宏定義
sbit CS = P2^6; //片選信號(hào)
sbit SID = P2^5; //串行數(shù)據(jù)
sbit SCLK = P2^7; //串行同步時(shí)鐘
sbit PSB = P3^2; //串并口選擇 1:并口模式; 0:串口模式;
#define CLEAR_SCREEN 0x01 //清屏指令:清屏且AC值為00H
#define AC_INIT 0x02 //將AC設(shè)置為00H。且游標(biāo)移到原點(diǎn)位置
#define CURSE_ADD 0x06 //設(shè)定游標(biāo)移到方向及圖像整體移動(dòng)方向(默認(rèn)游標(biāo)右移,圖像整體不動(dòng))
#define FUN_MODE 0x30 //工作模式:8位基本指令集
#define DISPLAY_ON 0x0c //顯示開,顯示游標(biāo),且游標(biāo)位置反白
#define DISPLAY_OFF 0x08 //顯示關(guān)
#define CURSE_DIR 0x14 //游標(biāo)向右移動(dòng):AC=AC+1
#define SET_CG_AC 0x40 //設(shè)置AC,范圍為:00H~3FH
#define SET_DD_AC 0x80
uint second,count,month,day ,minute,hour;
uchar code addr_tab[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,//第一行漢字位置
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,//第二行漢字位置
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,//第三行漢字位置
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,//第四行漢字位置
};
void initial();
void delayms(uint t) //約延時(shí)n(ms)
{
uint i;
while(t--)
{
for(i=0;i<125;i++);
}
}
void SendByte(uchar Dbyte)
{
uchar i;
for(i=0;i<8;i++)
{
SCLK = 0;
Dbyte=Dbyte<<1; //左移一位
SID = CY; //移出的位給SID
SCLK = 1;
SCLK = 0;
}
}
uchar ReceiveByte(void)
{
uchar i,temp1,temp2;
temp1 = 0;
temp2 = 0;
for(i=0;i<8;i++)
{
temp1=temp1<<1;
SCLK = 0;
SCLK = 1;
SCLK = 0;
if(SID) temp1++;
}
for(i=0;i<8;i++)
{
temp2=temp2<<1;
SCLK = 0;
SCLK = 1;
SCLK = 0;
if(SID) temp2++;
}
return ((0xf0&temp1)+(0x0f&temp2));
}
void CheckBusy( void )
{
do SendByte(0xfc); //11111,RW(1),RS(0),0
while(0x80&ReceiveByte()); //BF(.7)=1 Busy
}
void Lcd_WriteCmd(uchar Cbyte )
{
CS = 1;
CheckBusy();
SendByte(0xf8); //11111,RW(0),RS(0),0
SendByte(0xf0&Cbyte); //高四位
SendByte(0xf0&Cbyte<<4); //低四位(先執(zhí)行<<)
CS = 0;
}
void Lcd_WriteData(uchar Dbyte )
{
CS = 1;
CheckBusy();
SendByte(0xfa); //11111,RW(0),RS(1),0
SendByte(0xf0&Dbyte); //高四位
SendByte(0xf0&Dbyte<<4); //低四位(先執(zhí)行<<)
CS = 0;
}
void Lcd_Init(void)
{
PSB = 0;
delayms(50);
Lcd_WriteCmd(0x30); //選擇基本指令集
delayms(1);
Lcd_WriteCmd(0x30); //選擇8bit數(shù)據(jù)流
delayms(1);
Lcd_WriteCmd(0x0c); //開顯示(無游標(biāo)、不反白)
delayms(1);
Lcd_WriteCmd(0x01); //清除顯示,并且設(shè)定地址指針為00H
delayms(20);
}
void hanzi_Disp(uchar x,uchar y,uchar code *s)
{
Lcd_WriteCmd(addr_tab[8*x+y]); //寫地址
while(*s>0)
{
Lcd_WriteData(*s); //寫數(shù)據(jù)
s++;
}
}
void shuju(uchar x,uchar y,uint sz)
{
Lcd_WriteCmd(addr_tab[8*x+y]); //寫地址
if(sz<10)
Lcd_WriteData(0x20);
else
Lcd_WriteData((sz/10)+0x30);
Lcd_WriteData((sz%10)+0x30);
}
void shizhong(uchar x,uchar y,uint h,uint m,uint s)
{
Lcd_WriteCmd(addr_tab[8*x+y]); //寫地址
Lcd_WriteData(h/10+0x30);
Lcd_WriteData(h%10+0x30);
Lcd_WriteData(0x3a);
Lcd_WriteData(m/10+0x30);
Lcd_WriteData(m%10+0x30);
Lcd_WriteData( 0x3a);
Lcd_WriteData(s/10+0x30);
Lcd_WriteData(s%10+0x30);
}
//當(dāng)i=0時(shí)顯示上面128×32,當(dāng)i=8時(shí)顯示下面128×32
//當(dāng)i=0時(shí)顯示上面128×32,當(dāng)i=8時(shí)顯示下面128×32
void LcdFill_Vertical()
{
uchar x,y,i;
for(i=0;i<9;i=i+8)
for(y=0;y<0x20;y++)
{
for(x=0;x<8;x++)
{
Lcd_WriteCmd(0x36); //擴(kuò)充指令繪圖顯示
Lcd_WriteCmd(y+0x80); //行地址
Lcd_WriteCmd(x+0x80+i); //列地址
Lcd_WriteData(0x55); //寫數(shù)據(jù) D15-D8
Lcd_WriteData(0x55); //寫數(shù)據(jù) D7-D0
Lcd_WriteCmd(0x30);
}
}
}
//當(dāng)i=0時(shí)顯示上面128×32,當(dāng)i=8時(shí)顯示下面128×32
//當(dāng)i=0時(shí)顯示上面128×32,當(dāng)i=8時(shí)顯示下面128×32
void Lcd_Fill(uchar test)
{
uchar x,y,i;
for(i=0;i<9;i=i+8)
for(y=0;y<0x20;y++)
{
for(x=0;x<8;x++)
{
Lcd_WriteCmd(0x36); //擴(kuò)充指令繪圖顯示
Lcd_WriteCmd(y+0x80); //行地址
Lcd_WriteCmd(x+0x80+i); //列地址
Lcd_WriteData(test); //寫數(shù)據(jù) D15-D8
Lcd_WriteData(test); //寫數(shù)據(jù) D7-D0
Lcd_WriteCmd(0x30);
}
}
}
void main(void)
{
Lcd_Init();
initial();
while(1)
{
hanzi_Disp(0,0," 我");
hanzi_Disp(1,0," cd ");
hanzi_Disp(2,0," ef ");
hanzi_Disp(3,0," 01 ");
}
}
void initial()
{
TMOD = 0x01;
TH0 = 0x0EE;
TL0 = 0x00;
EA = 1;
ET0 = 1;
TR0 = 1;
month=9;
day=17;
}
void Timer0Interrupt(void) interrupt 1
{
TH0 = 0x0EE;
TL0 = 0x00;
count++;
if(count>200)
{
count=0;
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
hour++;
minute=0;
}
}
}
}
|
|