标题:
求教 制作的呼吸灯 但是没有达到预期渐亮渐灭的效果 请各位大神看看哪儿出错了 感谢
[打印本页]
作者:
18862511786
时间:
2020-8-7 11:20
标题:
求教 制作的呼吸灯 但是没有达到预期渐亮渐灭的效果 请各位大神看看哪儿出错了 感谢
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define TIME_1MS 65536-1000
long timer_ms=0;
void delay(uchar a1);
uchar a4;
void main()
{
uchar a=5,bb=0;
int aaa=0;
TMOD = 0x01; //set timer0 as mode1 (16-bit)
TL0 = TIME_1MS%256; //initial timer0 low byte
TH0 = TIME_1MS/256; //initial timer0 high byte
TR0 = 1; //timer0 start running
ET0 = 1; //enable timer0 interrupt
EA = 1;
a4=0;
while(1)
{
if(bb==0)
{
if(timer_ms==a)
{
P1=0XFF;
}
else if(timer_ms==20-a)
{
P1=0;
}
}
else
{
if(timer_ms==a)
{
P1=0;
}
else if(timer_ms==20-a)
{
P1=0xff;
}
}
if(timer_ms>=21)timer_ms=0;
aaa++;
if(aaa == 3000)
{
a++;
if(a==20)
{
bb=~bb;
a=5;
}
aaa=0;
}
}
}
void timero() interrupt 1
{
TL0 = (65536-1000)%256; //initial timer0 low byte
TH0 = (65536-1000)/256; //initial timer0 high byte
timer_ms++;
}
void delay(uchar a1)
{
char a2,a3;
for(a2=0;a2<a1;a2++)
for(a3=0;a3<250;a3++);
}
作者:
Roy-2010
时间:
2020-8-7 13:25
可以使用硬件方法。
作者:
压着我头发啦
时间:
2020-8-7 14:08
http://www.51hei.com/bbs/dpj-100638-1.html
参考下
作者:
xianfajushi
时间:
2020-8-7 14:12
可参,定时时间自己去调节,能实现,曾经做过。
https://blog.csdn.net/xianfajushi/article/details/81331101
作者:
小菜孟
时间:
2020-8-7 16:11
还是时间参数设置的不合理 ,主要是逻辑的问题
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1