Input not working with PIC12F675


Closed Thread
Results 1 to 5 of 5
  1. #1
    Henque19's Avatar
    Henque19 Guest

    Exclamation Input not working with PIC12F675

    I'm trying to get the hang of PIC programming, so I made a really simple circuit with two leds on port 1 and 2, and a switch on port 0 (connected so that pin 0 is high when the switch is open. The pin is connected to the positive terminal via a 10k resistor, and to ground via the switch).

    The code segment I use is:
    c VAR BYTE
    ...
    c = PORTA
    IF c.0 = 0 Then loop2

    What have I done wrong? I have also tried the button command, and using pin 4 instead, still not working. Please help me!

    Thanks
    /Henrik

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    > What have I done wrong?

    Well, lets start by looking at the DATSHEET for the 12F675...

    ...there you will discover it hasn't got a PORTA, so...

    c = PORTA

    ...isn't a valid statement.

    Read the DATASHEET, find out what it's supposed to be, and try again... also don't forget (a) your TRIS statement, and (b) doublecheck to see if you need to turn off any any analogue functions on multiplexed pins...

  3. #3
    Henque19's Avatar
    Henque19 Guest


    Did you find this post helpful? Yes | No

    Default

    But I can use porta with outputs.

    PORTA = 2
    Pause 400
    PORTA = 4
    Pause 400

    This makes the two leds turn on and off alternatively.

    So if the pic doesnt have porta, why does this work?

    I have defined pin 0 as input and pin 1 and 2 as outputs.

    Input PORTA.0
    Output PORTA.1
    Output PORTA.2

    And I'm a high school student, I don't have a degree in engineering, so I don't have a clue what the datasheet says.

    Can you please explain that about disableing analogue functions on multiplexed pins?

    Thanks again
    /Henrik

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Why PORTA work?... O.K Let's open and look one section of the PBPPIC14.lib file located in the PBP folder.
    Code:
    .......
    ;****************************************************************
    ;* Fake PORT settings for 12C67x, 14C000                        *
    ;****************************************************************
    
        ifndef PORTA
    PORTA EQU 5
        endif
    ........
    AND now if we open the 12F675 datasheet section 2.2.2 and we look the figure 2-2 on the left colums, we discover that GPIO is located @ 05H.... In the above snip, they create an alias to GPIO.

    The usual way to write a program, is to use the correct name of the port... wich, in your case, is GPIO. your code will look like
    Code:
    GPIO = 2
    Pause 400
    GPIO = 4
    Pause 400
    --------------------------------------------------------------------------
    I have defined pin 0 as input and pin 1 and 2 as outputs.

    Input PORTA.0
    Output PORTA.1
    Output PORTA.2
    It's one way to do it. You use the PBP function. You can also use the TRISIO register to do that... look section 3.0. your code will look
    Code:
    TRISIO.0=1 ' GPIO.0 As input
    TRISIO.1=0 ' GPIO.1 As output
    TRISIO.2=0 ' GPIO.2 As output
    OR in one line
    Code:
    TRISIO=%111001 ' GPIO<2:1> as output, all the other as input
    --------------------------------------------------------------------------
    Can you please explain that about disableing analogue functions on multiplexed pins?
    Look in section 6 and section 7. you'll discover the setting to use in CMCON and ANSEL register.
    CMCON=%00000111
    ANSEL=0

    Now go in the FAQ and read the following thread wich discuss on HOW TO SET the PIC configuration fuses => http://www.picbasic.co.uk/forum/showthread.php?t=543

    Do a search in this forum with 12F675 and you'll probably found some good example.

    A really simple example here.
    Code:
        '
        '    Hardware configuration
        '    ======================
             @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
                 ' Internal Oscillator
                 ' Disable watch dog timer
                 ' Enable power up timer
                 ' Disable MCLR function but leave this pin available as input
                 ' Enable brown out detect
        
             CMCON = %00000111 ' Disable analog comparator
             ANSEL = 0         ' Disable A/D converter
             TRISIO = %111001  ' Set GPIO<2:1> as output, the other as input
    
        '                      
        '    Hardware connection
        '    ===================
             SWITCH             VAR GPIO.0 
             LED1               VAR GPIO.1
             LED2               var GPIO.2
             
        '
        '    ////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\        
        '
        '                             Program Start Here                               
        '
        '    ////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\        
        '    
    START:
        IF SWITCH=1 THEN
           LED1=1
           LED2=0
           ELSE
               LED2=1          
               LED1=0
           ENDIF
        GOTO START
    Last edited by mister_e; - 15th January 2006 at 10:33.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Henque19's Avatar
    Henque19 Guest


    Did you find this post helpful? Yes | No

    Default

    Its working!
    Thank you, you have given me a reason to live again

    /Henrik

Similar Threads

  1. Sony LanC Program
    By l_gaminde in forum Code Examples
    Replies: 2
    Last Post: - 25th September 2009, 18:51
  2. PIC12F675 not working
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th March 2009, 17:40
  3. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  4. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19
  5. PIC12F675 trouble
    By russman613 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th February 2006, 18:40

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