Hi all,
I've made this small program to learn how the EUSART RX interrupt works....and it works BUT
Yes, the code below works but I'm getting confused when I think about having unknown data length to be received. I'm not even sure that this code is really correct.
In this example, I'm waiting for 5 charaters to be received. As long as 5 characters have not arrived, nothing will be printed out.
And here is where I'm confused.
Since the HSERIN command is in the ISR, each time I send a character from the Serial Communiactor, I expect the ISR the receive "at least" one character so the LED should toggle. But no, it doesn't. It seems to wait until all 5 characters have arrived and then, only then, the LED toggles.
I don't get it....
How shall I handle this please? What is the correct approach?
Code:' ====== FUSES ==================================================================================== ' PIC 16F690 Fuses (MPASM) @ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_INTRC_OSC_NOCLKOUT &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF @ ERRORLEVEL -306 ' ====== REGISTERS ================================================================================= OSCCON = %01110000 'Internal RC set to 8Mhz - Register not to be used with XTal OPTION_REG = %10000000 'PORT A&B Pull-Ups (look WPUA & WPUB) ANSEL = %00000000 'Select analog inputs Channels 0 to 7 ANSELH = %00000000 'Select analog inputs Channels 8 to 11 INTCON = %11000000 'INTERRUPT Control PIE1 = %00100000 'Peripheral Interrupts ' ====== UART SETTINGS ============================================================================ RCSTA = %10010000 ' Enable serial port & continuous receive TXSTA = %00100000 ' Enable transmit, BRGH = 0 SPBRG = 12 ' 9600 Baud @ 8MHz, 0.16% ' ====== DEFINES ================================================================================== DEFINE OSC 8 DEFINE NO_CLRWDT 1 ' Don't waste cycles clearing WDT DEFINE HSER_CLOERR 1 ' Automatic clear overrun error ' ====== VARIABLES ================================================================================ LED VAR PORTB.6 SData VAR BYTE(5) Print VAR BIT '======= INITIALIZE =============================================================================== PORTB.5 = 1 ' set to avoid sending serial data garbage Print = 0 ' send out serial data only if some is received '======= PROGRAM ================================================================================== ON INTERRUPT GOTO ISR MAIN: IF PRINT THEN Hserout [STR SData\5,13,10] Print = 0 ENDIF GOTO MAIN END ' ====== INTERRUPT SERVICE ROUTINE ================================================================ Disable ISR: HSerin [STR SData\5] PRINT = 1 TOGGLE LED RESUME ENABLE





Bookmarks