打印
[复制链接]
818|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zhangnan123|  楼主 | 2022-1-12 15:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
PIC24EP512GUB814的串口程序中,接收中断一直进不去怎么回事,哪位大神能帮我看看程序吗?
/******************************************************************************/
/* Files to Include                                                           */
/******************************************************************************/

/* Device header file */
#if defined(__XC16__)
    #include <xc.h>
#elif defined(__C30__)
    #if defined(__PIC24E__)
            #include <p24Exxxx.h>
    #elif defined (__PIC24F__)||defined (__PIC24FK__)
        #include <p24Fxxxx.h>
    #elif defined(__PIC24H__)
        #include <p24Hxxxx.h>
    #endif
#endif

#include <stdint.h>        /* Includes uint16_t definition                    */
#include <stdbool.h>       /* Includes true/false definition                  */

#include "system.h"        /* System funct/params, like osc/peripheral config */
#include "user.h"          /* User funct/params, such as InitApp              */
#include "libpic30.h"      /* C30函数库                                       */
#include "common.h"
/******************************************************************************/
/* Global Variable Declaration                                                */
/******************************************************************************/
#define ModPulseCtl PORTDbits.RD1
/* i.e. uint16_t <variable_name>; */
uint8_t ReceivedState = 0;
uint8_t ReceivedChar = 0;
uint8_t UartReceivedData[4] = {0,0,0,0} ;
uint16_t Int_Mask = 0;          /* 中断标志 */
/******************************************************************************/
/* Main Program                                                               */
/******************************************************************************/
void __attribute__ ( (interrupt, no_auto_psv) ) _U1RXInterrupt( void )
{
    IFS0bits.U1RXIF = 0;
    switch  ( ReceivedState )
    {        
        case 0:
                    ReceivedChar = U1RXREG;
                    if( ReceivedChar == 0x55 ) ReceivedState = 1;  
                    else ReceivedState = 0;
                    break;
        case 1:
                    ReceivedChar = U1RXREG;
                    if( ReceivedChar == 0xAA ) ReceivedState = 2;  
                    else ReceivedState = 0;
                    break;
        case 2:     
                    UartReceivedData[0] = U1RXREG;  
                    ReceivedState = 3;
                    break;
        case 3:     
                    UartReceivedData[1] = U1RXREG;  
                    ReceivedState = 4;
                    break;
        case 4:     
                    UartReceivedData[2] = U1RXREG;  
                    ReceivedState = 5;
                    break;
        case 5:     
                    UartReceivedData[3] = U1RXREG;  
                    ReceivedState = 6;
                    break;
        case 6:
                    ReceivedChar = U1RXREG;
                    if( ReceivedChar == 0x5A ) ReceivedState = 7;  
                    else ReceivedState = 0;
                    break;
        case 7:
                    ReceivedChar = U1RXREG;
                    if( ReceivedChar == 0xA5 )
                    {
                        ReceivedState = 0;
                        Int_Mask = 1;
                    }
                    else ReceivedState = 0;
                    break;                           
    }  
}

/*此段关于串口的程序在网络传输时不需要*/
void __attribute__ ( (interrupt, no_auto_psv) ) _U1TXInterrupt( void )
{
    IFS0bits.U1TXIF = 0;
}

void __attribute__((interrupt, auto_psv)) _DMA0Interrupt(void)
{
_DMA0IF = 0; /* Clear DMA interrupt flag to prepare for next block */
}
int16_t main(void)
{

    /* Configure the oscillator for the device */
    ConfigureOscillator();

    /* Initialize IO ports and peripherals */
    Port_Inint();
    InitApp();
    Interrupt_Init();
    /* TODO <INSERT USER APPLICATION CODE HERE> */

    while(1)
    {
    if( UartReceivedData[1] == 0x01 )
    {  ModPulseCtl = 1;
        U1TXREG  = 0x23; }
    else
            ModPulseCtl = 0;

    }
}


void InitApp(void)
{

Uart_Init();

}

void Uart_Init(void)
        {         
        U1MODEbits.STSEL = 0;           // 1-Stop bit
        U1MODEbits.PDSEL = 0;           // No Parity, 8-Data bits
        U1MODEbits.ABAUD = 0;           // Auto-Baud disabled
        U1MODEbits.BRGH = 0;            // Low-Speed mode
        U1MODEbits.UEN = 0;
        U1BRG = 20;                    // Baud Rate setting for 115200      

        U1STAbits.URXISEL0 = 0;  //Bits6,7 Int. on character recieved
        U1STAbits.URXISEL1 = 0;  //Bits6,7 Int. on character recieved

        U1STAbits.UTXISEL0 = 0;        
        U1STAbits.UTXISEL1 = 0;        

        RPOR5bits.RP84R = 1;            //TXs
        RPINR18bits.U1RXR = 83;          //RX

        U1MODEbits.UARTEN = 1;  // And turn the peripheral on
        U1STAbits.UTXEN = 1;
        }


使用特权

评论回复
沙发
tpgf| | 2022-2-5 16:08 | 只看该作者
楼主 还需要看一下io的初始化程序

使用特权

评论回复
板凳
heimaojingzhang| | 2022-2-5 16:18 | 只看该作者
开始中断使能了吗

使用特权

评论回复
地板
keaibukelian| | 2022-2-5 16:25 | 只看该作者
中断向量没有指错吧

使用特权

评论回复
5
labasi| | 2022-2-5 16:32 | 只看该作者
还需要开启总中断

使用特权

评论回复
6
paotangsan| | 2022-2-5 16:38 | 只看该作者
一次中断都不进入吗

使用特权

评论回复
7
renzheshengui| | 2022-2-5 16:46 | 只看该作者
有一个文件里边屏蔽了中断向量  需要解除屏蔽

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

1

帖子

0

粉丝