//mplab v1.7 mcc18 串口接收中断示例
#include #include #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(); // } } }
上一篇:PIC18**K80配置位详解
下一篇:pic 18f45k80单片机看门狗程序
推荐阅读最新更新时间:2024-11-01 13:54
设计资源 培训 开发板 精华推荐
- 使用 Analog Devices 的 LTC1261CS 的参考设计
- 使用 Microchip Technology 的 TC1185 的参考设计
- 基于 LT3782A 的同步升压转换器(8.5A 时 VOUT = 24V,VIN = 8.5V 至 18V)
- S32K146EVB: S32K146 评估板
- CW32-48F大学计划板
- SY89853U,用于 GB 以太网交换机的时钟多路复用器的评估板
- 典型应用 - MCP1632 高速低侧 PWM 控制器的电压模式控制
- LTM4643EV 2.375V 至 5V 输入、四路 1V、1.2V、1.5V、1.8V 输出降压稳压器的典型应用
- 使用连接到 ADuC7024 精密模拟微控制器的 ADXL345 数字加速度计检测低 g 加速度
- ESP8266 WiFI杀手