標(biāo)題:
單片機(jī)定時(shí)器方式二仿真(led不亮,請(qǐng)問哪出錯(cuò)了)
[打印本頁]
作者:
dzl111
時(shí)間:
2021-4-18 12:22
標(biāo)題:
單片機(jī)定時(shí)器方式二仿真(led不亮,請(qǐng)問哪出錯(cuò)了)
#include <reg51.h>
typedef unsigned int u16;
sbit led0 = P1^0;
sbit led1 = P1^1;
u16 num;
void main(void)
{
TMOD = 0x02;
TH0 = 156;
TL0 = 156;
ET0 = 1;
TR0 = 1;
EA = 1;
while (1)
{
if(num == 10000)
{
num = 0;
led0 = ~led0;
}
}
}
void T0_time(void) interrupt 2
{
num++;
}
作者:
tyrl800
時(shí)間:
2021-4-18 19:56
把void T0_time(void) interrupt 2改成void T0_time(void) interrupt 1
作者:
dzl111
時(shí)間:
2021-4-18 20:16
tyrl800 發(fā)表于 2021-4-18 19:56
把void T0_time(void) interrupt 2改成void T0_time(void) interrupt 1
#include <reg51.h>
typedef unsigned int u16;
sbit led0 = P1^0;
sbit led1 = P1^1;
u16 num;
void main(void)
{
// Write your code here
TMOD = 0x52;
TH0 = 0x9C;
TL0 = 0x9C;
TH1 = (65536-100)/256;
TL1 = (65536-100)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
ET1 = 1;
TR1 = 1;
while (1);
}
void T0_time(void) interrupt 1
{
num++;
if(num==10000)
{
num = 0;
led0 = ~led0;
}
}
void T1_time(void) interrupt 3
{
TH1 = (65536-100)/256;
TL1 = (65536-100)%256;
if(TF1==1)
{
TF1 = 0;
led1 = ~led1;
}
}
那請(qǐng)問這個(gè)T1為計(jì)數(shù)器時(shí),給它記100個(gè)脈沖,led取反,為什么仿真時(shí)候不亮呢
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1