標(biāo)題:
幫忙看一下怎么進(jìn)入不了中斷程序了啊
[打印本頁]
作者:
代碼蝦1
時間:
2018-9-11 15:06
標(biāo)題:
幫忙看一下怎么進(jìn)入不了中斷程序了啊
#include "stc12c5a60s2.h"
#include "init.h"
#include "uart.h"
#include "delay.h"
#include "ad.h"
#include "flash.h"
#include "iic.h"
//串口數(shù)據(jù)的格式
#define HEAD 0XF1 //幀頭
#define VERSION 0X15 //發(fā)送版本
#define YUAN 0XB1 //源
#define FH_VERSION 0XB1 //接收版本
#define FH_YUAN 0XBF //接收版本
#define ZI 0XD1 // 控制字
#define LEN1 0X28 //24 =4+20+1
extern uchar i;
uchar uart1_flag=0;
//數(shù)組定義
uchar xdata fs_buf[46];
uchar xdata rbuf[]={
0x7E,0x80, 0x00, 0x01,
0x00, 0x00, 0x80, 0xAA,
0x00, 0x01, 0x001, 0x00,
0xDE, 0x62, 0x7E};
void receive_deal();
void uart_js();
void uart_js();
sbit jdq1=P0^0;
sbit jdq2=P0^1;
void main()
{
Time_init(); //定時器初始化
PCA_init(); //pca端口初始化
InitUart();
jdq1=jdq2=0;
EA=1;
ES=1;
uart1_flag=0;
while(1)
{
mDelay(100000);
jdq1=~jdq1;
}
}
void uart_js() interrupt 4 //RI==1時執(zhí)行串口中斷
{
static unsigned char count;
uchar xdata receive1_xorg=0;
if(RI==1)
{
RI=0;
rbuf[count]=SBUF; //保存數(shù)據(jù)
if(uart1_flag!=0)
{
count=0;
return;
}
count++;
if((count==1)&&(rbuf[0]!=0x7E))//0 0xf1
{
count=0;
}
else if((count==2)&&(rbuf[1]!=0x80)) //1 0xb1
{
count=0;
}
else if((count==3)&&(rbuf[2]!=0x00)) //1 0xbf
{
count=0;
}
else if((count==4)&&(rbuf[3]!=0x01)) //rbuf[3]
{
count=0;
}
else if((count==5)&&(rbuf[4]!=0x00)) //rbuf[4]
{
count=0;
}
else if(count==6&&rbuf[5]==(rbuf[0]^rbuf[1]^rbuf[2]^rbuf[3]^rbuf[4])) //count=6 實際接收6個字節(jié) 0-5 rbuf[5]
{
count=0 ;
uart1_flag=rbuf[3];
ES=0;
}
else if(count==7&&(rbuf[6]==(rbuf[0]^rbuf[1]^rbuf[2]^rbuf[3]^rbuf[4]^rbuf[5]))) //count=7 實際接收7個字節(jié) 0-6
{
count=0 ;
uart1_flag=rbuf[3];
ES=0;
}
else if(count==8&&(rbuf[7]==(rbuf[0]^rbuf[1]^rbuf[2]^rbuf[3]^rbuf[4]^rbuf[5]^rbuf[6])))
{
count=0 ;
uart1_flag=1;
uart1_flag=rbuf[3];
ES=0;
}
else if(count>8)
{
count=0;
}
}
}
作者:
wulin
時間:
2018-9-11 20:51
沒有完整程序文件無法判斷問題所在,單從串口中斷函數(shù)看,寫得有點啰嗦。可以先簡化一下程序調(diào)試串口,成功后再增加其他功能。
作者:
喬陸騰
時間:
2018-9-11 20:53
定時器初始化的時候打開定時器中斷了嗎?
作者:
代碼蝦1
時間:
2018-9-11 22:24
喬陸騰 發(fā)表于 2018-9-11 20:53
定時器初始化的時候打開定時器中斷了嗎?
定時器已經(jīng)開了啊
作者:
hzwenli
時間:
2018-9-13 11:39
有可能上電的時候收到亂碼剛好和你要的數(shù)據(jù)對應(yīng),然后關(guān)中斷了
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1