#include "reg51.h"
sbit led=P2^0;
sbit PB1=P3^2;
sbit PB2=P3^3;
int i=20;
int j=0;
char count=0;
char bcd[2]={0,0};
char code P0table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
char code P1table[]={0xfe,0xfd}; //0xfe才會從個位數開始數
void T0_int(void) interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
P0=P0table[ bcd[j] ];
P1=P1table[j];
j++;
if(j==2)
j=0;
}
void T1_int(void) interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
i--;
if(i==0)
{
i=20;
count++;
if(count==10)
{
count=0;
led=~led;
}
bcd[1]=count/10;
bcd[0]=count%10;
}
}
void int0_sw() interrupt 0
{
TR1=!TR1;//是關閉計時中斷1讓他不會顯示一直計數數字,而掃描一樣讓他持續的scan
while(!PB1);
}
void int1_rst(void ) interrupt 2
{
while(!PB2);
count=0;
bcd[1]=0;
bcd[0]=0;
}
void main()
{
IE=0x8f;
TMOD=0x11;
PT1=1;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR0=1;
TR1=1;
while(1);
}
沒有留言:
張貼留言