![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hello,
I cannot get the interrupt to work correctly on the following code. Can anybody see what I am doing wrong? Thanks cblock 0x20 Delay1 ; Assign an address to label Delay1 Delay2 Display ; define a variable to hold the diplay Direction LookingFor temp1 die1 temp2 die2 endc cblock 0x70 W_Save STATUS_Save endc org 0 goto Start org 0x004 ; interrupt vector location Init: clrf PORTA ; Clears memory in file register A clrf PORTB ; Clears memory in file register B clrf PORTC ; Clears memory in file register C clrf PORTD ; Clears memory in file register D clrf PORTE ; Clears memory in file register E bsf STATUS,RP0 ; select Register Bank bsf IOCB,0 movlw 0x01 movwf TRISB ; Make RB0 input clrf TRISD ; Make PortD all output movlw b'10010000' movwf INTCON movlw b'00000111' movwf OPTION_REG ; Maximum Prescale bcf STATUS,RP0 ; back to Register Bank 0 return ISR: movwf W_Save ; Save context movf STATUS,w movwf STATUS_Save btfsc INTCON,INTE goto DieNumSel goto ExitISR DieNumSel: movf TMR0,w ;grabs a value from TMR0 and stores in working reg. movwf temp1 ;moves working reg to file temp1. andlw b'00000111' ;Ands literal 00000111 to working reg call Tabledie1 ;calls tabledie1 movwf die1 ;moves result of working to file die1 btfsc die1,7 ;tests msb, if 1 go back to beginning to ensure no 1 in msb. goto DieNumSel movf temp1,w swapf temp1,w andlw b'00000111' call Tabledie2 movwf die2 btfsc die2,7 goto DieNumSel ;swapf die2 ;movf die1,w addwf die1,w movwf PORTD goto $ Tabledie1: addwf PCL,f ;jump to retlw b'10000000' retlw b'00000001' retlw b'00000010' retlw b'00000011' retlw b'00000100' retlw b'00000101' retlw b'00000110' retlw b'10000111' Tabledie2: addwf PCL,f ;jump to retlw b'10000000' retlw b'00000001' retlw b'00000010' retlw b'00000011' retlw b'00000100' retlw b'00000101' retlw b'00000110' retlw b'10000111' ExitISR: movf STATUS_Save,w ; Restore context movwf STATUS swapf W_Save,f ; swapf doesn't affect Status bits, but MOVF would swapf W_Save,w retfie Start: call Init rotate: end |
|
|
|
|
|
|
(permalink) |
|
what uC your using(chip)
org 0x00 goto Start org 0x004 ; interrupt vector location goto ISR Try that
__________________
My YouTube Videos! My Favorite Stores: dipmicro Electronics SparkFun Electronics Futurlec BG Micro |
|
|
|
|
|
|
(permalink) |
|
Ill try it.
THanks |
|
|
|
|
|
|
(permalink) |
|
I am using the pic 16f887
|
|
|
|
|
|
|
(permalink) |
|
Doesnt this look way better?
Code:
cblock 0x20 Delay1 ; Assign an address to label Delay1 Delay2 Display ; define a variable to hold the diplay Direction LookingFor temp1 die1 temp2 die2 endc cblock 0x70 W_Save STATUS_Save endc org 0x00 goto Start org 0x004 ; interrupt vector location goto ISR Init: clrf PORTA ; Clears memory in file register A clrf PORTB ; Clears memory in file register B clrf PORTC ; Clears memory in file register C clrf PORTD ; Clears memory in file register D clrf PORTE ; Clears memory in file register E bsf STATUS,RP0 ; select Register Bank bsf IOCB,0 movlw 0x01 movwf TRISB ; Make RB0 input clrf TRISD ; Make PortD all output movlw b'10010000' movwf INTCON movlw b'00000111' movwf OPTION_REG ; Maximum Prescale bcf STATUS,RP0 ; back to Register Bank 0 return ISR: movwf W_Save ; Save context movf STATUS,w movwf STATUS_Save btfsc INTCON,INTE goto DieNumSel goto ExitISR DieNumSel: movf TMR0,w ;grabs a value from TMR0 and stores in working reg. movwf temp1 ;moves working reg to file temp1. andlw b'00000111' ;Ands literal 00000111 to working reg call Tabledie1 ;calls tabledie1 movwf die1 ;moves result of working to file die1 btfsc die1,7 ;tests msb, if 1 go back to beginning to ensure no 1 in msb. goto DieNumSel movf temp1,w swapf temp1,w andlw b'00000111' call Tabledie2 movwf die2 btfsc die2,7 goto DieNumSel ;swapf die2 ;movf die1,w addwf die1,w movwf PORTD goto $ Tabledie1: addwf PCL,f ;jump to retlw b'10000000' retlw b'00000001' retlw b'00000010' retlw b'00000011' retlw b'00000100' retlw b'00000101' retlw b'00000110' retlw b'10000111' Tabledie2: addwf PCL,f ;jump to retlw b'10000000' retlw b'00000001' retlw b'00000010' retlw b'00000011' retlw b'00000100' retlw b'00000101' retlw b'00000110' retlw b'10000111' ExitISR: movf STATUS_Save,w ; Restore context movwf STATUS swapf W_Save,f ; swapf doesn't affect Status bits, but MOVF would swapf W_Save,w retfie Start: call Init rotate: end
__________________
My YouTube Videos! My Favorite Stores: dipmicro Electronics SparkFun Electronics Futurlec BG Micro |
|
|
|
|
|
|
(permalink) |
|
Thanks for the info, but the goto ISR failed to get the interrupt to work.
|
|
|
|
|
|
|
(permalink) |
|
btfsc INTCON,INTE
This just test if the interrupt is enabled and not if the flag bit is set... What are you trying to do? Code:
REGISTER 2-3: INTCON: INTERRUPT CONTROL REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-x GIE PEIE T0IE INTE RBIE(1) T0IF(2) INTF RBIF bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 GIE: Global Interrupt Enable bit 1 = Enables all unmasked interrupts 0 = Disables all interrupts bit 6 PEIE: Peripheral Interrupt Enable bit 1 = Enables all unmasked peripheral interrupts 0 = Disables all peripheral interrupts bit 5 T0IE: Timer0 Overflow Interrupt Enable bit 1 = Enables the Timer0 interrupt 0 = Disables the Timer0 interrupt bit 4 INTE: INT External Interrupt Enable bit 1 = Enables the INT external interrupt 0 = Disables the INT external interrupt bit 3 RBIE: PORTB Change Interrupt Enable bit(1) 1 = Enables the PORTB change interrupt 0 = Disables the PORTB change interrupt bit 2 T0IF: Timer0 Overflow Interrupt Flag bit(2) 1 = TMR0 register has overflowed (must be cleared in software) 0 = TMR0 register did not overflow bit 1 INTF: INT External Interrupt Flag bit 1 = The INT external interrupt occurred (must be cleared in software) 0 = The INT external interrupt did not occur bit 0 RBIF: PORTB Change Interrupt Flag bit 1 = When at least one of the PORTB general purpose I/O pins changed state (must be cleared in software) 0 = None of the PORTB general purpose I/O pins have changed state
__________________
My YouTube Videos! My Favorite Stores: dipmicro Electronics SparkFun Electronics Futurlec BG Micro Last edited by AtomSoft; 21st May 2008 at 12:16 AM. |
|
|
|
|
|
|
(permalink) |
|
I am trying to use the button to interrupt to pick a random value from the below code.
I am using INTE and INTF for the registers. DieNumSel: bcf INTCON,0 movf TMR0,w ;grabs a value from TMR0 and stores in working reg. movwf temp1 ;moves working reg to file temp1. andlw b'00000111' ;Ands literal 00000111 to working reg call Tabledie1 ;calls tabledie1 movwf die1 ;moves result of working to file die1 btfsc die1,7 ;tests msb, if 1 go back to beginning to ensure no 1 in msb. goto DieNumSel movf temp1,w swapf temp1,w andlw b'00000111' call Tabledie2 movwf die2 btfsc die2,7 goto DieNumSel addwf die1,w movwf PORTD goto $ retfie Tabledie1: addwf PCL,f ;jump to retlw b'10000000' retlw b'00000001' retlw b'00000010' retlw b'00000011' retlw b'00000100' retlw b'00000101' retlw b'00000110' retlw b'10000111' Tabledie2: addwf PCL,f ;jump to retlw b'10000000' retlw b'00000001' retlw b'00000010' retlw b'00000011' retlw b'00000100' retlw b'00000101' retlw b'00000110' retlw b'10000111' ExitISR: movf STATUS_Save,w ; Restore context movwf STATUS swapf W_Save,f ; swapf doesn't affect Status bits, but MOVF would swapf W_Save,w retfie |
|
|
|
|
|
|
(permalink) |
|
This is above the label DieNumSel from the previous post.
ISR: movwf W_Save ; Save context movf STATUS,w movwf STATUS_Save btfsc INTCON,INTF goto DieNumSel goto ExitISR |
|
|
|
|
|
|
(permalink) |
|
INTE: INT External Interrupt Enable
You are checking the wrong thing i assume you want to check RBIF or INTF Since those are the flag bits... also you have to clear the bit before you can check for another interrupt.. This code is confusing as that all you do is run the INIT then program ends Try: Code:
Start:
call Init
WaitForInt:
goto WaitForInt
end
This is all i thik i can help you with . You can still ask other and i hope they help you out. FINAL Code:
cblock 0x20
Delay1 ; Assign an address to label Delay1
Delay2
Display ; define a variable to hold the diplay
Direction
LookingFor
temp1
die1
temp2
die2
endc
cblock 0x70
W_Save
STATUS_Save
endc
org 0x00
goto Start
org 0x004 ; interrupt vector location
goto ISR
Init:
clrf PORTA ; Clears memory in file register A
clrf PORTB ; Clears memory in file register B
clrf PORTC ; Clears memory in file register C
clrf PORTD ; Clears memory in file register D
clrf PORTE ; Clears memory in file register E
bsf STATUS,RP0 ; select Register Bank
bsf IOCB,0
movlw 0x01
movwf TRISB ; Make RB0 input
clrf TRISD ; Make PortD all output
movlw b'10010000'
movwf INTCON
movlw b'00000111'
movwf OPTION_REG ; Maximum Prescale
bcf STATUS,RP0 ; back to Register Bank 0
return
ISR:
movwf W_Save ; Save context
movf STATUS,w
movwf STATUS_Save
btfsc INTCON,INTF
goto DieNumSel
goto ExitISR
DieNumSel:
movf TMR0,w ;grabs a value from TMR0 and stores in working reg.
movwf temp1 ;moves working reg to file temp1.
andlw b'00000111' ;Ands literal 00000111 to working reg
call Tabledie1 ;calls tabledie1
movwf die1 ;moves result of working to file die1
btfsc die1,7 ;tests msb, if 1 go back to beginning to ensure no 1 in msb.
goto DieNumSel
movf temp1,w
swapf temp1,w
andlw b'00000111'
call Tabledie2
movwf die2
btfsc die2,7
goto DieNumSel
;swapf die2
;movf die1,w
addwf die1,w
movwf PORTD
goto $
Tabledie1:
addwf PCL,f ;jump to
retlw b'10000000'
retlw b'00000001'
retlw b'00000010'
retlw b'00000011'
retlw b'00000100'
retlw b'00000101'
retlw b'00000110'
retlw b'10000111'
Tabledie2:
addwf PCL,f ;jump to
retlw b'10000000'
retlw b'00000001'
retlw b'00000010'
retlw b'00000011'
retlw b'00000100'
retlw b'00000101'
retlw b'00000110'
retlw b'10000111'
ExitISR:
movf STATUS_Save,w ; Restore context
movwf STATUS
swapf W_Save,f ; swapf doesn't affect Status bits, but MOVF would
swapf W_Save,w
retfie
Start:
call Init
WaitForInt:
goto WaitForInt
end
__________________
My YouTube Videos! My Favorite Stores: dipmicro Electronics SparkFun Electronics Futurlec BG Micro Last edited by AtomSoft; 21st May 2008 at 12:38 AM. |
|
|
|
|
|
|
(permalink) |
|
This is sample ASM from MPLAB
Code:
;********************************************************************** ; This file is a basic code template for assembly code generation * ; on the PIC16F887. This file contains the basic code * ; building blocks to build upon. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler (Document DS33014). * ; * ; Refer to the respective PIC data sheet for additional * ; information on the instruction set. * ; * ;********************************************************************** ; * ; Filename: xxx.asm * ; Date: * ; File Version: * ; * ; Author: * ; Company: * ; * ; * ;********************************************************************** ; * ; Files Required: P16F887.INC * ; * ;********************************************************************** ; * ; Notes: * ; * ;********************************************************************** list p=16f887 ; list directive to define processor #include <p16f887.inc> ; processor specific variable definitions ; '__CONFIG' directive is used to embed configuration data within .asm file. ; The labels following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. __CONFIG _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT __CONFIG _CONFIG2, _WRT_OFF & _BOR21V ;***** VARIABLE DEFINITIONS w_temp EQU 0x7D ; variable used for context saving status_temp EQU 0x7E ; variable used for context saving pclath_temp EQU 0x7F ; variable used for context saving ;********************************************************************** ORG 0x000 ; processor reset vector nop goto main ; go to beginning of program ORG 0x004 ; interrupt vector location 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 movf PCLATH,w ; move pclath register into w register movwf pclath_temp ; save off contents of PCLATH register ; isr code can go here or be located as a call subroutine elsewhere movf pclath_temp,w ; retrieve copy of PCLATH register movwf PCLATH ; restore pre-isr PCLATH register contents 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 ; remaining code goes here ; example of preloading EEPROM locations ORG 0x2100 DE 5, 4, 3, 2, 1 END ; directive 'end of program'
__________________
My YouTube Videos! My Favorite Stores: dipmicro Electronics SparkFun Electronics Futurlec BG Micro |
|
|
|
|
|
|
(permalink) |
|
I set the GIE,INTE and I am checking the INTF. There is more code than Init but it relates to rotating leds around the 16f887 board. I will keep looking at it.
thanks |
|
|
|
|
|
|
(permalink) |
|
Thats the thing you dont have to check the INTF if you get to the point that your checking it its because its set. That flag is there to tell the uC that a interrupt has occured all you have to do is clear it. If its ever set it will jump to the ISR code. So what you should do is remove that check frmo the ISR like this:
Code:
ISR:
BCF INTCON,INTF ; Clear the Flag so new interrupts can be handled
movwf W_Save ; Save context
movf STATUS,w
movwf STATUS_Save
DieNumSel: ;Now this is in the ISR CODE without a jump
movf TMR0,w ;grabs a value from TMR0 and stores in working reg.
movwf temp1 ;moves working reg to file temp1.
andlw b'00000111' ;Ands literal 00000111 to working reg
call Tabledie1 ;calls tabledie1
movwf die1 ;moves result of working to file die1
btfsc die1,7 ;tests msb, if 1 go back to beginning to ensure no 1 in msb.
goto DieNumSel
movf temp1,w
swapf temp1,w
andlw b'00000111'
call Tabledie2
movwf die2
btfsc die2,7
goto DieNumSel
;swapf die2
;movf die1,w
addwf die1,w
movwf PORTD
goto $
ExitISR: ; Again no jump needed
movf STATUS_Save,w ; Restore context
movwf STATUS
swapf W_Save,f ; swapf doesn't affect Status bits, but MOVF would
swapf W_Save,w
retfie
Code:
cblock 0x20
Delay1 ; Assign an address to label Delay1
Delay2
Display ; define a variable to hold the diplay
Direction
LookingFor
temp1
die1
temp2
die2
endc
cblock 0x70
W_Save
STATUS_Save
endc
org 0x00
goto Start
org 0x004 ; interrupt vector location
goto ISR
Init:
clrf PORTA ; Clears memory in file register A
clrf PORTB ; Clears memory in file register B
clrf PORTC ; Clears memory in file register C
clrf PORTD ; Clears memory in file register D
clrf PORTE ; Clears memory in file register E
bsf STATUS,RP0 ; select Register Bank
bsf IOCB,0
movlw 0x01
movwf TRISB ; Make RB0 input
clrf TRISD ; Make PortD all output
movlw b'10010000'
movwf INTCON
movlw b'00000111'
movwf OPTION_REG ; Maximum Prescale
bcf STATUS,RP0 ; back to Register Bank 0
return
ISR:
BCF INTCON,INTF ; Clear the Flag so new interrupts can be handled
movwf W_Save ; Save context
movf STATUS,w
movwf STATUS_Save
DieNumSel:
movf TMR0,w ;grabs a value from TMR0 and stores in working reg.
movwf temp1 ;moves working reg to file temp1.
andlw b'00000111' ;Ands literal 00000111 to working reg
call Tabledie1 ;calls tabledie1
movwf die1 ;moves result of working to file die1
btfsc die1,7 ;tests msb, if 1 go back to beginning to ensure no 1 in msb.
goto DieNumSel
movf temp1,w
swapf temp1,w
andlw b'00000111'
call Tabledie2
movwf die2
btfsc die2,7
goto DieNumSel
;swapf die2
;movf die1,w
addwf die1,w
movwf PORTD
goto $
ExitISR: ; Exit right after the end of your jump code
movf STATUS_Save,w ; Restore context
movwf STATUS
swapf W_Save,f ; swapf doesn't affect Status bits, but MOVF would
swapf W_Save,w
retfie
Tabledie1:
addwf PCL,f ;jump to
retlw b'10000000'
retlw b'00000001'
retlw b'00000010'
retlw b'00000011'
retlw b'00000100'
retlw b'00000101'
retlw b'00000110'
retlw b'10000111'
Tabledie2:
addwf PCL,f ;jump to
retlw b'10000000'
retlw b'00000001'
retlw b'00000010'
retlw b'00000011'
retlw b'00000100'
retlw b'00000101'
retlw b'00000110'
retlw b'10000111'
Start:
call Init
WaitForInt:
goto WaitForInt ; wait for interrupt in loop
end
__________________
My YouTube Videos! My Favorite Stores: dipmicro Electronics SparkFun Electronics Futurlec BG Micro Last edited by AtomSoft; 21st May 2008 at 01:02 AM. |
|
|
|
|
|
|
(permalink) |
|
Here is the whole code, if I attached it correct.
thanks |
|
|
|
|
|
|
(permalink) |
|
Test this ... im tired ill help you more tomorrow if you still need it or if someone else hasnt helped.
__________________
My YouTube Videos! My Favorite Stores: dipmicro Electronics SparkFun Electronics Futurlec BG Micro |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Interrupt triggering communication with a host computer and counting interrupt calls | ssylee | Micro Controllers | 1 | 12th May 2008 06:08 AM |
| odd project, 1 button adds a light 1 button takes a light away with sound. | KevinAlaska | Electronic Projects Design/Ideas/Reviews | 15 | 6th June 2007 04:38 AM |
| Interrupt problems! | amindzo | Micro Controllers | 16 | 9th November 2006 08:11 PM |
| RB0 interrupt problems | amindzo | Micro Controllers | 4 | 26th August 2006 12:14 PM |
| Timer: Interrupt Flag (IF) and Interrupt Enable (IE) | patricktran | Micro Controllers | 0 | 25th April 2004 05:11 AM |