#include <at89x52.h>
char seg7[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
char left_move[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
char left_add[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};
char righ_add[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
char seg2020[]={0xb0,0xc0,0xb0,0xc0};
char seg0704[]={0xc0,0xf8,0xc0,0x92};
char buf[]={0xc0,0xc0,0xc0,0xc0};
char scanline=0x01;
sbit led0=P3^0;
sbit led1=P3^1;
sbit led2=P3^2;
sbit led3=P3^3;
sbit btn1=P3^4;
sbit btn2=P3^5;
int Mode=0;
int i,j,x=0;
void delay_1ms(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<114;j++)
;
}
void init()
{
int i;
for(i=0;i<2;i++)
{
P1=0X00;delay_1ms(1000);
P2=0X00;delay_1ms(1000);
led0=0;led1=0;led2=0;led3=0;P0=0x00;delay_1ms(1000);
P1=0XFF;delay_1ms(1000);
P2=0XFF;delay_1ms(1000);
led0=1;led1=1;led2=1;led3=1;P0=0xFF;delay_1ms(1000);
}
P2=seg7[0];
}
main()
{
init();
while(1)
{
while(btn1==0) //開關按下
{
delay_1ms(10);
if(btn1==1) //開關放開
{
delay_1ms(10);
Mode=Mode+1;
if(Mode>9)
Mode=0;
}
}
while(btn2==0)
{
delay_1ms(10);
if(btn2==1)
{
delay_1ms(10);
Mode=Mode-1;
if(Mode < 0)
Mode=9;
}
}
switch(Mode)
{
case 0:
P2=seg7[0];P1=0xff;P0=0xff;
break;
case 1:
P2=seg7[1];delay_1ms(20);
P1=0x00;delay_1ms(500);
P1=0xff;delay_1ms(500);
break;
case 2:
P2=seg7[2];
for(i=0;i<8;i++)
{
P1=~left_move[i];delay_1ms(500);
}
break;
case 3:
P2=seg7[3];
for(i=7;i>=0;i--)
{
P1=~left_move[i];delay_1ms(500);
}
break;
case 4:
P2=seg7[4];
for(i=0;i<8;i++)
{
P1=~left_add[i];delay_1ms(500);
}
break;
case 5:
P2=seg7[5];
for(i=0;i<8;i++)
{
P1=~righ_add[i];delay_1ms(500);
}
break;
case 6:
P2=seg7[6];
P3=~0x01 & 0x0f ;P0=buf[0];delay_1ms(4);
P3=~0x02 & 0x0f ;P0=buf[1];delay_1ms(4);
P3=~0x04 & 0x0f ;P0=buf[2];delay_1ms(4);
P3=~0x08 & 0x0f ;P0=buf[3];delay_1ms(4);
break;
case 7:
P2=seg7[7];P1=0xff;P0=0xff;
break;
case 8:
P2=seg7[8];P1=0xff;P0=0xff;
break;
case 9:
P2=seg7[9];P1=0xff;P0=0xff;
break;
}
}
}
沒有留言:
張貼留言