#include <reg52.h>
#include "LCD7290.h"
sbit S1=P3^0;
sbit S2=P3^1;
sbit S3=P3^2;
sbit S4=P3^3;
code unsigned char SMGcode[18]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,0xbf,0xff};
unsigned int s=0;
unsigned int s0_1=0;
unsigned int s1=0;
unsigned int m=0;
void selectHC573(unsigned char n)
{
switch(n)
{
case 5: P2=(P2 & 0x1f) | 0xa0;break;
case 6: P2=(P2 & 0x1f) | 0xc0;break;
case 7: P2=(P2 & 0x1f) | 0xe0;break;
}
}
void displySMG(unsigned char pos,unsigned char value)
{
selectHC573(6);
P0=0x01<<pos;
selectHC573(7);
P0=value;
}
void delay_dingshi(unsigned int n)
{
while(n--);
}
void delay()
{
unsigned char i;
i = 350;
while (i--);
}
void init()
{
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
ET0=1;
EA=1;
TR0=1;
}
void dinshi() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
s++;
if(s == 20)
{
s0_1++;
s=0;
if(s0_1 >= 59)
{
s1++;
s0_1 = 0;
if(s1 >= 59)
{
m++;
s1=0;
}
if(m >= 24)
m=0;
}
}
}
void RunningSMG()
{
displySMG(7,SMGcode[s0_1%10]);
delay();
displySMG(6,SMGcode[s0_1/10]);
delay();
displySMG(5,SMGcode[17]);
delay();
displySMG(4,SMGcode[s1%10]);
delay();
displySMG(3,SMGcode[s1/10]);
delay();
displySMG(2,SMGcode[17]);
delay();
displySMG(1,SMGcode[m%10]);
delay();
displySMG(0,SMGcode[m/10]);
delay();
}
void scan()
{
if(S1 == 0)
{
delay_dingshi(50);
if(S1 == 0)
{
while(S1==0);
TR0=~TR0;
}
}
if(S2 == 0)
{
delay_dingshi(50);
if(S2 == 0)
{
while(S2==0);
if(++s0_1 >= 59)
s0_1=0;
}
}
if(S3 == 0)
{
delay_dingshi(50);
if(S3 == 0)
{
while(S3==0);
if(++s1 >= 59)
s1=0;
}
}
if(S4 == 0)
{
delay_dingshi(50);
if(S4 == 0)
{
while(S4==0);
if(++m >= 24)
m=0;
}
}
}
int main()
{
init();
LCD_Init();
LCD_Disp_String(0,1,"³ÂÌÎ");
LCD_Disp_String(1,1,"2021441811");
LCD_Disp_String(3,0,"ÖÇÄÜÒÇÆ÷");
while(1)
{
scan();
RunningSMG();
}
} |