//顯示 00.0~99.9
//2011 12 12 E:\DPJ_C\00.00\00.0.c
#include <reg51.h>
#define uchar unsigned char
//sbit P20=P2^0;
sbit P21=P2^1;
sbit P22=P2^2;
sbit P23=P2^3;
sbit P07=P0^7;
sbit KS=P1^0; //開始
sbit KR=P1^1; //復位
uchar time,xs,ge,shi,bai,qian;
uchar code tab[ ]= {
0x3F,/*0*/
0x06,/*1*/
0x5B,/*2*/
0x4F,/*3*/
0x66,/*4*/
0x6D,/*5*/
0x7D,/*6*/
0x07,/*7*/
0x7F,/*8*/
0x6F,/*9*/
};
void delay_ms(unsigned int ms) //1ms延時
{
uchar a;
while(ms--)
for(a=123;a>0;a--);
}
void display();
void T0intinit( ) //定時器T0初始化
{
TMOD=0x01;
TH0=(65536-10000)/256; //10ms定時
TL0=(65536-10000)%256;
EA=1;
ET0=1;
}
void main()
{
T0intinit( );
while(1)
{
display( );
while(!KS) //開始鍵
{
display( );
if(KS)
TR0=1;
}
while(!KR) //清零鍵
{
display( );
if(KR)
TR0=0;
qian=0;
bai=0;
shi=0;
ge=0;
}
if(bai==10)
{
bai=0;
qian++;
}
if(qian==10)
{
qian=0;
TR0=0;
}
}
}
void display( )
{
P23=0;
P0=tab[shi];
delay_ms(1);
P23=1;
P22=0;
P0=tab[bai];
P07=1;
delay_ms(1);
P22=1;
P21=0;
P0=tab[qian];
delay_ms(1);
P21=1;
//P20=0;
P0=tab[qian];
delay_ms(1);
//P20=1;
}
void T0int( ) interrupt 1 //定時器T0中斷 方式1
{
TH0=(65536-10000)/256; //重裝10ms定時常數
TL0=(65536-10000)%256;
ge++;
if(ge==10)
{
ge=0;
shi++;
}
if(shi==10)
{
shi=0;
bai++;
}
}