#include<reg52.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
uint8 led[]={0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7};
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ENLED1=P1^4;
sbit ENLED2=P1^3;
void display_love();
void int_init();
void timer1_init();
main()
{
P0=0x00;
ENLED1=0;
ENLED2=0;
//选中定时器1方式1
timer1_init();
int_init();
while(1);
}
void timer1_init()
{
TMOD |= 0x10;
TMOD &= 0xdf;
TR1 = 1;
//0xF8CD 是2ms,定时器1方式1
TH1=0xF8;
TL1=0xCD;
}
void int_init()
{
ET1 = 1;
EA = 1;
}
void display_love()
{
static uint8 n=0;
switch(n)
{
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=led[n];
if(7==n++)n=0;
}
void interrupt_led() interrupt 3
{
TH1=0xF8;
TL1=0xCD;
//display();
display_love();
}
用点阵显示一个爱心
最新推荐文章于 2023-03-26 16:59:41 发布