;DISPLAY_LED
ANDLW 0x0F ; Make sure only 4 lower bits are valid
MOVWF PORTD
CALL DELAY255
CALL DELAY255
CALL DELAY255
RETURN
Hi Eric... a quick question. When you set a flag do you use say a bit in a variable and set that and then test for it with BTFSS in main?
Also I assume when you refer to the setting of interrupt flags you mean initialise the LCD as well and then set the interrupt flags...
I only just worked out that 3 in HEX is not the same as 3 in ASCII (I knew this but realised it in this programming context earlier today). The display_led was a crude way to determine if my program was getting there...
Hi Eric,
I could see two call statements one of which I removed and then moved the other (I moved the call statement to GET_Keys to the EVAL_KEYS routine) but it still played up.. so I am not sure what to do next.. It would be great if you could make the necessary changes and let me know why. As wp100 says these are the traps beginners find and I am no exception..
Simon
I really appreciate the time, effort and help your are giving with this.
;===============================================================================
; PROGRAM JUMP TO START.
;===============================================================================
org RESET_V ;RESET VECTOR LOCATION.
goto START
;=============================================================================
;THIS IS THE INTERUPT ROUTINE. sss
;=============================================================================
SERVICE_INTRPT
org ISRV_V ;INTERRUPT VECTOR LOCATION.
movwf W_ISR_TEMP ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf STATUS_ISR_TEMP ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf PCLATH_ISR_TEMP ; save off contents of PCLATH register
movf PORTB,W ; read PORTB to clear any mismatch condition
bcf INTCON,GIE ;DISABLE ALL INTERRUPTS.
bcf INTCON,RBIF ;clear portb intrf
bcf flags,0 ;clear the key pressed flags bit
movf PORTB,W ;check sense of portb intr
andlw 0xf0
sublw 0x00 ;if PORTB 7~4 are high the key has been released
btfss STATUS,Z
bsf flags,0 ;else a key is pressed down
nop
;call DELAY30
ISREND
movf PCLATH_ISR_TEMP,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf STATUS_ISR_TEMP,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf W_ISR_TEMP,f
swapf W_ISR_TEMP,w ; restore pre-isr W register contents
retfie ; return from interrupt
;===============================================================================
; PROGRAM STARTS HERE.
;===============================================================================
START: ;sss
call PIC_INIT ;INITIALIZE FOR RC0-7 TO BE OUTPUTS.
call LCD_INIT ;NOW INITIALIZE THE LCD FOR 4 BIT OPERATION.
call DISPLAY ;DISPLAY "HELLO WORLD".
;===============================================================================
;ENABLE INTERRUPTS.
;===============================================================================
clrf PIE1
clrf INTCON ; clr ALL intr
movf PORTB,W ;read PORTB
bcf INTCON,INTF ;CLEAR INTERRUPT FLAG.
bsf INTCON,RBIE ;ENABLE INTERRUPT ON RB4-7 CHANGE.
bsf INTCON,GIE ;ENABLE ALL INTERRUPTS.
LOOP
;bsf INTCON,GIE ;restore intr
btfss flags,0 ;TEST FOR KEYPAD f=flags bit
goto LOOP ;not set so loop
bcf flags,0 ;clear the flag
call GETKEY ;KEY PRESSED NOW IN W (0 - 15).
;iorlw 0x30
;Call LCD_DISP_CHAR
call EVAL_KEY
bsf INTCON,GIE ;restore the intr
goto LOOP
Hi Eric, Others
After floundering around for hours and hours with this I now have it working with the interrupt and the LCD displaying the number entered onto the keypad just like a calculator... I wasnt able to get the interrupt to work with a flag as you showed unfortunately no matter what I tried... hey it works and I am making sure that any calls from the interrupt dont go more than two deep keeping in mind that you can only go 8 deep..
So many many thanks for your time on this...
Hi Eric,
I kept modifying the code until it worked and didnt keep a copy of the asm program at that stage... trying to work through the details myself... I have loaded the program as it worked without the flags mod..
I have another problem and will start another thread in a few moments with the program as it stands now...
Simon
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?