//mplab v1.7 mcc18 串口接收中断示例
#include<p18f14k50.h>
#include <p18cxxx.h>
#define u8 unsigned char
#define u16 unsigned int
#pragma config CPUDIV = NOCLKDIV
#pragma config USBDIV = OFF
#pragma config FOSC = HS
#pragma config PLLEN = ON
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRTEN = OFF
#pragma config BOREN = OFF
#pragma config BORV = 30
#pragma config WDTEN = OFF
#pragma config WDTPS = 32768
#pragma config MCLRE = OFF
#pragma config HFOFST = OFF
#pragma config STVREN = ON
#pragma config LVP = OFF
#pragma config XINST = OFF
#pragma config BBSIZ = OFF
#pragma config CP0 = OFF
#pragma config CP1 = OFF
#pragma config CPB = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
#pragma config WRTB = OFF
#pragma config WRTC = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
#pragma config EBTRB = OFF
#define Firmware_led LATBbits.LATB4
#define InitFirmwareLed() LATB |= 1<<4; TRISB &= ~(1<<4)
#define Fir_Led_on() Firmware_led = 0
#define Fir_Led_Off() Firmware_led = 1
#define InitSwitch() ANSEL = 0;\
ANSELH = 0;\
LATC |= 0xF9;\
TRISC |= 0xF9;
#define SW_MENU PORTCbits.RC0
#define SW_VGA2 PORTCbits.RC4
#define DelayMs(x) \
{ \
unsigned long _dcnt; \
unsigned long _ms; \
_ms = x; \
while (_ms) \
{ \
_dcnt=((unsigned long)(0.001/(1.0/2000000)/6));
\
while(_dcnt--);
\
_ms--; \
} \
}
void UART_Init(void)
{
//Fir_Led_on();
TRISBbits.TRISB5 = 1;
ANSELHbits.ANS11 = 0;
TXSTAbits.TX9 = 0;
TXSTAbits.TXEN = 1;
TXSTAbits.BRGH = 1;
RCSTAbits.RX9 = 0;
RCSTAbits.CREN =1;
TXSTAbits.SYNC = 0;
RCSTAbits.SPEN = 1;
BAUDCONbits.BRG16 = 0;
SPBRG = 25;
RCONbits.IPEN = 1;
PIE1bits.RCIE = 1;
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
Fir_Led_on();
}
//void InterruptHandlerLow(void);
//#pragma code InterruptVectorLow = 0x18
//void InterruptVectorLow(void)
//{
// _asm
// goto InterruptHandlerLow
// _endasm
//}
//#pragma code
//
//#pragma interruptlow InterruptHandlerLow
//void InterruptHandlerLow(void)
//{
// unsigned char data;
// if(PIR1bits.RCIF)
// {
// PIR1bits.RCIF = 0;
// data = RCREG;
// Fir_Led_on();
// }
//}
void InterruptHandlerHigh(void);
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh(void)
{
_asm
goto InterruptHandlerHigh
_endasm
}
#pragma code
#pragma interrupt InterruptHandlerHigh
void InterruptHandlerHigh(void)
{
unsigned char data;
if(PIR1bits.RCIF)
{
PIR1bits.RCIF = 0;
data = RCREG;
Fir_Led_on();
}
}
void main(void)
{
unsigned char data;
InitSwitch();
InitFirmwareLed();
UART_Init();
while(1)
{
if(!SW_MENU)
{
Fir_Led_Off();
}
else if(!SW_VGA2)
{
Fir_Led_on();
}
// else if(PIR1bits.RCIF)
// {
// //PIR1bits.RCIF = 0;
// data = RCREG;
// Fir_Led_on();
// }
}
}