gogo2520
Junior Member level 1
Hello
I have been studying different parts of a program in the simulator and on project board. I ran into something I don't understand. I'll post the code then explain the problem
Ok the switch part I ran on a project board and had no problems with it, what is dose is when I push a button a LED lights up and stays lit until I release the button. The timer1 part I ran in the simulator and it work. So I added the switch part to the timer1 part and now the switches don't work right. When I run it on a project board just one LED lights up and stays on no matter what button I push.
What I think is happening is the Timer1 setup is turning on the PORTB interrupt, INTCON,RBIF somehow and I can't figure out how to turn it off.
OR the RETFIE after the ISR is.
So any info would help Thank You.
gogo
I have been studying different parts of a program in the simulator and on project board. I ran into something I don't understand. I'll post the code then explain the problem
Code:
;Timer1-s1.asm FOR SIMULATOR
; program to test timer1
LIST p=16F628a ;tell assembler what chip we are using
include "P16F628a.inc" ;include the defaults for the chip
__config 0x3D18 ;__config _PWRTE_ON&_LVP_OFF&_CP_OFF&_WDT_OFF&_INTRC_OSC_NOCLKOUT&_BODEN_OFF
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
W_TEMP equ 0x70
STATUS_TEMP equ 0x71
Cblock 0x20
STUFF
count1
endc
goto main
org 0x04
goto dosomething
;;;;; SETUP TIMER1 ;;;;;;;;
INT
CLRF T1CON ; Stop Timer1, Internal Clock Source,
CLRF TMR1H ; Clear Timer1 High byte register
CLRF TMR1L ; Clear Timer1 Low byte register
clrf count1
movlw 0xFD
movwf TMR1H ; for short time period
CLRF INTCON ; Disable interrupts
bsf STATUS, RP0 ; Bank1
bsf T1CON, TMR1ON ; enable timer1
banksel PIE1 ; enable interrupt
bsf PIE1, TMR1IE ; timer1 overflow interrupt enable ;
banksel INTCON ;
bsf INTCON, PEIE ; peripheral interrupt enable
bsf INTCON, GIE ; global interrupt enable
MOVLW 0x0D ; Internal Clock source with 1:1 prescaler
MOVWF T1CON ; Timer1 is stopped and T1 osc is disabled
BSF T1CON, TMR1ON ; Timer1 starts to increment
retlw 0x00
main ;
BANKSEL TRISA
MOVLW 0X00
MOVWF TRISA
MOVLW 0XF0
MOVWF TRISB
BANKSEL PORTA
MOVLW 0X00
MOVWF PORTA ; all ports output
MOVLW 0XF0
MOVWF PORTB ; 0 - 3 outputs, 4 - 7 inputs
call INT ;while waiting for Timer1
goto Start
;8888888888888888 ADDED PART
Start
LOOP
BTFSS PORTB,4 ;button pushed
CALL LED1 ; no then skip
BTFSS PORTB,5 ;button pushed
CALL LED2 ; no then skip
BTFSS PORTB,6 ;button pushed
CALL LED3 ;no then skip
BTFSS PORTB,7 ; button pushed
CALL LED4 ; no then skip
GOTO LOOP ; test buttons again
LED1
BTFSC PORTB,4 ;check again
RETURN ;no go back
BSF PORTB,0 ;yes turn on LED
T1 BTFSS PORTB,4 ; check again
GOTO T1 ; button still pushed test again
BCF PORTB,0 ; button realeased turn off LED
RETURN ; go back to call
LED2
BTFSC PORTB,5 ;check again
RETURN ;no go back
BSF PORTB,1 ;yes turn on LED
T2 BTFSS PORTB,5 ;check again
GOTO T2 ; button still pushed test again
BCF PORTB,1 ; button realeased turn off LED
RETURN ; go back to call
LED3
BTFSC PORTB,6 ;check again
RETURN ;no go back
BSF PORTB,2 ;yes turn on LED
T3 BTFSS PORTB,6 ;check again
GOTO T3 ; button still pushed test again
BCF PORTB,2 ; button realeased turn off LED
RETURN ; go back to call
LED4
BTFSC PORTB,7 ;check again
RETURN ;no go back
BSF PORTB,3 ;yes turn on LED
T4 BTFSS PORTB,7 ;check again
GOTO T4 ; button still pushed test again
BCF PORTB,3 ; button realeased turn off LED
RETURN ; go back to call
;888888888888888888888 END ADDED PART
dosomething
MOVWF W_TEMP ; Copy W to a Temporary Register
; regardless of current bank
SWAPF STATUS,W ; Swap STATUS nibbles and place
; into W register
MOVWF STATUS_TEMP ; Save STATUS to a Temporary register
; in Bank0
;:
;: (Interrupt Service Routine (ISR) )
incf count1, 1
;:
SWAPF STATUS_TEMP,W ; Swap original STATUS register value
; into W (restores original bank)
MOVWF STATUS ; Restore STATUS register from
; W register
SWAPF W_TEMP,F ; Swap W_Temp nibbles and return
; value to W_Temp
SWAPF W_TEMP,W ; Swap W_Temp to W to restore original
; W value without affecting STATUS
; RESET INTERRUPT
nop ;for simulator break POINT
BCF PIR1, TMR1IF
movlw 0xFD
movwf TMR1H
BSF T1CON, TMR1ON ; Timer1 starts to increment
retfie
;********************************************************
end ;Must put end for compiler dosn't effect the program
Ok the switch part I ran on a project board and had no problems with it, what is dose is when I push a button a LED lights up and stays lit until I release the button. The timer1 part I ran in the simulator and it work. So I added the switch part to the timer1 part and now the switches don't work right. When I run it on a project board just one LED lights up and stays on no matter what button I push.
What I think is happening is the Timer1 setup is turning on the PORTB interrupt, INTCON,RBIF somehow and I can't figure out how to turn it off.
OR the RETFIE after the ISR is.
So any info would help Thank You.
gogo