Assembler: Matrix Multimedia ASM - IDE
I've been trying to use the INFSZ command in a loop but find it causes the PIC to demonistrate unusual behaviour, particularly when values are sent to PORTB.
The program will work when run in RC mode at around 100hz but behaves oddly XT mode.
The program below shows this and I wondered if anyone has seen this problem; also am I doing something wrong?
The program sets all bits on PORTB as outputs then clears the port. It then lights LEDS connected to RB7 + RB6 to show the start of the program.
Next it loads an initial value into the variable COUNT via register w.
The program then begins to loop until COUNT overflows.
PORTB is cleared and LEDS on RB0 and RB1 are illuminated to show the end of the program.
The problems that occur are:
Any LEDS illuminated before INCFSZ (ie RB6 and RB7) cannot be switched off. ie RB6 and RB7 are not cleared by CLRF.
If the initial value for COUNT is set to H'F0' then the LEDS are particially turnned off.
Code: Select all
; The following line embeds configuration data into the PICmicro
__CONFIG H'3FF9' ; XT mode
; __CONFIG H'3FFB' ; RC mode
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include "C:\PROGRA~1\MPLAB\P16F84a.INC"
COUNT EQU H'21'
; Program Start:
ORG 0
GOTO 005
NOP
NOP
NOP
NOP
BSF STATUS,5 ;BANK1
CLRF TRISB ;SET-UP PORTB AS OUTPUTS
BCF STATUS,5 ;BANK0
CLRF PORTB ;CLEAR PORTB (LEDS OFF)
BSF PORTB,6 ;LIGHT RB6
BSF PORTB,7 ;LIGHT RB7
MOVLW H'0' ;PREPARE INITIAL VALUE FOR COUNT
MOVWF COUNT ;LOAD COUNT WITH INITIAL VALUE
NEXT INCFSZ COUNT,1 ;INCREMENNT COUNT UNTIL OVERFLOW
GOTO NEXT ;LOOP
GOTO FINISH ;WHEN OVERFLOW OCCURS GOTO FINISH
FINISH CLRF PORTB ;CLEAR PORTB (ALL LEDS OFF)
BSF PORTB,0 ;LIGHT RB0 to show program finished
BSF PORTB,1 ;LIGHT RB1
END
EXAMPLE 2
In the second example the value of COUNT is sent to PORTB so changes can be monitored when run in RC mode at 100Hz. Again every thing appears OK but when run in XT mode (4Mhz crystal) the LEDS remain on after exiting the loop when in fact they should be off as a result of the CLRF COUNT command.
I have run the program on the Matrixmultimedia v2 Development Board and on a prototype board using different 16F84a chips but still get the same problem. It also occurs when using DECFSZ.
Code: Select all
; The following line embeds configuration data into the PICmicro
__CONFIG H'3FF9' ; xt mode
; __CONFIG H'3FFB' ; RC mode
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include "C:\PROGRA~1\MPLAB\P16F84a.INC"
radix hex
COUNT EQU H'21'
DELAY EQU H'22'
; Program Start:
ORG 0 ;Reset vector
GOTO 5 ;Goto start of program
ORG 4 ;Interrupt vector
GOTO 5 ;Goto start of program
ORG 5 ;Start of program memory
BSF STATUS,5 ;bank1
bcf OPTION_REG, 7 ;enable PORTB pullup resistors
MOVLW 0
MOVWF TRISB ;set-up PORTB as outputs
BCF STATUS,5 ;bank0
CLRF PORTB ;clear PORTB (LEDS off)
CLRF COUNT ;set COUNT= = 0
LOOP INCFSZ COUNT,1 ;increment COUNT until overflow
GOTO NEXT
GOTO FINISH
NEXT MOVF COUNT,0 ;copy COUNT to w
MOVWF PORTB ;show value of COUNT on PORTB using w
GOTO LOOP ;continue in loop
FINISH CLRF PORTB ;after exiting loop clear PORtB (ALL LEDS off)
BSF PORTB,0 ;light RB0 to show program finished
END