list p=16f690
#include <p16f690.inc>
__CONFIG -_MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
ERRORLEVEL -302
UDATA
temp RES 1
display RES 1
count RES 1
;**************************STEUP THE CONSTANTS*******************************
org 0x05 ;this is where we come on power up and reset
;**************************INTRUPT ROUTINE************************************
movwf temp ;this and the lable Loop will run simultenously
;move w into f in case to there was someting in
;count(see first step of Loop)
incf count,f ;increase count by 1 and put result in count
movlw .10 ;load w with decimal 10
subwf count,w ;subtract count from w and place result in w
btfss STATUS,C ;if in above operation count<= w then carry bit
;is set, so check for that and skip next step
;if it is set
goto carry_on
goto clear
carry_on:
bcf INTCON,0x01 ;clear the INTF, just in case(read tuto. 11)
movfw temp ;move temp to w
retfie ;get out of intrupt loop (this will start over
; the whole INTRUPT LOOP again
clear:
clrf count ;set count to 0
bcf INTCON,0x01 ;clear INTF
retfie
;*****************************MAIN PROGRAMME************************
Main:
;*****************************SET UP THE INTRUP REGISTERS***********
bsf INTCON,0x07 ; set globel intrupt (tell PIC that we will use intrupts)
bsf INTCON,0x04 ;
bcf INTCON,0x01
;******************************SET UP THE PORTS**********************
bsf STATUS,RP0
movlw b'10000000'
movwf TRISC
bcf STATUS,RP0
;******************************NOW SEND THE VALUE OF COUNT TO PORTC**
Loop:
movf count,w
movwf PORTC
goto Loop
END
list p=16f690
#include <p16f690.inc>
__CONFIG _WDT_OFF & _INTRC_OSC_NOCLKOUT
cblock 0x20
count
endc
Wtemp equ 0x70 ; all bank RAM
org 0x00 ; this is where we come on power up and reset
goto Init
;**************************INTRUPT ROUTINE************************************
org 0x04
IRQ movwf Wtemp ; save W
incf count,f ;increase count by 1 and put result in count
movlw .10
subwf count,w ;subtract count from w and place result in w
btfsc STATUS,C ;if in above operation count<= w then carry bit
clrf count
movf count,W
movwf PORTC ; display W on PORTC
movf Wtemp,W ; restore W
bcf INTCON,INTF
return
Init bsf STATUS,RP0 ;b1
movlw b'10000000'
movwf TRISC
bcf STATUS,RP0 ;b0
clrf count ; count = 0
bsf INTCON,T0IE
bcf INTCON,INTF
bsf INTCON,GIE
Main call IRQ ; wait till next interrupt
goto Main
END
list p=16f690
#include <p16f690.inc>
__CONFIG -_MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
ERRORLEVEL -302
[COLOR="Blue"]cblock 0x20[/COLOR]
temp RES 1
display RES 1
count RES 1
[COLOR="blue"]endc[/COLOR]
;**************************STEUP THE CONSTANTS*******************************
[COLOR="Blue"]org 0x0 [/COLOR] ;this is where we come on power up and reset
[COLOR="blue"]goto Main[/COLOR]
;**************************INTRUPT ROUTINE************************************
[COLOR="blue"]org 0x04[/COLOR]
movwf temp ;this and the lable Loop will run simultenously
;move w into f in case to there was someting in
;count(see first step of Loop)
incf count,f ;increase count by 1 and put result in count
movlw .10 ;load w with decimal 10
subwf count,w ;subtract count from w and place result in w
btfss STATUS,C ;if in above operation count<= w then carry bit
;is set, so check for that and skip next step
;if it is set
goto carry_on
goto clear
carry_on:
bcf INTCON,0x01 ;clear the INTF, just in case(read tuto. 11)
movfw temp ;move temp to w
retfie ;get out of intrupt loop (this will start over
; the whole INTRUPT LOOP again
clear:
clrf count ;set count to 0
bcf INTCON,0x01 ;clear INTF
retfie
;*****************************MAIN PROGRAMME************************
Main:
;*****************************SET UP THE INTRUP REGISTERS***********
bsf INTCON,0x07 ; set globel intrupt (tell PIC that we will use intrupts)
bsf INTCON,0x04 ;
bcf INTCON,0x01
;******************************SET UP THE PORTS**********************
bsf STATUS,RP0
movlw b'10000000'
movwf TRISC
bcf STATUS,RP0
;******************************NOW SEND THE VALUE OF COUNT TO PORTC**
Loop:
movf count,w
movwf PORTC
goto Loop
END
yor idia of not using linker gives too many errors:Forget about the linker and just have 1 asm file to start with. To get your code to compile without the linker, change it to,
Code:list p=16f690 #include <p16f690.inc> __CONFIG -_MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT ERRORLEVEL -302 [COLOR="Blue"]cblock 0x20[/COLOR] temp RES 1 display RES 1 count RES 1 [COLOR="blue"]endc[/COLOR] ;**************************STEUP THE CONSTANTS******************************* [COLOR="Blue"]org 0x0 [/COLOR] ;this is where we come on power up and reset [COLOR="blue"]goto Main[/COLOR] ;**************************INTRUPT ROUTINE************************************ [COLOR="blue"]org 0x04[/COLOR] movwf temp ;this and the lable Loop will run simultenously ;move w into f in case to there was someting in ;count(see first step of Loop) incf count,f ;increase count by 1 and put result in count movlw .10 ;load w with decimal 10 subwf count,w ;subtract count from w and place result in w btfss STATUS,C ;if in above operation count<= w then carry bit ;is set, so check for that and skip next step ;if it is set goto carry_on goto clear carry_on: bcf INTCON,0x01 ;clear the INTF, just in case(read tuto. 11) movfw temp ;move temp to w retfie ;get out of intrupt loop (this will start over ; the whole INTRUPT LOOP again clear: clrf count ;set count to 0 bcf INTCON,0x01 ;clear INTF retfie ;*****************************MAIN PROGRAMME************************ Main: ;*****************************SET UP THE INTRUP REGISTERS*********** bsf INTCON,0x07 ; set globel intrupt (tell PIC that we will use intrupts) bsf INTCON,0x04 ; bcf INTCON,0x01 ;******************************SET UP THE PORTS********************** bsf STATUS,RP0 movlw b'10000000' movwf TRISC bcf STATUS,RP0 ;******************************NOW SEND THE VALUE OF COUNT TO PORTC** Loop: movf count,w movwf PORTC goto Loop END
You should also read the data sheet about context saving in interrupts. (section 9.5)
Edit, forget Bill's code as well at the moment. It doesn't demonstrate interrupts at all and has just served to confuse you.
Mike.
list p=16f690
#include <p16f690.inc>
__CONFIG -_MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
ERRORLEVEL -302
cblock 0x20
temp ;;RES 1
display ;;RES 1
count ;;RES 1
endc
;**************************STEUP THE CONSTANTS*******************************
org 0x0 ;this is where we come on power up and reset
goto Main
;**************************INTRUPT ROUTINE************************************
org 0x04
movwf temp ;this and the lable Loop will run simultenously
;move w into f in case to there was someting in
;count(see first step of Loop)
incf count,f ;increase count by 1 and put result in count
movlw .10 ;load w with decimal 10
subwf count,w ;subtract count from w and place result in w
btfss STATUS,C ;if in above operation count<= w then carry bit
;is set, so check for that and skip next step
;if it is set
goto carry_on
goto clear
carry_on:
bcf INTCON,0x01 ;clear the INTF, just in case(read tuto. 11)
movfw temp ;move temp to w
retfie ;get out of intrupt loop (this will start over
; the whole INTRUPT LOOP again
clear:
clrf count ;set count to 0
bcf INTCON,0x01 ;clear INTF
retfie
;*****************************MAIN PROGRAMME************************
Main:
;*****************************SET UP THE INTRUP REGISTERS***********
bsf INTCON,0x07 ; set globel intrupt (tell PIC that we will use intrupts)
bsf INTCON,0x04 ;
bcf INTCON,0x01
;******************************SET UP THE PORTS**********************
bsf STATUS,RP0
movlw b'10000000'
movwf TRISC
bcf STATUS,RP0
;******************************NOW SEND THE VALUE OF COUNT TO PORTC**
Loop:
movf count,w
movwf PORTC
goto Loop
END
list p=16f690
#include <p16f690.inc>
__CONFIG -_MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
ERRORLEVEL -302
cblock 0x20
temp ;RES 1
display ;RES 1
count ;RES 1
endc
;**************************STEUP THE CONSTANTS*******************************
org 0x00 ;this is where we come on power up and reset
goto Main
;**************************INTRUPT ROUTINE************************************
[COLOR="Red"]org 0x05[/COLOR]
movwf temp ;this and the lable Loop will run simultenously
;move w into f in case to there was someting in
;count(see first step of Loop)
incf count,f ;increase count by 1 and put result in count
movlw .10 ;load w with decimal 10
subwf count,w ;subtract count from w and place result in w
btfss STATUS,C ;if in above operation count<= w then carry bit
;is set, so check for that and skip next step
;if it is set
goto carry_on
goto clear
carry_on:
bcf INTCON,0x01 ;clear the INTF, just in case(read tuto. 11)
movfw temp ;move temp to w
retfie ;get out of intrupt loop (this will start over
; the whole INTRUPT LOOP again
clear:
clrf count ;set count to 0
bcf INTCON,0x01 ;clear INTF
retfie
;*****************************MAIN PROGRAMME************************
Main:
;*****************************SET UP THE INTRUP REGISTERS***********
bsf INTCON,0x07 ; set globel intrupt (tell PIC that we will use intrupts)
bsf INTCON,0x04 ;
bcf INTCON,0x01
;******************************SET UP THE PORTS**********************
bsf STATUS,RP0
movlw b'10000000'
movwf TRISC
movlw b'00000100'
movwf TRISA ;set RA2 as input (for interrupt)
bcf STATUS,RP0
;******************************NOW SEND THE VALUE OF COUNT TO PORTC**
Loop:
movf count,w
movwf PORTC
goto Loop
END
list p=16f690
#include <p16f690.inc>
__CONFIG -_MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
ERRORLEVEL -302
cblock 0x20
temp
display
count
endc
;**************************STEUP THE CONSTANTS*******************************
org 0x00 ;this is where we come on power up and reset
goto Main
;**************************INTRUPT ROUTINE************************************
org 0x04
movwf temp ;this and the lable Loop will run simultenously
;move w into f in case to there was someting in
;count(see first step of Loop)
incf count,f ;increase count by 1 and put result in count
movlw .10 ;load w with decimal 10
subwf count,w ;subtract count from w and place result in w
btfss STATUS,C ;if in above operation count<= w then carry bit
;is set, so check for that and skip next step
;if it is set
goto carry_on
goto clear
carry_on:
bcf INTCON,0x01 ;clear the INTF, just in case(read tuto. 11)
movfw temp ;move temp to w
retfie ;get out of intrupt loop (this will start over
; the whole INTRUPT LOOP again
clear:
clrf count ;set count to 0
bcf INTCON,0x01 ;clear INTF
retfie
;*****************************MAIN PROGRAMME************************
Main:
;*****************************SET UP THE INTRUP REGISTERS***********
bsf INTCON,0x07 ; set globel intrupt (tell PIC that we will use intrupts)
bsf INTCON,0x04 ;
bcf INTCON,0x01
;******************************SET UP THE PORTS**********************
bsf STATUS,RP0
movlw b'10000000'
movwf TRISC
[COLOR="Red"]bcf STATUS,RP0
bsf STATUS,RP1
clrf ANSEL[/COLOR]
movlw b'00000100'
movwf TRISA ;set RA2 as input (for interrupt)
bcf STATUS,RP0
;******************************NOW SEND THE VALUE OF COUNT TO PORTC**
Loop:
movf count,w
movwf PORTC
goto Loop
END
;******************************SET UP THE PORTS**********************
bsf STATUS,RP0 ;bank 1
movlw b'10000000'
movwf TRISC
movlw b'00000100'
movwf TRISA ;set RA2 as input (for interrupt)
bcf STATUS,RP0 ;bank 0
bsf STATUS,RP1 ;bank 2
clrf ANSEL
bcf STATUS,RP1 ;bank 0
;******************************NOW SEND THE VALUE OF COUNT TO PORTC**
list p=16f690
#include <p16f690.inc>
__CONFIG -_MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
ERRORLEVEL -302
cblock 0x20
temp
display
count
endc
;**************************STEUP THE CONSTANTS*******************************
org 0x00 ;this is where we come on power up and reset
goto Main
;**************************INTRUPT ROUTINE************************************
org 0x04
movwf temp ;this and the lable Loop will run simultenously
;move w into f in case to there was someting in
;count(see first step of Loop)
incf count,f ;increase count by 1 and put result in count
movlw .10 ;load w with decimal 10
subwf count,w ;subtract count from w and place result in w
btfss STATUS,C ;if in above operation count<= w then carry bit
;is set, so check for that and skip next step
;if it is set
goto carry_on
goto clear
carry_on:
bcf INTCON,0x01 ;clear the INTF, just in case
movfw temp ;move temp to w
retfie ;get out of intrupt loop (this will start over
; the whole INTRUPT LOOP again
clear:
clrf count ;set count to 0
bcf INTCON,0x01 ;clear INTF
retfie
;*****************************MAIN PROGRAMME************************
Main:
;*****************************SET UP THE INTRUP REGISTERS***********
bsf INTCON,0x07 ; set globel intrupt (tell PIC that we will use intrupts)
bsf INTCON,0x04 ;
bcf INTCON,0x01
;******************************SET UP THE PORTS**********************
[COLOR="Red"]bsf STATUS,RP0
movlw b'10000000'
movwf TRISC
movlw b'00000100'
movwf TRISA ;set RA2 as input (for interrupt)
bcf STATUS,RP0
bsf STATUS,RP1
clrf ANSEL
bcf STATUS,RP1[/COLOR];******************************NOW SEND THE VALUE OF COUNT TO PORTC**
Loop:
movf count,w
movwf PORTC
goto Loop
END
Yes eric I do follow that and thank you for that to the point answer but, what if I want to set more than one interrupt, I mean only one interrupt can start at 0x04
and I'm still waiting for that code to be solved please don;t forget that (this is for any one who usually jumps to the final post, so my problem is yet not solved, please read few preavious posts )
(this is for any one who usually jumps to the final post, my problem is yet not solved, please read few preavious posts )
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?