I still can't read momentary push buttons on GPIO.0 and GPIO.3. I simplified the code. I think (and could be wrong) that PBP sets the TRISIO bits depending on if the High or Low is used or if the pin is used in an If statement.
Here is the simplified code that doesn't work yet.
' PIC12F683 SOIC-8 Pin Assignments:
' Pin 1 Vdd +3.8V Power, Battery Voltage +2.5 - 4.5V
' Pin 2 GP5 Out GreenLED Driven by 2N2222, High = LED ON
' Pin 3, GP4 Out RedLED Drivven by 2N2222, High = LED ON
' Pin 4 GP3 In Switch (S1), Low = Pressed
' Pin 5, GP2 N/C
' Pin 6, GP1 N/C
' Pin 7, GP0 In Switch (S2), Low = Pressed
' Pin 8, Vss Supply Ground
'
' Using INTRC Oscillator
INCLUDE "modedefs.bas" ' Mode definitions for Serout
DEFINE OSC 4
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _CP_OFF
INTCON = %10001000 'internal oscillator
OSCCON = %01100000 ' 4mHz
CMCON0 = 7 'Comparators off
GPIO = %00000000 'outputs low
'TRISIO = %00001111 'GP0-GP3 as input
TRISL = %1111
TRISH = %1111
'======== SET UP VARIABLES & INITIAL VALUES ====================================
GreenLED VAR GPIO.5 ' Alias Green LED Drive, High = LED ON, Pin 2 Green
RedLED VAR GPIO.4 ' Alias Red LED Drive, High= LED ON, Pin 3 Red
SwitchS1 VAR GPIO.0 ' Alias Switch S2, Low = Pressed, Pin 7
SwitchS2 VAR GPIO.2 ' Alias Switch S1, Low = Pressed, Pin 5
'Pin 4 is set for external MCLR and has a 5.9K pull up
N VAR BYTE ' Counting Variable, used in Auto-OFF Routine
Low GreenLED
Low RedLED
StartLoop:
Pause 10
If SwitchS1 = 0 Then
High GreenLED
ELSE
Low GreenLED
EndIf
PAUSE 10
If SwitchS2 = 0 Then
High RedLED
ELSE
Low RedLED
EndIf
PAUSE 1000
GoTo StartLoop ' Repeat
END
Bookmarks