TRISIO on PIC12F683, I have a bit stuck midway


Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Oct 2010
    Posts
    7

    Default TRISIO on PIC12F683, I have a bit stuck midway

    I'm having a hard time trying to figure out why I have pin 7 at 1.247 volts when it has a 10K pull up resistor to Vdd (3.86V). It is connected to a momentary switch. I have disconnected pin 7 from the switch and the switch goes to 3.8 volts with the pull up.

    It looks like I have pin 7 GPIO.0 set as an output.

    Overview: I have two LED's and two switches. Switch S2 works OK electrically. But S1 is stuck in mid voltage and never goes high. It goes to zero when I press it. Also, It is never read as low even when I press it or the other switch S2

    I can't figure out why this is happening.

    Here is the code:
    Code:
    ----------------------------------------------------------------------------------------------------------
    ' 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_OFF & _CP_OFF
        CMCON=7 
        
    INTCON = %10001000 'internal oscillator
    OSCCON = %01110000 ' 8mHz
    CMCON0 = 7 'Comparators off
    GPIO = %00000000 'outputs low
    TRISIO = %00001111 'GP0-GP3 as input
    
    
    
    
    '======== SET UP VARIABLES & INITIAL VALUES ====================================
    
    GreenLED    CON 5        ' Alias Green LED Drive, High = LED ON, Pin 2 Green
    RedLED         CON 4        ' Alias Red LED Drive, High= LED ON, Pin 3 Red
    SwitchS1    VAR GPIO.0        ' Alias Lip Switch, Low = Pressed, Pin 4 
    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
                
    N=0
    StartLoop:
    
    N=N+1
    High GreenLED
    Low RedLED
    
    PAUSE 1000
    
    If S1 = 0 Then N=0
    If S2 = 0 Then N=0
    
    
    Low GreenLED
    High RedLED
    
    PAUSE 1000
    
    If N=10 Then
        Low GreenLED
        Low RedLED
        NAP 7
    EndIF
    
    GoTo StartLoop        ' Repeat 
    
    END
    Last edited by ScaleRobotics; - 31st October 2010 at 20:04.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts