#include <reg52.h>
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
uchar image[8] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
uchar T0RH, T0RL;
uint rate;
void LEDScan();
void resetImage();
void configTmr0(uint ms1, uchar ms2);
void main() {
EA = 1;
ADDR3 = 0;
ENLED = 0;
configTmr0(50, 2);
while (1) ;
}
void configTmr0(uint ms1, uchar ms2) {
ulong tmp;
rate = ms1 / ms2;
tmp = 11059200 / 12; //定时器计数频率
tmp = (tmp * ms2) / 1000; //计算所需的计数值
tmp = 65536 - tmp; //计算定时器重载值
tmp = tmp + 12; //补偿中断响应延时造成的误差
T0RH = tmp >> 8; //定时器重载值拆分为高低字节
T0RL = tmp;
TMOD &= 0xF0;
TMOD |= 0x01;
TH0 = T0RH;
TL0 = T0RL;
ET0 = 1;
51单片机 漩涡流水点阵
最新推荐文章于 2021-10-25 20:25:16 发布
本文介绍如何使用51单片机编写程序,通过配置定时器TMR0,实现漩涡流水点阵效果。代码中定义了相关管脚,设置中断服务函数,动态改变点阵显示,形成了连续的视觉效果。
摘要由CSDN通过智能技术生成