//-----------------------------------------------------------------------------------------------
//来个猛一点的,显示欢迎界面,之后进入当前日期,时钟显示
//我前前后后花了10来天才调成功,没得问,汗死了,网上又没资料供参考
//51+PIC通杀:时钟
#define ww
#ifdef ww
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]=" hello!jasper ";
uchar code table1[]=" xm.dabiao ";
uchar code aa[]=" 2018-01-04 MON ";
uchar code bb[]=" 09:59:56 ";
sbit lcden=P3^4; //液晶使能位
sbit lcdrs=P3^5; //液晶RS,数据/命令切换选择位
sbit dula=P2^6; //数码管关断
sbit wela=P2^7;
sbit FM=P2^3;
#endif
#ifdef PIC
#include <pic.h>
__CONFIG(0X3B31);
#define uchar unsigned char
#define uint unsigned int
const uchar table[]=" hello! jasper ";
const uchar table1[]=" xm.dabiao ";
const uchar aa[]=" 2012-01-04 MON ";
const uchar bb[]=" 09:59:56 ";
#define lcden RA3
#define lcdrs RA5
#define lcdrw RA4
#define P0 PORTD
#define FM RE0
#endif
uchar num,count;
char miao=56,fen=59,shi=9;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar date)
{
lcdrs=1;
P0=date;
delay(5);
lcdrs=1;
#ifdef PIC
lcdrw=0;
#endif
lcden=1;
delay(5);
lcden=0;
}
void lcd_enable(void)
{
lcdrs = 0;
#ifdef PIC
lcdrw = 0;
#endif
lcden = 0;
delay(5);
lcden = 1;
}
void delayzd(uint zz)
{
uint xz,yz;
for(xz=zz;xz>0;xz--)
for(yz=110;yz>0;yz--);
}
void write_comzd(uchar comz)
{
lcdrs=0;
P0=comz;
delayzd(5);
lcden=1;
delayzd(5);
lcden=0;
}
void write_datazd(uchar dataz)
{
lcdrs=1;
P0=dataz;
delayzd(5);
lcdrs=1;
#ifdef PIC
lcdrw=0;
#endif
lcden=1;
delayzd(5);
lcden=0;
}
void write_sfm(uchar adda,char datez)
{
char shi,ge;
shi=datez/10;
ge=datez%10;
write_comzd(0x80+0x40+adda);
write_datazd(0x30+shi);
write_datazd(0x30+ge);
}
void lcd_enablezd(void)
{
lcdrs = 0;
#ifdef PIC
lcdrw = 0;
#endif
lcden = 0;
delayzd(5);
lcden = 1;
}
void init(void)
{
#ifdef ww
dula=0;
wela=0;
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
// write_com(0x80);
write_com(0x80+0x10);
#endif
#ifdef PIC
TRISA=0x00;PORTA=0XF0;
TRISD=0x00;PORTD=0XFF;
ADCON1=0X07;
lcd_enable();
write_com(0x38);
lcd_enable();
write_com(0x0e);
lcd_enable();
write_com(0x06);
lcd_enable();
write_com(0x01);
lcd_enable();
// write_com(0x80);
write_com(0x80+0x10);
#endif
}
void hello(void)
{
for(num=0;num<16;num++)
{
write_data(table[num]);
delay(10);
}
write_com(0x80+0x51);
for(num=0;num<16;num++)
{
write_data(table1[num]);
delay(10);
}
for(num=0;num<16;num++)
{
write_com(0x18);
delay(160);
}
delay(1800);
}
void pingxian(void)
{
uchar num_x;
delay(500);
write_com(0x01);
write_com(0x80);
for(num_x=0;num_x<16;num_x++)
{
write_data(aa[num_x]);
delay(20);
}
write_com(0x80+0x40);
delay(5);
for(num_x=0;num_x<16;num_x++)
{
write_data(bb[num_x]);
delay(20);
}
delay(300);
}
void zd(void)
{
#ifdef ww
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
#endif
#ifdef PIC
INTCON=0xc0;
PIE1=0x01;
T1CON=0x01;
TMR1L=(65536-50000)%256;
TMR1H=(65536-50000)/256;
#endif
}
void main()
{
init();
hello();
pingxian();
zd();
while(1)
{ }
}
void timego(void)
{
if(count==19)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
write_sfm(4,shi);
}
write_sfm(7,fen);
}
write_sfm(10,miao);
}
}
#ifdef ww
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
timego();
}
#endif
#ifdef PIC
void interrupt time0(void)
{
TMR1IF=0;
TMR1L=(65536-50000)%256;
TMR1H=(65536-50000)/256;
count++;
//if(count==19)P0=0x02;
timego();
}
#endif
|