/*谁去试一下我的程序看,用的是LCD12864液晶屏的,我用的是郭天祥的单片机,可是我的效果是想出时分秒自己懂的 但是现在不成功啊,我那个sbit wr=P3^4;
sbit sbit lcden=P3^5;
sbit rs=P3^3;这几个换了
*/
#include<reg51.h> // 包含51单片机寄存器定义的头文件
#include<intrins.h>
typedef unsigned int uint16;
typedef unsigned char uint8;
uint8 n,miao,fen,shi;
void fsm(uint8 add,uint8 dat);
void dispay();
sbit duan=P2^6;
sbit wei=P2^7;
sbit wr=P3^4;
sbit sbit lcden=P3^5;
sbit rs=P3^3;
void write_12864dat(uint8 dat);
void write_12864com(uint8 com);
void init();
uint8 code table[]="我我我我我我我我";
uint8 code table1[]=" 00:00:00";
void delay_50us(uint16 z) // 11.0592MHz 晶振延时50us
{
uint16 j,x;
for(j=20; j>0; j--)
for(x=z;x>0;x--) ;
}
void delayms(uint16 m) // 11.0592MHz 晶振ms延时,偏差小于1%
{
uint16 i, j;
for(i=m; i>0; i--)
for(j=114; j>0; j--);
}
void main()
{
duan=0;
wei=0;
init();
dispay();
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TMOD=0X01;
EA=1;
ET0=1;
TR0=1;
while(1);
}
void dispay()
{
uint8 j;
write_12864com(0x88);
delay_50us(1);
for(j=0;j<16;j++)
{
write_12864dat(table[j]);
delay_50us(2);
}
write_12864com(0x98);
delay_50us(2);
for(j=0;j<12;j++)
{
write_12864dat(table1[j]);
delay_50us(1);
}
}
void t0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
n++;
if(n==20){n=0;miao++;
if(miao==60){miao=0;fen++;
if(fen==60){fen=0;shi++;
if(shi==24){shi=0;} fsm(4,shi);}fsm(7,fen);}fsm(10,miao);}
}
void fsm(uint8 add,uint8 dat)
{
uint8 shiwei,gewei;
shiwei=dat/10;
gewei=dat%10;
write_12864com(0x98+add);
write_12864dat(0x30+shiwei);
write_12864dat(0x30+gewei);
}
void write_12864com(uint8 com)
{
rs=0;
wr=0;
lcden=0;
delay_50us(1);
lcden=1;
P0=com;
delay_50us(10);
lcden=0;
delay_50us(2);
}
void write_12864dat(uint8 dat)
{
rs=1;
wr=0;
lcden=0;
delay_50us(1);
lcden=1;
P0=dat;
delay_50us(10);
lcden=0;
delay_50us(2);
}
void init()
{
delayms(40);
write_12864com(0x30);
delay_50us(4);
write_12864com(0x30);
delay_50us(4);
write_12864com(0x0c);
delay_50us(4);
write_12864com(0x01);
delayms(20);
write_12864com(0x06);
delay_50us(1);
}