jakeselectronics
Member
I'm working on a project for a battery charge station for my other hobby (flying RC helis)
I want to be able to monitor the temperature of the power supplys and also run a count up timer for a very rough guide to fuel usage of a generator that will power the charge station at the flying field).
I am deep in coding and have the timer and temp (single sensor for now) displayed on the LCD.
It is running, however very inefficiently.
I am using Timer 1 with a 32.768 crytal to generate a 1 second interrupt for the timer, and also Timer 2 to generate an interrupt at about 15hz to refresh the display.
What I want to know is, what should the interrupt be used for and how should i best update the display.
At the moment i have 64 bytes of RAM to represent each character on my 16x4 LCD (LCD_DISP_R1_C1, LCD_DISP_R1_C2 and so on). The Timer 2 interrupt simply loads the RAM contents into the LCD during the interrupt using indirect addressing and if i want to write something to the display i just write it to the RAM address during normal program flow and the interrupt does the rest.
but is this the best way to do it?
Here is what i am doing in the interrupt with timer 2.
I want to be able to monitor the temperature of the power supplys and also run a count up timer for a very rough guide to fuel usage of a generator that will power the charge station at the flying field).
I am deep in coding and have the timer and temp (single sensor for now) displayed on the LCD.
It is running, however very inefficiently.
I am using Timer 1 with a 32.768 crytal to generate a 1 second interrupt for the timer, and also Timer 2 to generate an interrupt at about 15hz to refresh the display.
What I want to know is, what should the interrupt be used for and how should i best update the display.
At the moment i have 64 bytes of RAM to represent each character on my 16x4 LCD (LCD_DISP_R1_C1, LCD_DISP_R1_C2 and so on). The Timer 2 interrupt simply loads the RAM contents into the LCD during the interrupt using indirect addressing and if i want to write something to the display i just write it to the RAM address during normal program flow and the interrupt does the rest.
but is this the best way to do it?
Here is what i am doing in the interrupt with timer 2.
Code:
TIMER2_ISR
; Refresh all (visible) LCD display address locations
MOVLW LCD_DISP_R1_C1 ; Initialise pointer to RAM address
MOVWF FSR ; (File Select Register)
; Print first 32 address locations (LCD display address' 0x00 to 0x1F, lines 1 & 3)
BSF LCD_RS ; Place LCD in character entry mode
CALL PRINT_32_CHAR ;
; Move cursor to address 0x40
BCF LCD_RS ; Place LCD in command entry mode
MOVLW B'11000000' ; Set display address at 0x40 (Line 2, Column 1)
CALL LCD_WRITE ; Send data to LCD
; Print second 32 address locations (LCD display address' 0x40 to 0x5F, lines 2 & 4)
BSF LCD_RS ; Place LCD in character entry mode
CALL PRINT_32_CHAR ;
; Display & Cursor home
BCF LCD_RS ; Place LCD in command entry mode
MOVLW B'00000010' ; LCD command for Display & Cursor home
CALL LCD_WRITE ; Send data to LCD
BCF PIR1, TMR2IF ; Clear TMR2 interrupt flag
GOTO ISR_END
PRINT_32_CHAR
CLRF COUNT ; Reset counter
MOVF INDF, W ; Move indirectly addressed registers contents to W
CALL LCD_WRITE ; Send data to LCD
INCF FSR, F ; Increment indirectly addressed register pointer
INCF COUNT, F ; Increment count
BTFSS COUNT, 5 ; Count 32?
GOTO $-D'5' ; No? Do again. Yes? Skip..
RETURN