Hi friends,
In one battery charger circuit, I like to use an indication of being the battery charged by blinking a LED. For this purpose, I feel that TMR0 Interrupt could easily be employed. Thus I have assembled a code. But unfortunately, the LED does not blinks. On setting of first interrupt flag, the LED changes its state but it does not respond to the successive interrupt flag settings. I have checked the code in OSHONSOFT simulator which shows the same result. Please see my code and guide me in right way.
regards
swapan.
In one battery charger circuit, I like to use an indication of being the battery charged by blinking a LED. For this purpose, I feel that TMR0 Interrupt could easily be employed. Thus I have assembled a code. But unfortunately, the LED does not blinks. On setting of first interrupt flag, the LED changes its state but it does not respond to the successive interrupt flag settings. I have checked the code in OSHONSOFT simulator which shows the same result. Please see my code and guide me in right way.
regards
swapan.
Code:
list p=16F676 ; list directive to define processor
#include <p16F676.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _HS_OSC
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
;***** VARIABLE DEFINITIONS (examples)
; example of using Shared Uninitialized Data Section
INT_VAR UDATA_SHR 0x20
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
;**********************************************************************
RESET_VECTOR CODE 0x0000 ; processor reset vector
goto start ; go to beginning of program
INT_VECTOR CODE 0x0004 ; interrupt vector location
INTERRUPT
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movlw b'00000001'
xorwf PORTC,1
bcf INTCON,T0IF
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
MAIN_PROG CODE
; these first 4 instructions are not required if the internal oscillator is not used
start
bsf STATUS,RP0
movlw b'111111' ; All bits are input.
movwf TRISA
movlw b'111110' ; All but bit 0 are input.
movwf TRISC
movlw b'00000000' ;
movwf OPTION_REG
bcf STATUS,RP0
movlw b'10100000' ; GIE enabled, Peripheral Interrupts disabled,
movwf INTCON ; TMR0 interrupt enable, External interrupt disabled,
; PORTA change interrupt disabled, TMR0 Overflow bit clear,
btfss PORTA,0 ; This an infinite loop to check the Interrupt service.
goto $-1
goto $-2
; initialize eeprom locations
EE CODE 0x2100
DE 0x00, 0x01, 0x02, 0x03
END ; directive 'end of program'