這是一個(gè)用按鍵調(diào)節(jié)七段顯示屏顯示數(shù)字的值的程序,其中一個(gè)按鍵按下加1,另外一個(gè)按下減1 程序:
#include
#include
sbit P2_2=P2^2 ;
sbit P2_3=P2^3 ;
sbit P3_3=P3^3;
sbit P3_4=P3^4;
unsigned char num=18,shi,fen;
unsigned char table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
void delay(unsigned char dly)
{
unsigned char i,j;
for(i=255;i>0;i--)
for(j=dly;j>0;j--)
;
}
void initial()
{
TMOD=0x01;
EA=1;
TR0=1;
ET0=1;
}
void timer0() interrupt 1
{
TH0=(65535-10000)/256;
TL0=(65535-10000)% 256;
shi=num/10;
fen=num;
P2_2=1;
P2_3=0;
P0=table[shi];
delay(2);
P2_2=0;
P2_3=1;
P0=table[fen];
delay(2);
}
void main()
{
initial();
while(1)
{
if(P3_3==0)
{
num++;
while(P3_3==0);
}
if(P3_4==0)
{
num--;
while(P3_4==0);
}
}
}
評論