#include <STC12C5A60S2.h>
#include <intrins.h>
typedef unsigned char u8;
typedef unsigned int u16;
//stc15w408as共陽數(shù)碼管代碼
u16 mun, key=0,key_;//變量聲明
u8 code tab[16][10]=
{{1,1,0,0,0,0,0,0},
{1,1,1,1,1,0,0,1},
{1,0,1,0,0,1,0,0},
{1,0,1,1,0,0,0,0},
{1,0,0,1,1,0,0,1},
{1,0,0,1,0,0,1,0},
{1,0,0,0,0,0,1,0},
{1,1,1,1,1,0,0,0},
{1,0,0,0,0,0,0,0},
{1,0,0,1,0,0,0,0},
{1,0,0,0,1,0,0,0},//a
{1,0,0,0,0,0,1,1},//b
{1,1,0,0,0,1,1,0},//c
{1,0,1,0,0,0,0,1},//d
{1,0,0,0,0,1,1,0},//e
{1,0,0,0,1,1,1,0}};//f
sbit A_=P1^0;//斷碼
sbit B_=P1^1;
sbit C_=P1^2;
sbit D_=P1^3;
sbit E_=P1^4;
sbit F_=P1^5;
sbit G_=P1^6;
sbit H_=P3^7;
sbit GeWei=P2^6;
sbit ShiWei=P2^7;
void Delay10ms();
unsigned char Desplay(unsigned char mun,com);
void Delay1ms() ;
void Time();
void main()
{Time();//定時器初始化
while(1)
{
if(key==60)
{
key=0;
}
Desplay( key%10,1);
Desplay((key/10)%10,2);
}
}
void Time()
{
AUXR &= 0x7F; //定時器時鐘12T模式
TMOD &= 0xF0; //設(shè)置定時器模式
TMOD |= 0x01; //設(shè)置定時器模式
TL0 = 0x00; //設(shè)置定時初值
TH0 = 0xB8; //設(shè)置定時初值
TF0 = 0; //清除TF0標(biāo)志
TR0 = 1; //定時器0開始計時
ET0=1;
EA=1;
}
unsigned char Desplay(unsigned char mun,com)
{u8 i;
for(i=0;i<8;i++)
{
switch(i)
{
case 0:A_=tab[mun][7];break;
case 1:B_=tab[mun][6];break;
case 2:C_=tab[mun][5];break;
case 3:D_=tab[mun][4];break;
case 4:E_=tab[mun][3];break;
case 5:F_=tab[mun][2];break;
case 6:G_=tab[mun][1];break;
case 7:H_=tab[mun][0];break;
}
}
switch(com)
{
case 1:GeWei=1;ShiWei=0;break;
case 2:GeWei=0;ShiWei=1;break;
}
Delay1ms();
A_=1;B_=1;C_=1;D_=1;E_=1;F_=1;G_=1;H_=1;
GeWei=0;
ShiWei=0;
}
void titn_time_ () interrupt 1
{
TL0 = 0x00; //設(shè)置定時初值
TH0 = 0xB8; //設(shè)置定時初值
++mun;
if(mun==50)
{ mun=0;
key++;}
}
void Delay1ms() //@11.0592MHz
{
unsigned char i, j;
_nop_();
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
}
|