#include <reg52.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long uint32;
code uint8 graph[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xC3,0xE7,0xE7,0xE7,0xE7,0xC3,0xFF,
0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7,
0xFF,0x99,0x99,0x99,0x99,0x81,0xC3,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
sbit ENLED = P1^4;
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
uint8 i= 0,counter = 0;
void timer1_init()
{
TMOD |= 0x10;
TMOD &= 0xdf;
TH1 = 0xFC;
TL1 = 0x67;
TR1 = 1;
}
void int_init()
{
ET1 = 1;
EA = 1;
}
void refresh_led()
{
static uint8 j = 0;
switch(j)
{
case 0: ADDR0 = 0;ADDR1 = 0;ADDR2 = 0;break;
case 1: ADDR0 = 1;ADDR1 = 0;ADDR2 = 0;break;
case 2: ADDR0 = 0;ADDR1 = 1;ADDR2 = 0;break;
case 3: ADDR0 = 1;ADDR1 = 1;ADDR2 = 0;break;
case 4: ADDR0 = 0;ADDR1 = 0;ADDR2 = 1;break;
case 5: ADDR0 = 1;ADDR1 = 0;ADDR2 = 1;break;
case 6: ADDR0 = 0;ADDR1 = 1;ADDR2 = 1;break;
case 7: ADDR0 = 1;ADDR1 = 1;ADDR2 = 1;break;
default: break;
}
P0 = graph[i + j];
if(7 == j++) j = 0;
}
main()
{
ENLED = 0; ADDR3 = 0;
timer1_init();
int_init();
while(1);
}
void interrupt_timer1() interrupt 3
{
TH1 = 0xFC;
TL1 = 0x67;
counter++;
if(counter == 200)
{
counter = 0;
i++;
if(i>=32){i=0;}
}
refresh_led();
} |