问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
#include <REGX52.H>
sbit ENA=P1^0;
sbit ENB=P1^5;
sbit IN1=P0^1;
sbit IN2=P0^2;
sbit IN3=P0^3;
sbit IN4=P0^4;
unsigned int Duty_cycle_A,Duty_cycle_B£»
void advance() //Ç°½ø
{
IN1=1;
IN2=0;
IN3=0;
IN4=1;
}
void back() //ºóÍË
{
IN1=0;
IN2=1;
IN3=1;
IN4=0;
}
void right() //ÓÒת
{
IN1=0;
IN2=0;
IN3=0;
IN4=1;
}
void left() //×óת
{
IN1=1;
IN2=0;
IN3=0;
IN4=0;
}
void Timer0Init(void)
{
TMOD = 0x01; //???????
TL0 = (65536-10)/256; //???????
TH0 = (65536-10)%256; //???????
TR0 = 1; //???0????
ET0=1;
EA=1;
}
void Timer0_Routine() interrupt 1
{
unsigned int T0Count;
TR0=0;
TL0 = (65536-10)/256; //???????
TH0 = (65536-10)%256; //???????
TR0=1;
Duty_cycle_A=13;
Duty_cycle_B=100;
T0Count++;
if(T0Count<Duty_cycle_A)
{
ENA=1;
}
else
{
ENA=0;
}
if(T0Count<Duty_cycle_B)
{
ENB=1;
}
else
{
ENB=0;
}
if(T0Count>=100)
{
T0Count=0;
}
}
void main()
{
Timer0Init();
EA=1;
while(1)
{
advance();
}
}