De acuerdo con la descripción del conjunto de instrucciones, "xorwf myLiteral" debe combinar el contenido de "w" con "myLiteral" y, si ambos son iguales, se debe establecer el indicador Z en ESTADO (no me interesa dónde esta instrucción guarda el resultado, pero el indicador Z debe verse afectado si ambos los valores eran los mismos)
Pero en mi código esto no está sucediendo.
movf PORTC
xorwf red_on ;w holds 01000100 and red_on is also 01000100 Z must be one
btfsc STATUS, Z ;but here it's not one
goto Turn_Yellow_On
El código completo es el siguiente:
; PIC16F72 Configuration Bit Settings
; Assembly source line config statements
#include "p16f72.inc"
; CONFIG
; __config 0xFFF7
__CONFIG _FOSC_RC & _WDTE_ON & _PWRTE_ON & _CP_OFF & _BOREN_ON
STATUS equ 0x03
TRISC equ 0x87
PORTC equ 0x07
INTCON equ 0x0b
RP0 equ 5
RP1 equ 6
Z equ 2
GIE equ 7
INTE equ 4
INTF equ 1
all_off equ 0x00
red_on equ 0x44
yellow_on equ 0x22
green_on equ 0x11
bank0 macro
bcf STATUS, RP0
bcf STATUS, RP1
endm
bank1 macro
bsf STATUS, RP0
bcf STATUS, RP1
endm
extrn_int_enable macro
bsf INTCON, GIE
bsf INTCON, INTE
endm
PORTC_as_out macro
bank1
movlw 0x00
movwf TRISC
endm
PORTC_out macro outByte
bank0
movlw outByte
movwf PORTC
endm
test_and_switch macro testWith, jumpTo
movf PORTC
xorwf testWith
btfsc STATUS, Z
goto jumpTo
endm
org 0x00
Reset_Vector:
goto Main
org 0x04
Interrupt_Vector:
goto Switch_Next
org 0x05
Main:
PORTC_as_out
extrn_int_enable
Loop:
clrwdt
goto Loop
org 0x200
Switch_Next:
bcf INTCON, INTF
;test_and_switch all_off, Turn_Red_On
movf PORTC ;I recognized the mistake I should use d = 0 but data
;will still be copied in w when program goes to "Turn_Red_On" routine for
;the first time
xorwf all_off
btfsc STATUS, Z
goto Turn_Red_On
;test_and_switch red_on, Turn_Yellow_On
movf PORTC
xorwf red_on ;w holds 01000100 and red_on is also 01000100 Z must be one
btfsc STATUS, Z ;but here it's not one
goto Turn_Yellow_On
;test_and_switch yellow_on, Turn_Green_On
movf PORTC
xorwf yellow_on
btfsc STATUS, Z
goto Turn_Green_On
goto Turn_All_Off
Turn_Red_On:
PORTC_out red_on
goto Return_From_Int
Turn_Yellow_On:
PORTC_out yellow_on
goto Return_From_Int
Turn_Green_On:
PORTC_out green_on
goto Return_From_Int
Turn_All_Off:
PORTC_out all_off
goto Return_From_Int
Return_From_Int:
retfie
end
Su instrucción movf PORTC no tiene destino.
El valor predeterminado es f, PORTC en este caso, por lo que no está poniendo el número en el registro w.
Cámbielo a movf PORTC, w
Y siempre debe indicarlo explícitamente para evitar problemas. Ejecutar una simulación probablemente habría detectado esto, y vale la pena aprender a hacerlo.
Editar: Además, está usando xorwf (ex-o el registro w con un registro de archivo), cuando debería usar xorlw (ex-o un literal con el registro w).
xorwf toma el operando como una dirección y xor es el registro w con el contenido del registro en esa ubicación (0x44, en los 96 bytes de los registros de propósito general), que no es lo que desea.
ALI danés
Spehro Pefhany
ALI danés