char reset_P0table[]={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
*/
int add=-1;
char x;
sbit sw1=P1^0;
sbit sw2=P1^1;
sbit output=P2^0;
bit change_flag=0;
bit sw1_flag;
bit sw2_flag;
bit breath_flag;
unsigned int breath_count;
unsigned int rpt_count;
char disp_seg7[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x89,0xc9,0xb6,0xFF};
/*-------------------------------*/
void delay_1ms(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<114;j++) ;
}
/*-------------------------------*/
void cck_run_7seg()//???a ab abc...
{
int i;
for(i=0;i<8;i++) { P0=reset_P0table[i]; delay_1ms(500); }
}
/*-------------------------------*/
void delay_2ms(int k)//?500hz
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<20;j++)
;
}
void delay_1000ms(int k)//?1khz
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<6;j++)
;
}
void delay_4ms(int k)//245~248hz?250hz
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<40;j++)
;
}
main()
{
cck_run_7seg();
while(1)
{
if(sw1==0)
{
sw1_flag=1;
delay_1ms(20);while(sw1!=1);delay_1ms(20);
add++;
if(add>10) add=0;
}
/*--------------------------------------------------*/
if(sw1_flag)
{
if(add==0){P0=disp_seg7[0]; x=0; output=0;delay_4ms(x); output=1;delay_4ms(10-x);}
else if(add==1){ x=1; P0=disp_seg7[1]; output=0;delay_4ms(x);output=1;delay_4ms(10-x);}
else if(add==2){ x=2; P0=disp_seg7[2]; output=0;delay_4ms(x);output=1;delay_4ms(10-x);}
else if(add==3){ x=3; P0=disp_seg7[3]; output=0;delay_4ms(x); output=1;delay_4ms(10-x);}
else if(add==4){ x=4; P0=disp_seg7[4]; output=0;delay_4ms(x); output=1;delay_4ms(10-x); }
else if(add==5){ x=5; P0=disp_seg7[5]; output=0;delay_4ms(x); output=1;delay_4ms(10-x); }
else if(add==6){ x=6; P0=disp_seg7[6]; output=0;delay_4ms(x); output=1;delay_4ms(10-x); }
else if(add==7){ x=7; P0=disp_seg7[7]; output=0;delay_4ms(x); output=1;delay_4ms(10-x);}
else if(add==8){ x=8; P0=disp_seg7[8]; output=0;delay_4ms(x); output=1;delay_4ms(10-x);}
else if(add==9){ x=9; P0=disp_seg7[9]; output=0;delay_4ms(x); output=1;delay_4ms(10-x);}
else if(add==10){x=10;P0=disp_seg7[10];output=0;delay_4ms(x); output=1;delay_4ms(10-x);}
}
沒有留言:
張貼留言