
Originally Posted by
Jerson
Hi scopit
I can suggest you look at your TRISB settings. Have you set RB0 to input direction?
Hi Jerson,
Thanks for the welcome and the suggestion. RB0 is set to an input and I can connect the pin to 5V and trigger the interrupt routine manually. I have also tried enabling the internal pull ups via the option register, but no difference.
Here's my code which is not the complete progam yet. I have been testing step by step to make sure I have configured correctly. Forgive me if it not the best written code, this is my first serious program!
Any help is gratefully appreciated
Scopit
Code:
list p=16F84A ; list directive to define processor
#include <p16F84a.inc> ; processor specific variable definitions
; Set up constants
TIMER EQU 0x01 ; TMR0 register address
STATUS EQU 0x03 ; Status register address
PORTA EQU 0x05 ; Bank0 PORTA register address
PORTB EQU 0x06 ; Bank0 PORTB register address
INTREG EQU 0x0B ; INTCON register address
OPTREG EQU 0x81 ; OPTION register address
TRISA EQU 0x85 ; Bank1 PORTA register address
TRISB EQU 0x86 ; Bank1 PORTB register address
; Set up constants
TARGET EQU 0x59 ; Target interval ideal value of 89Dec 59Hex
OLOOP1 EQU 0xE0 ; Initial loop value for fine control 128
ILOOP1 EQU 0xE0 ; Initial loop value for coarse control 27H
; Registers for program varialbles
OUTERL EQU 0x10 ; Fine control delay value register
INNERL EQU 0x11 ; Coarse control delay value register
STORE EQU 0x12 ; Temporary register
OLOOP EQU 0x13 ; Fine control delay count register
ILOOP EQU 0x14 ; Coarse control delay count register
WREG EQU 0x16 ; Stores W reg during interrupt
SREG EQU 0x17 ; Stores STATUS reg during interrupt
; Reset
ORG 0x00 ; Power up and reset code start
GOTO Setup ; Skip over interrupt routine
; Interrupt subroutine
ORG 0x04
; Store STATUS and W Registers in temporary locations
MOVWF WREG
SWAPF STATUS,W ; Does not affect STATUS bits
MOVWF SREG
; Use PORTA bit 1 to signal interrupt
BSF PORTA,1
;Display
MOVF STORE,0 ; Move STORE to W
MOVWF PORTB ; Display TMR0 value on PORTB1-7
; Clear Interrupts and flags
CALL Intclr ; Clear interrupts and reset prescalar values
; Retore STATUS and W Registers from temporary locations
SWAPF SREG,W ; Does not affect STATUS bits
MOVWF STATUS
SWAPF WREG,F
SWAPF WREG,W
RETFIE ; Clears GIE bit in INTCON
Setup
; Set up Ports
BSF STATUS,5 ; Switch to BANK1
MOVLW 0x00 ; Move 00000000 to W
MOVWF TRISA ; Set outputs RA0=PWM RA2=TMR0 RA3=Interrupt
MOVLW 0x01 ; Move 00000001 to W
MOVWF TRISB ; Set RB0 input, RB1--8 as outputs
BSF STATUS,5 ; Switch to Bank1
; Set up option register
; BSF OPTREG,7 ; Enable PORTB pull ups
BSF OPTREG,6 ; Enable INTEDG, trigger RBO/INT on rising edge
BCF OPTREG,3 ; Assign Prescaler to TMR0
BSF OPTREG,2 ; Set prescalar to 1:256
BSF OPTREG,1 ; Set prescalar to 1:256
BSF OPTREG,0 ; Set prescalar to 1:256
BCF STATUS,5 ; Switch to Bank0
; Clear ports and flag register
CLRF PORTA
CLRF PORTB
; CLRF FLAG
; Initialise loop values
MOVLW ILOOP1
MOVWF INNERL ; Initialise inner loop
MOVLW OLOOP1
MOVWF OUTERL ; Initialise outer loop
; Clear interrupts
CALL Intclr
BCF INTREG,5 ; Disable TOIE in INTCON
BSF INTREG,4 ; Enable INTE in INTCON
BSF INTREG,7 ; Enable GIE in INTCON
; Main Program
Main
BSF PORTA,0 ; PWM high clcle
CALL Delay ; PWM high clcle
BCF PORTA,0 ; PWM low cycle
CALL Delay ; PWM low cycle
GOTO Main ; PWM high until interrupt on RB0
; Subroutines
Intclr
; Clear and enable interrupts
; Set bit 4 to enable INTE RB0/INT,
; Clear all other bits
BCF INTREG,0 ; Clear RBO INT flag
BCF INTREG,1 ; Clear RBO INT flag
BCF INTREG,2 ; Clear TOIF flag
;Reset prescalar values in option register
BSF STATUS,5 ; Switch to Bank1
BSF OPTREG,6 ; Enable INTEDG, trigger RBO/INT on rising edge
BCF OPTREG,3 ; Assign Prescaler to TMR0
BSF OPTREG,2 ; Set prescalar to 1:256
BSF OPTREG,1 ; Set prescalar to 1:256
BSF OPTREG,0 ; Set prescalar to 1:256
BCF STATUS,5 ; Switch to Bank0
RETURN
Delay
; Delay subroutine to keep PWM pulse low
; Total number instructions (4+((Outer*5)=1)+(Inner*3)+1))
MOVF OUTERL,0 ; Copy Outer loop value to W
MOVWF OLOOP ; Copy Outer loop value to loop count register
Outer
MOVF INNERL,0 ; Copy Inner loop value to W
MOVWF ILOOP ; Copy Inner loop value to loop count register
Inner
DECFSZ ILOOP,1
GOTO Inner
DECFSZ OLOOP,1
GOTO Outer
RETURN
; End of subroutines
END ; directive 'end of program'
Bookmarks