PIC24EP512
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 = {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 = U1RXREG;
ReceivedState = 3;
break;
case 3:
UartReceivedData = U1RXREG;
ReceivedState = 4;
break;
case 4:
UartReceivedData = U1RXREG;
ReceivedState = 5;
break;
case 5:
UartReceivedData = 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 == 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;
}
楼主 还需要看一下io的初始化程序 开始中断使能了吗 中断向量没有指错吧 还需要开启总中断 一次中断都不进入吗 有一个文件里边屏蔽了中断向量需要解除屏蔽
页:
[1]