|
#include<REG52.H>
#include<absacc.h>
#define COMMAND XBYTE[0X1F00]
#define PA XBYTE[0X1F01]
#define PB XBYTE[0x1f02]
#define uchar unsigned char
#define uint unsigned int
sbit cs=P2^5;
sbit om=P2^4;
sbit state=P2^6;
sbit int0=P3^2;
sbit int1=P3^3;
uchar k1=1,k2=1;
uchar a,shi,ge,shi1,ge1,num1,num2,num3;
uchar t;
uchar t1;
uchar dx_hong,dx_huang,dx_lv,nb_hong,nb_huang,nb_lv;
uchar run_state=1;
uchar ledflag1=1,ledflag2=3;//r y g y
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delayms(uint xms);
void display1(uchar shi,uchar ge,uchar shi1,uchar ge1);
void djs(uchar xs,uchar xs1);
void init(void);
void keyscan(void);
void main()
{init();
cs=0;
om=1;
COMMAND=0X0F;
PB=0XFF;
IT0=1;
IT1=1;
EX0=EX1=1;
while(1)
{
keyscan();
if(run_state){
TR0=1;
if(ledflag1==1){
t=20;/*dx_hong=0; dx_huang=1; dx_lv=1;*/
PB&=~(0X07);
PB|=0X01;
}
else if((ledflag1==2)||(ledflag1==4)){
t=3;/*dx_hong=1; dx_huang=0; dx_lv=1;*/
PB&=~(0X07);
PB|=0X02;
}
else if(ledflag1==3){
t=17;/*dx_hong=1; dx_huang=1; dx_lv=0;*/
PB&=~(0X07);
PB|=0X04;
}
if(ledflag2==1){
t1=20;/*nb_hong=0;nb_huang=1;nb_lv=1;*/
PB&=~(0X07<<3);
PB|=0X01<<3;
}
else if((ledflag2==2)||(ledflag2==4)){
t1=3;/*nb_hong=1;nb_huang=0;nb_lv=1;*/
PB&=~(0X07<<3);
PB|=0X02<<3;
}
else if(ledflag2==3){
t1=17;/*nb_hong=1;nb_huang=1;nb_lv=0;*/
PB&=~(0X07<<3);
PB|=0X04<<3;
}
djs(t,t1);
}else
{
TR0=0;
PA=0X00;
}
}
}
void keyscan(void)//p2^6
{
static key_state=1;
if(key_state&&(state==0))
{
delayms(10);
if(state==0)
{
key_state=0;
run_state=!run_state;
}
}else if(state)
{
key_state=1;
}
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display1(uchar shi,uchar ge,uchar shi1,uchar ge1)
{
P2=0xfe;
PA=0x00;
PA=table[shi];
delayms(5);
P2=0xfd;
PA=0x00;
PA=table[ge];
delayms(5);
P2=0xfb;
PA=0x00;
PA=table[shi1];
delayms(5);
P2=0xf7;
PA=0x00;
PA=table[ge1];
delayms(5);
}
void djs(uchar xs,uchar xs1)
{
shi=(xs-num2)/10;
ge=(xs-num2)%10;
shi1=(xs1-num3)/10;
ge1=(xs1-num3)%10;
display1(shi,ge,shi1,ge1);
if((xs-(num2-1))==0)
{
num2=0;
if(ledflag1<4)ledflag1++;
else ledflag1=1;
}
if((xs1-(num3-1))==0)
{
num3=0;
if(ledflag2<4)ledflag2++;
else ledflag2=1;
}
// }
}
void init(void)
{
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void T0_time()interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num1++;
if(num1==20)
{
num1=0;
num2++;
num3++;
}
}
void INT0_HANDER(void) interrupt 0
{
delayms(10);
if(int0==0)
{
if(run_state==0)
{
if(k1<3)k1++;
else k1=1;
if(k1==1){PB&=~(0X07);PB|=0X01;}
else if(k1==2){PB&=~(0X07);PB|=0X02;}
else if(k1==3){PB&=~(0X07);PB|=0X04;}
}
}
}
void INT1_HANDER(void) interrupt 2
{
delayms(10);
if(int1==0)
{
if(run_state==0)
{
if(k2<3)k2++;
else k2=1;
if(k2==1){PB&=~(0X07<<3);PB|=(0X01<<3);}
else if(k2==2){PB&=~(0X07<<3);PB|=(0X02<<3);}
else if(k2==3){PB&=~(0X07<<3);PB|=(0X04<<3);}
}
}
}
[img]file:///C:/Users/wzy/AppData/Roaming/Tencent/Users/624399639/QQ/WinTemp/RichOle/A)VUO4QSM[@$Y$O)[ZNYB_4.png[/img]
|
-
2.png
(96.5 KB, 下载次数: 49)
-
1.png
(36.29 KB, 下载次数: 36)
评分
-
查看全部评分
|