In this program I want to get input from GPIO2 using a momentary switch. I can get input from pin 4 which is GPIO 3 but I want to get input from both. I'm been trying to tackle this for awhile and I feel I could use a couple tips. I pasted the code below and look at the code portion where I call State3 and my condition is that GPIO2 is set high in order for that function to be called.
Rich (BB code):
list p=12f629 ; list directive to define processor
#include <p12f629.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The labels following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
;************************** VARIABLE DEFINITIONS ******************************
cblock 0x20
STATE_LED ; LED state machine counter
STATE_DEBOUNCE ; button debounce state machine counter
endc
;*************************** DEFINE STATEMENTS ********************************
; input and output definitions
#define SW1 GPIO,3 ; toggle switch 1
#define SW2 GPIO,2 ; toggle switch 2
; define input/output designation for LEDs (what TRISIO will equal)
#define TRIS_D0_D1 B'00001111' ; TRISIO setting for D0 and D1
#define TRIS_D2_D3 B'00101011' ; TRISIO setting for D2 and D3
#define TRIS_D4_D5 B'00011011' ; TRISIO setting for D4 and D5
#define TRIS_D6_D7 B'00111001' ; TRISIO setting for D6 and D7
#define allInputs B'00111111' ; TRISIO setting D0-D7 as inputs
; define LED state (what GPIO will equal)
#define D0_ON B'00010000' ; D0 LED
#define D1_ON B'00100000' ; D1 LED
#define D2_ON B'00010000' ; D2 LED
#define D3_ON B'00000100' ; D3 LED
#define D4_ON B'00100000' ; D4 LED
#define D5_ON B'00000100' ; D5 LED
#define D6_ON B'00000100' ; D6 LED
#define D7_ON B'00000010' ; D7 LED
#define Blank B'00000000' ; All LEDs off
;****************************** Start of Program ******************************
org 0x000 ; processor reset vector
goto Initialize
;******************************************************************************
; Initialize
; Initialize Special Function Registers
;******************************************************************************
org 0x005 ; Start of Programm Memory Vector
Initialize
;call 0x3FF ; retrieve factory calibration value
; comment instruction if using simulator, ICD2, or ICE2000
bsf STATUS,RP0 ; Bank 1
movwf OSCCAL ; update register with factory cal
; value
movlw B'00111111' ; Set all I/O pins as inputs
movwf TRISIO
movlw B'10000100' ; Weak pullups: disabled
movwf OPTION_REG ; TMR0 prescaler: 1:32 (TMR0 will
; overflow in 8.2ms)
clrf INTCON ; disable all interrupts, clear all
; flags
bcf STATUS,RP0 ; Bank 0
clrf GPIO ; clear all outputs
clrf TMR0 ; clear Timer 0
clrf STATE_LED ; clear LED state machine counter
clrf STATE_DEBOUNCE ; clear debounce state machine counter
;******************************************************************************
; State_Machine
; Implements a state machine that lights up the LEDs on the PICkit board
; sequentially when SW1 is pressed.
;******************************************************************************
StateMachine
btfss SW1
call State0 ; mented by STATE_LED in order
btfss SW1
call State1
btfss SW1
call State2
btfss SW2
call State3
bsf STATUS, RP0 ; Bank 1
movlw allInputs ; make all inputs in TRISIO
movwf TRISIO
btfsc SW1
call Restart
goto StateMachine
Restart
bcf STATUS, RP0 ; Bank 0
movlw Blank ; move predefined value to GPIO
movwf GPIO
return
State0
; Turns on D0 LED
bsf STATUS, RP0 ; Bank 1
movlw TRIS_D0_D1 ; move predefined value to TRISIO
movwf TRISIO
bcf STATUS, RP0 ; Bank 0
movlw D0_ON ; move predefined value to GPIO
movwf GPIO
return
State1
; Turns on D1 LED
bsf STATUS, RP0 ; Bank 1
movlw TRIS_D0_D1 ; move predefined value to TRISIO
movwf TRISIO
bcf STATUS, RP0 ; Bank 0
movlw D1_ON ; move predefined value to GPIO
movwf GPIO
return
State2
; Turns on D2 LED
bsf STATUS, RP0 ; Bank 1
movlw TRIS_D2_D3 ; move predefined value to TRISIO
movwf TRISIO
bcf STATUS, RP0 ; Bank 0
movlw D2_ON ; move predefined value to GPIO
movwf GPIO
return
State3
; Turns on D3 LED
bsf STATUS, RP0 ; Bank 1
movlw TRIS_D2_D3 ; move predefined value to TRISIO
movwf TRISIO
bcf STATUS, RP0 ; Bank 0
movlw D3_ON ; move predefined value to GPIO
movwf GPIO
return