求助用AI8051U写的第八课定时器周期性任务|已解决
各位大佬我按照视频教程自己编写了第一种方式的周期性任务,结果烧录到擎天柱核心板上P20,P21,P22这三个灯一个都不闪,编译也没问题。求找下问题,下面是代码,或者大神指导下这种我用什么方法能发现问题出现了哪里,我对了半天的视频代码都没找到问题。#include "ai8051u.h"
#include "stc32_stc8_usb.h"
#define u8 unsigned char
#define u16 unsigned int
u8 stste1=0;
u8 stste2=0;
u8 stste3=0;
u16 count_300=0;
u16 count_600=0;
u16 count_900=0;
//定时器中断函数
void Timer0_Init(void) //1毫秒@24.000MHz
{
TM0PS = 0x00; //设置定时器时钟预分频 ( 注意:并非所有系列都有此寄存器,详情请查看数据手册 )
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x30; //设置定时初始值
TH0 = 0xF8; //设置定时初始值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1; //使能定时器0中断
}
void main()
{
int count = 1;
WTST = 0;//设置程序指令延时参数,赋值为0可将CPU执行指令的速度设置为最快
EAXFR =1; //扩展寄存器(XFR)访问使能
CKCON = 0; //提高访问XRAM速度
P0M1 = 0x00; P0M0 = 0x00;
P1M1 = 0x00; P1M0 = 0x00;
P2M1 = 0x00; P2M0 = 0x00;
P3M1 = 0x00; P3M0 = 0x00;
P4M1 = 0x00; P4M0 = 0x00;
P5M1 = 0x00; P5M0 = 0x00;
P6M1 = 0x00; P6M0 = 0x00;
P7M1 = 0x00; P7M0 = 0x00;
usb_init(); //USB CDC 接口配置
EA = 1;
while (1)
{
if (bUsbOutReady)
{
usb_OUT_done();
}
if(count_300 >= 300)
{
count_300=0;
stste1= !stste1;
P20= stste1;
}
if(count_600 >= 600)
{
count_600=0;
stste2=!stste2 ;
P21= stste2;
}
if(count_900 >= 900)
{
count_900=0;
stste3=!stste3 ;
P22= stste3;
}
}
}
void Timer0_Isr(void) interrupt 1
{
count_300++;
count_600++;
count_900++;
}
补充下不是不闪,是一个灯都不亮。我换了其他的程序就能正常闪烁,请大神看下问题到底在哪里,感谢! 没调用定时器0初始化函数Timer0_Init(void) huashanhui20 发表于 2025-5-9 07:43
没调用定时器0初始化函数Timer0_Init(void)
感谢大神,真是定时器初始化函数没写。
页:
[1]