|
发表于 2015-11-10 12:04:01
|
显示全部楼层
#include <REGX52.H>
typedef unsigned char uint8;
typedef unsigned int uint16;
uint8 a[6];
code uint8 number123[6] = {0x06,0x5b,0x4f,
0x00,0x00,0x00};
uint16 counter = 0;
sbit P22 = P2^0;
sbit P21 = P2^1;
sbit P20 = P2^2;
sbit P24 = P2^4;
void refresh();
void int_init();
void timer1_init();
MAIN()
{
P24 = 1;
a[0] = 0; a[1] = 1; a[2] = 2; a[3] = 3; a[4] = 4; a[5] = 5;
timer1_init();
int_init();
while(1);
}
void refresh()
{
static uint8 j=0;
switch(j)
{
case 0: P20 = 0; P21 = 0; P22 = 0; j++;P1 = number123[a[0]];break;
case 1: P20 = 0; P21 = 0; P22 = 1; j++;P1 = number123[a[1]];break;
case 2: P20 = 0; P21 = 1; P22 = 0; j++;P1 = number123[a[2]];break;
case 3: P20 = 0; P21 = 1; P22 = 1; j++;P1 = number123[a[3]];break;
case 4: P20 = 1; P21 = 0; P22 = 0; j++;P1 = number123[a[4]];break;
case 5: P20 = 1; P21 = 0; P22 = 1; j=0;P1 = number123[a[5]];break;
default:break;
}
}
void timer1_init()
{
TMOD |= 0x10;
TMOD &= 0xdf;
TH1 = 0xFC;
TL1 = 0x67;
TR1 = 1;
}
void int_init()
{
ET1 = 1;
EA = 1;
}
void interrupt_timer1() interrupt 3
{
static uint8 k=0;
TH1 = 0xFC;
TL1 = 0x67;
counter++;
if(1000==counter)
{
counter = 0;
switch(k)
{
case 0: a[0] = 0; a[1] = 1; a[2] = 2; a[3] = 3; a[4] = 4; a[5] = 5;break;
case 1: a[0] = 5; a[1] = 0; a[2] = 1; a[3] = 2; a[4] = 3; a[5] = 4;break;
case 2: a[0] = 4; a[1] = 5; a[2] = 0; a[3] = 1; a[4] = 2; a[5] = 3;break;
case 3: a[0] = 3; a[1] = 4; a[2] = 5; a[3] = 0; a[4] = 1; a[5] = 2;break;
case 4: a[0] = 2; a[1] = 3; a[2] = 4; a[3] = 5; a[4] = 0; a[5] = 1;break;
case 5: a[0] = 1; a[1] = 2; a[2] = 3; a[3] = 4; a[4] = 5; a[5] = 0;break;
default:break;
}
k++;
if(6 == k) k=0;
}
refresh();
} |
评分
-
查看全部评分
|