Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LCD serial interrupt initialization and ISR routine
;Enable unmasked peripheral interrupts
INTCON = %11000000
;Declear interrupt handler
ON INTERRUPT goto Serial_Interrupt
;Enable interrupt on USART (Serial Receive)
PIE1.5 = 1
...
;-----[ Variables ]--------------------------------------------------------
;High Baud Rate Select bit
BRGH VAR TXSTA.2
;Receive interrupt flag (1 = full, 0 = empty)
RCIF VAR PIR1.5
;-----[ EEPROM ]-----------------------------------------------------------
;Reference labels for associated memory locations
;EEPROM locations 0 and 1 store the default baud rate value (9600 baud)
_BRGH DATA @0, 0
_SPBRG DATA @1, 32
...
;-----[ Initialization ]---------------------------------------------------
Init:
...
;Read BRGH Baud Rate Select Bit and SPBRG Register from memory. Set
;baud rate based on these values. A better understanding of these
;settings can be gathered from the selected microcontroller data sheet.
;GOSUB READ_BAUD_RATE
read _BRGH, BRGH
read _SPBRG, SPBRG
...
;We read BRGH and SPBRG values from EEPROM. BRGH will be 0 for low bit
;rates and 1 for high bit rates. The below routine is used to display
;the saved baud rate on initial power on of the LCD controller. This is
;to aid in pairing the correct baud rate from the controller/PC to the
;LCD controller. A Clear Screen command should be sent to the LCD
;before sending further data unless you want the baud rate to stay on
;the display.
select case brgh
case 0
size = 4
ARRAYWRITE baud, ["9600"]
case 1
select case SPBRG
case 64
size = 5
ARRAYWRITE baud, ["19200"]
case 32
size = 5
ARRAYWRITE baud, ["38400"]
case 21
size = 5
ARRAYWRITE baud, ["57600"]
case else
END SELECT
end select
...
;--------------------------------------------------------------------------
;Serial Interrupt routine
;--------------------------------------------------------------------------
;Make sure we do interrupt our interrupt
disable
Serial_Interrupt:
;Check for serial input
if (RCIF = 1) then
;Keep track of serial buffer
index = index + 1
;If buffer over-flows reset buffer
if (index = buffer_size) then index = 0
;Get serial input and store in array
hserin [Rx_Array[index]]
endif
resume
enable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment