StC 89c52单片机 串口中断进不去

傲娇小斑鸠 2017-10-13 11:15:12
StC 89c52单片机 串口中断进不去 用的蓝牙发送串口下面是程序

#include<reg52.h>
#include <intrins.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int

/***左右轮的 PWM***/
sbit EN1=P0^6;
sbit EN2=P0^7;
sbit EN3=P1^6;
sbit EN4=P1^7;
sbit IN11=P0^0;
sbit IN12=P0^1;
sbit IN21=P0^2;
sbit IN22=P0^3;
sbit IN41=P1^2;
sbit IN42=P1^3;
sbit IN31=P1^0;
sbit IN32=P1^1;

unsigned long int counter;
uchar PWM_1,PWM_2;
#define High_Speed 19
#define ML_Speed 5
#define Middle_Speed 12
#define Stop 0
bit sgn1=0,sgn2=0;
uchar speed1=0;
uchar speed2=0;
uchar blue_receivestore=0;

void initial()
{
ES=1;
EA=1;
EX0=1;
IT0=1;
ET0=1;
TR0=1;
TH0=0XF8;
TL0=0X10;
TMOD=0x21;
TH1=0Xfd;
TL1=0Xfd;
TR1=1;
SM0=0;
SM1=1;
REN=1;
// ES=1;
// EA=1;
EN1=0;
EN2=0;
EN3=0;
EN4=0;
counter=0;
}

void motor(uchar index, bit sgn,uchar speed)
{
if(speed>=0&&speed<=19)
{
if(index==1)
{
if(sgn==1)
{
IN11=0;
IN12=1;
IN41=0;
IN42=1;
PWM_1=speed;
}
else
{
IN11=1;
IN12=0;
IN41=1;
IN42=0;
PWM_1=speed;
}
}
if(index==2)
{
if(sgn==1)
{
IN21=0;
IN22=1;
IN31=0;
IN32=1;
PWM_2=speed;
}
else
{
IN21=1;
IN22=0;
IN31=1;
IN32=0;
PWM_2=speed;
}
}
}
}

void number_analyse(uint tmp)
{
uint operation;
//if(tmp==0xff){sgn1=0;sgn2=0;speed1=High_Speed;speed2=High_Speed;}
operation=tmp&0x30;
if(operation==0x00){sgn1=0;sgn2=0;} //前行
if(operation==0x20){sgn1=0;sgn2=0;} //左行
if(operation==0x10){sgn1=1;sgn2=1;} //右行
if(operation==0x30){sgn1=1;sgn2=1;} //后退
operation=tmp&0x0c;
if(operation==0x0c){speed1=High_Speed;} //设定左轮为高速
if(operation==0x08){speed1=Middle_Speed;} //设定左轮为中速
if(operation==0x04){speed1=ML_Speed;} //设定左轮为低速
if(operation==0x00){speed1=Stop;} //设定左轮停下来
operation=tmp&0x03;
if(operation==0x03){speed2=High_Speed;}
if(operation==0x02){speed2=Middle_Speed;}
if(operation==0x01){speed2=ML_Speed;}
if(operation==0x00){speed2=Stop;}
motor(1, sgn1,speed1);
motor(2, sgn2,speed2);
}
void main()
{
uint extern_accept_now=0;
uint extern_accept=0;
initial();
while(1)
{
extern_accept_now=blue_receivestore;
extern_accept=extern_accept_now;
number_analyse(extern_accept);
}
}

void timer1() interrupt 1
{
counter++;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
//TH0=(65536-50000)/256;
//TL0=(65536-50000)%256;

if(counter%20<PWM_1){EN1=1;EN4=1;}
if(counter%20>PWM_1){EN1=0;EN4=0;}
if(counter%20<PWM_2){EN2=1;EN3=1;}
if(counter%20>PWM_2){EN2=0;EN3=0;}
if(counter==60000) counter=0;
}

void blue_receive() interrupt 4
{
if(RI==1)
{
blue_receivestore=SBUF;
RI=0;
}
}

这是我用kiel仿真往串口发送0x4A数据的截图,串口中断的断点进不去
...全文
500 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dannes_li 2017-10-14
  • 打赏
  • 举报
回复
void blue_receive() interrupt 4 { if(RI==1) { blue_receivestore=SBUF; RI=0; } }改成 void blue_receive() interrupt 4 { if(RI==1) { RI=0; blue_receivestore=SBUF; } }试试
大米粥哥哥 2017-10-13
  • 打赏
  • 举报
回复
注释其它代码 只测试串口中断程序 不正常的话 是你的设置有问题 正常的话 可能是中断优先级的问题(O_O)? 或者配置有错 检测串口相关配置
傲娇小斑鸠 2017-10-13
  • 打赏
  • 举报
回复
运行了 没有反应
worldy 2017-10-13
  • 打赏
  • 举报
回复
代码下载到单片机运行测试

27,375

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧