#include <at89x52.h>
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 output=P2^0;
char disp_seg7[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x89,0xc9,0xb6,};
/*-------------------------------*/
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_4ms(int k)//248hz
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<43;j++)
;
}
main()
{
P0=0xff;
P1=0xff;
cck_run_7seg();
while(1)
{
if(sw1==0)
{
delay_1ms(20);while(sw1!=1);delay_1ms(20);
add++;
if(add==11) add=0;
}
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)
{
P0=disp_seg7[3];
x=3;
output=0;delay_4ms(x);
output=1;delay_4ms(10-x);
}
else if(add==4)
{
P0=disp_seg7[4];
x=4;
output=0;delay_4ms(x);
output=1;delay_4ms(10-x);
}
else if(add==5)
{
P0=disp_seg7[5];
x=5;
output=0;delay_4ms(x);
output=1;delay_4ms(10-x);
}
else if(add==6)
{
P0=disp_seg7[6];
x=6;
output=0;delay_4ms(x);
output=1;delay_4ms(10-x);
}
else if(add==7)
{
P0=disp_seg7[7];
x=7;
output=0;delay_4ms(x);
output=1;delay_4ms(10-x);
}
else if(add==8)
{
P0=disp_seg7[8];
x=8;
output=0;delay_4ms(x);
output=1;delay_4ms(10-x);
}
else if(add==9)
{
P0=disp_seg7[9];
x=9;
output=0;delay_4ms(x);
output=1;delay_4ms(10-x);
}
else if(add==10)
{
P0=disp_seg7[10];
x=10;
output=0;delay_4ms(x);
output=1;delay_4ms(10-x);
}
}
}
沒有留言:
張貼留言