Hi
There's something wrong with my code here, I'm attempting toggle the outputs of RA0-3 between high and low in a certain sequence by looping through a data table and retrieving the corresponding values. Heres my code:
What I expect to see is this:
RA3 HIGH
RA1 HIGH
RA2 HIGH
RA0 HIGH
However RA2 is taking twice as long on high (being called twice?) and RA0 is never turning on.
Attached an oscilloscope output to help visualize what's going on.
Whats wrong with my code?
There's something wrong with my code here, I'm attempting toggle the outputs of RA0-3 between high and low in a certain sequence by looping through a data table and retrieving the corresponding values. Heres my code:
Code:
;====================================================================
; Main.asm file generated by New Project wizard
;
; Created: Sat Feb 15 2014
; Processor: PIC16F84A
; Compiler: MPASM (MPLAB)
;====================================================================
;====================================================================
; DEFINITIONS
;====================================================================
#include p16f84a.inc ; Include register definition file
;====================================================================
; VARIABLES
;====================================================================
;====================================================================
; RESET and INTERRUPT VECTORS
;====================================================================
; Reset Vector
RST code 0x0
goto Start
;====================================================================
; CODE SEGMENT
;====================================================================
PGM code
Start
STATUS equ 03h ;Address of the STATUS register
TRISA equ 85h ;Address of the tristate register for port A
PORTA equ 05h ;Address of Port A
COUNT1 equ 08h ;First counter for our delay loops
COUNT2 equ 09h ; for looping
COUNT3 equ 10h ; for looping
PC equ 02h ; program counter
bsf STATUS,5 ;Switch to Bank 1
movlw 00h ;Set the Port A pins
movwf TRISA ;to output.
bcf STATUS,5 ;Switch back to Bank 0
call GOCW
TABLE addwf PC
retlw 01h ;return binary 0001 RA0
retlw 04h ;0100 RA2
retlw 02h ;0010 RA1
retlw 08h ;1000 RA3
return
GOCW
movlw 04h ; put 4 in W
movwf COUNT3 ; move W to COUNT3, 4.
loop3
movf COUNT3, 0 ;move count3 to W
CALL TABLE
movwf PORTA ; set an output to high
call DELAY ; wait a while
decfsz COUNT3,1 ;sub 1 from count3 or end loop if count3 is 0
goto loop3
return
DELAY ;
;****Start of the delay loop 1****
movlw 80h
movwf COUNT2
Loop1 decfsz COUNT1,1 ;Subtract 1 from 255
goto Loop1 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 255
goto Loop1 ;Go back to the start of our loop. ;This delay counts down from ;255 to zero, 255 times
return ;end delay subroutine
;====================================================================
END
What I expect to see is this:
RA3 HIGH
RA1 HIGH
RA2 HIGH
RA0 HIGH
However RA2 is taking twice as long on high (being called twice?) and RA0 is never turning on.
Attached an oscilloscope output to help visualize what's going on.
Whats wrong with my code?