標(biāo)題:
單片機(jī)定時(shí)查詢(xún)流水燈程序求教
[打印本頁(yè)]
作者:
葬閱
時(shí)間:
2018-12-17 19:08
標(biāo)題:
單片機(jī)定時(shí)查詢(xún)流水燈程序求教
我想實(shí)現(xiàn)定時(shí)查詢(xún)流水燈的程序,每隔1秒led燈依次點(diǎn)亮,(下一個(gè)點(diǎn)亮上一個(gè)滅),這個(gè)程序哪里錯(cuò)了,請(qǐng)大佬指教。謝謝
#include <reg51.h>
#define LED P1
#define long_time0(void)
#define count 50000
#define TH_M1 (65636-count)/256
#define TL_M1 (65636-count)%256
//
unit n=0;
//
main()
{ int i;
TMOD &= 0xf1;
TMOD |= 0x01;
p1=0x01;
while(1)
{ for (i=0;i<20;i++) {
TH0=TH_M1;
TL0=TL_M1;
TR0=1;
while(TF0==0);
TF0=0;
}
static uint i;
i++;
if(long_time==i)
{
p1=~(0x01<<n);
if(++n=8)n=0;
i=0;
}
}
}
作者:
wzj1999
時(shí)間:
2018-12-17 20:45
在論壇上有相似的,可以去相互印證
作者:
wulin
時(shí)間:
2018-12-18 06:47
#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
#define LED P1
#define count 50000
#define TH_M1 (65636-count)/256
#define TL_M1 (65636-count)%256
void main()
{
uchar i=0,j=0x01;
TMOD &= 0xF0;
TMOD |= 0x01;
TH0 = TH_M1;
TL0 = TL_M1;
TF0 = 0;
TR0 = 1;
LED=~j;
while(1)
{
if(TF0==1)
{
TF0=0;
i++;
if(i==20)
{
i=0;
j<<=1;
if(j==0)
j=0x01;
LED=~j;
}
}
}
}
作者:
葬閱
時(shí)間:
2018-12-19 00:03
wulin 發(fā)表于 2018-12-18 06:47
#include
#define uint unsigned int
#define uchar unsigned char
謝謝啊,我也弄出來(lái)啦
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1