心形流水灯变换
程序员文章站
2022-07-12 23:15:56
...
#八个LED 心形流水灯
今天学了定时器,老师布置了和心形流水灯有关的任务,所以就来试一下。
心形流水灯,其实就是将流水灯摆成心形,再加上花样发光就行。话不多说。代码如下
#include<reg51.h>
#define u8 unsigned char ;
#define u16 unsigned int ;
u16 ms50;
u16 lednum;
u16 code temp_led[]={0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,0xFF,
0xFF,0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF,
0xFF,0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0xFF
0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF,0XFF
0xFF,0x7F,0x3F,0x1F,0x0F,0x07,0x03,0x01,0x00,0XFF
0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xFF,0XFF
0xFF,0xE7,0xDB,0xBD,0x7E,0x7E,0xBD,0xDB,0xE7,0xFF,
0xFF,0xE7,0xDB,0xBD,0x7E,0x7E,0xBD,0xDB,0xE7,0xFF,
0xFF,0xAA,0xFF,0xAA,0xFF,0xFF,0x55,0xFF,0x55,0xFF,
0xFF,0xAA,0xFF,0xAA,0xFF,0xFF,0x55,0xFF,0x55,0xFF,
0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0X00,0XFF
};
void init_time()
{
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
ET0=1;
EA=1;
TR0=1;
}
void inter_timer2() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
ms50++;
if(ms50>9)
{
ms50=0;
P1=temp_led[lednum];
lednum++;
if(lednum>104) lednum=0;
}
}
main()
{
init_time();
while(1)
{
;}
}
仿真图图片如下:
上一篇: springboot整合MongoDB
下一篇: SpringMVC基于注解开发