#include <at89x52.h>
char reset_P1table[]={0xFE, 0XFC, 0XF8, 0XF0, 0XE0, 0XC0, 0X00, 0xc0};
/* a ab abc abcd abcde abcdef
1111 1110 a
1111 1100 ab
1111 1000 abc
1111 0000 abcd
1110 0000 abcde
1100 0000 abcdef
0000 0000 abcdefg
1100 0000 abcdef
*/
char disp_seg7[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x89,0xc9,0xb6,0xFF};
int k=0;
sbit sw1=P2^0;
sbit sw2=P2^1;
void delay_1ms(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<114;j++) ;
}
void cck_run_7seg()
{
int i;
for(i=0;i<8;i++)
{
P1=reset_P1table[i];delay_1ms(1000);
}
}
void main()
{
cck_run_7seg();
while(1)
{
if(sw1==0)
{
delay_1ms(20);
while(sw1 !=1);
delay_1ms(20);
k++;
if(k>9)k=0;
}
if(sw2==0)
{
delay_1ms(20);
while(sw2 !=1);
delay_1ms(20);
k--;
if(k<0)k=9;
}
if(k==0){P1=disp_seg7[k];}
else if(k==1){P1=disp_seg7[k];}
else if(k==2){P1=disp_seg7[k];}
else if(k==3){P1=disp_seg7[k];}
else if(k==4){P1=disp_seg7[k];}
else if(k==5){P1=disp_seg7[k];}
else if(k==6){P1=disp_seg7[k];}
else if(k==7){P1=disp_seg7[k];}
else if(k==8){P1=disp_seg7[k];}
else if(k==9){P1=disp_seg7[k];}
}
}
沒有留言:
張貼留言