#include <reg51.h>
sbit led0 = P2^2;
sbit sw1 = P3^2;
char code data_7seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
//shor_line 1111 1110(a) FE
//shor_line 1111 1101(b) FD
//shor_line 1111 1011(c) FB
//shor_line 1111 0111(d) F7
//shor_line 1110 1111(e) EF
//shor_line 1101 1111(f) DF
char code shor_line[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xFF};
char disp[]={0,0,0,0};
char act[]={0xfe,0xfd,0xfb,0xf7};
int value;
int flag=1;
int cck=0;
int hi,lo;
int di;
void delay(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<120;j++);
}
void t0_isr(void) interrupt 1
{
TH0=value/256;
TL0=value%256;
P0=disp[di];
P1=act[di];
di++;
if(di==4)di=0;
}
void init()
{
value=65536-2000;
TH0=hi=value/256;
TL0=lo=value%256;
TMOD=0x01;
IE=0x82;
TR0=1;
}
void show1_data()
{
disp[0]=data_7seg[0];
disp[1]=data_7seg[2];
disp[2]=data_7seg[0];
disp[3]=data_7seg[2];
}
void test1_7seg()
{
int i;
for(i=0;i<3;i++)
{
TR0=1;
show1_data();delay(200);
TR0=0;P1=0xff;P2=0xff;delay(200);
}
}
void show2_data()
{
disp[0]=data_7seg[5];
disp[1]=data_7seg[1];
disp[2]=data_7seg[6];
disp[3]=data_7seg[0];
}
void test2_7seg()
{
int i;
for(i=0;i<2;i++)
{
TR0=1;
show2_data();delay(200);
TR0=0;P1=0xff;P2=0xff;delay(200);
}
}
void led()
{
int i;
for(i=0;i<1;i++)
{
led0=0;delay(2000);
led0=1;
}
}
void clockwise()
{
disp[1] = shor_line[6];disp[0] = shor_line[0];delay(500);//6 0
disp[1] = shor_line[0];disp[0] = shor_line[6];delay(500);//0 6
disp[1] = shor_line[5];disp[0] = shor_line[6];delay(500);//5 6
disp[1] = shor_line[4];disp[0] = shor_line[6];delay(500);//4 6
disp[1] = shor_line[3];disp[0] = shor_line[6];delay(500);//3 6
disp[1] = shor_line[6];disp[0] = shor_line[3];delay(500);//6 3
disp[1] = shor_line[6];disp[0] = shor_line[2];delay(500);//6 2
disp[1] = shor_line[6];disp[0] = shor_line[1];delay(500);//6 1
}
void counterclockwise()
{
disp[1] = shor_line[6];disp[0] = shor_line[1];delay(500);//6 1
disp[1] = shor_line[6];disp[0] = shor_line[2];delay(500);//6 2
disp[1] = shor_line[6];disp[0] = shor_line[3];delay(500);//6 3
disp[1] = shor_line[3];disp[0] = shor_line[6];delay(500);//3 6
disp[1] = shor_line[4];disp[0] = shor_line[6];delay(500);//4 6
disp[1] = shor_line[5];disp[0] = shor_line[6];delay(500);//5 6
disp[1] = shor_line[0];disp[0] = shor_line[6];delay(500);//0 6
disp[1] = shor_line[6];disp[0] = shor_line[0];delay(500);//6 0
}
main()
{
init();
test1_7seg();
test2_7seg();
led();
TR0=1;
while(1)
{
if(flag==1)
{
clockwise();
}
if(flag==0)
{
counterclockwise();
}
}
}
沒有留言:
張貼留言