Problem getting button to turn on LED using 12F675


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jun 2008
    Location
    Spokane, WA
    Posts
    9

    Default Problem getting button to turn on LED using 12F675

    Name:  button.png
Views: 1808
Size:  28.3 KB

    I have a noob question. i have been playing with this all night. Im using Microcode 3005 and PBP 2.46. Chip is 12F675. I have checked the usual...blinked the LED's using blink program as a test, and tested the button. All i get is: LED 1 stays on. Schematic is similar to the one above 'cept RC osc, different chip of course.

    Code:
        CMCON = $1F 
        CMCON = %00000111
        
        GPIO = %00000001                 ' Set GPIO 1 high to turn on LED1
        TRISIO = %00000010               ' set GPIO 4-1 to INputs, RA0 OUTput
    
    Main:
        '*** Test the switch state ***
        if GPIO.0 = 0 then led2 'If switch is pressed then jump to LED2 routine 
     
        GPIO.1 = 1            ' Turn LED1 on
        GPIO.2 = 0            ' Turn LED2 off
        goto Main              ' Jump to the top of the main loop
    
    LED2:
        '*** Turn LED2 on ***
        GPIO.2 = 1            ' LED2 on 
        GPIO.1 = 0            ' LED1 off
        goto Main               ' Jump to the top of the main loop
    Any hints on how to troubleshoot this? I don't really want it re-written for me because i am trying to learn but i may change my mind later. thanks.

  2. #2
    Join Date
    Jun 2008
    Location
    Spokane, WA
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Re: Problem getting button to turn on LED using 12F675

    I found a mistake, cmcon was the wrong address

    ADCON0 = $1F
    ADCON0 = %00000000 'TURN OFF CONVERTER

    CMCON = $19 'MAKE PINS DIGITAL
    CMCON = %00000111

    GPIO = %00000001 ' Set GPIO 1 high to turn on LED1
    TRISIO = %00000110 ' set GPIO 1 & 2 to INputs, GPIO 0 OUTput

    Main:
    '*** Test the switch state ***
    if GPIO.0 = 0 then led2 'If switch is pressed then jump to LED2 routine

    GPIO.1 = 1 ' Turn LED1 on
    GPIO.2 = 0 ' Turn LED2 off
    goto Main ' Jump to the top of the main loop

    LED2:
    '*** Turn LED2 on ***
    GPIO.2 = 1 ' LED2 on
    GPIO.1 = 0 ' LED1 off
    goto Main ' Jump to the top of the main loop

  3. #3
    Join Date
    Jun 2008
    Location
    Spokane, WA
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Re: Problem getting button to turn on LED using 12F675

    Still doesnt work though. BTW, how do i edit my post??

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Problem getting button to turn on LED using 12F675

    Check the pins to make sure you have them set up as digital and not analog inputs.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Problem getting button to turn on LED using 12F675

    ANSEL turns the ADC on or off on the 12F675.

    Use this to disable all ADC
    ANSEL=%00000000
    CMCON=7
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jun 2008
    Location
    Spokane, WA
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Re: Problem getting button to turn on LED using 12F675

    Thanks guys, you were both right; rookie mistaek on my part. It works now - onward and upward. Now the button turns on LED2 and off LED1. SWEET!

    ANSEL = $9F 'FIRST FOUR BITS MAKE IT DIGITAL INPUT
    ANSEL = %00000000

    ADCON0 = $1F
    ADCON0 = %00000000 'TURN OFF CONVERTER

    CMCON = $19 'MAKE PINS DIGITAL
    CMCON = %00000111


    GPIO = %00000010 ' Set GPIO 1 high to turn on LED1
    TRISIO = %00000001 ' set GPIO 1 & 2 to INputs, GPIO 0 OUTput

    Main:
    '*** Test the switch state ***
    if GPIO.0 = 0 then led2 'If switch is pressed then jump to LED2 routine

    GPIO.1 = 1 ' Turn LED1 on
    GPIO.2 = 0 ' Turn LED2 off
    goto Main ' Jump to the top of the main loop

    LED2:
    '*** Turn LED2 on ***
    GPIO.2 = 1 ' LED2 on
    GPIO.1 = 0 ' LED1 off
    goto Main ' Jump to the top of the main loop

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Problem getting button to turn on LED using 12F675

    Quote Originally Posted by Jeff View Post
    Thanks guys, you were both right; rookie mistake on my part. It works now - onward and upward. Now the button turns on LED2 and off LED1. SWEET!
    Welcome back Jeff,
    3 years almost. I think what trips up people is this statement,
    CMCON = $?? 'MAKE PINS DIGITAL
    Which seems to reappear on a regular basis, perhaps copy paste, it should more factually report,
    CMCON = $?? 'Disable input Comparators
    The ANSEL is the 'MAKE PINS DIGITAL part of the equation, as you found out, My post here is for the future newbies who read this post.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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