想写一个遥控小车的程序,void serial() interrupt 4 跳不进去
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar buf;
unsigned char jd;
unsigned char count;
sbit pwm =P1^7 ;
sbit motor_control_1 = P2^7;// 动力电机控制
sbit motor_control_2 = P2^6;//
void Time0_Init() //定时器初始化
{
TMOD = 0x01; //定时器0工作在方式1
IE = 0x82;
TH0 = 0xfe;
TL0 = 0x33; //11.0592MZ晶振,0.5ms
TR0=1; //定时器开始
}
void main(void)
{
jd=3;
count=0;
Time0_Init();
SCON=0x50; //设定串口工作方式
PCON=0x00; //波特率不倍增
TMOD=0x20; //定时器1工作于8位自动重载模式, 用于产生波特率
EA=1;
ES = 1; //允许串口中断
TL1=0xfd;
TH1=0xfd; //波特率9600
TR1=1;
while(1);
}
/*********************************************************
串行中断服务函数
*********************************************************/
void serial() interrupt 4
{
ES = 0; //关闭串行中断
RI = 0; //清除串行接受标志位
buf = SBUF; //从串口缓冲区取得数据
if(buf==0X31)//前进
{
motor_control_1 = 0;
motor_control_2 = 1;
}
if(buf==0x30)//刹车
{
motor_control_1 = 0;
motor_control_2 = 0;
}
if(buf==0x33)//后退
{
motor_control_1 = 1;
motor_control_2 = 0;
}
if(buf==0x32)//左转
{
jd=5;
}
if(buf==0x34)//右转
{
jd=1;
}
ES = 1; //允许串口中断
}
void Time0_Int() interrupt 1 //中断程序
{
TH0 = 0xfe; //重新赋值
TL0 = 0x33;
if(count< jd) //判断0.5ms次数是否小于角度标识
pwm=1; //确实小于,PWM输出高电平
else
pwm=0; //大于则输出低电平
count=(count+1); //0.5ms次数加1
count=count%40; //次数始终保持为40 即保持周期为20ms
}