找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1840|回復: 4
收起左側(cè)

幫忙看一下怎么進入不了中斷程序了啊

[復制鏈接]
ID:394056 發(fā)表于 2018-9-11 15:06 | 顯示全部樓層 |閱讀模式
#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;
   }
  }
}
回復

使用道具 舉報

ID:213173 發(fā)表于 2018-9-11 20:51 | 顯示全部樓層
沒有完整程序文件無法判斷問題所在,單從串口中斷函數(shù)看,寫得有點啰嗦。可以先簡化一下程序調(diào)試串口,成功后再增加其他功能。
回復

使用道具 舉報

ID:347721 發(fā)表于 2018-9-11 20:53 | 顯示全部樓層
定時器初始化的時候打開定時器中斷了嗎?
回復

使用道具 舉報

ID:394056 發(fā)表于 2018-9-11 22:24 | 顯示全部樓層
喬陸騰 發(fā)表于 2018-9-11 20:53
定時器初始化的時候打開定時器中斷了嗎?

定時器已經(jīng)開了啊
回復

使用道具 舉報

ID:397384 發(fā)表于 2018-9-13 11:39 | 顯示全部樓層
有可能上電的時候收到亂碼剛好和你要的數(shù)據(jù)對應,然后關(guān)中斷了
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表