Input?


Closed Thread
Results 1 to 3 of 3

Thread: Input?

Hybrid View

  1. #1
    Join Date
    May 2006
    Posts
    19

    Default Input?

    I'm new to PIC programming and i have a question
    I want to know how to get an input on an 16f688
    i want to switch on a led if some port is high and turn it of again when it's low, but i can't get it done

    this is the code i use but it doesn't work yet

    <code>Led Var PORTC.1
    Sensor var PORTC.2

    high Led
    pause 5000
    low led
    input Sensor
    loop: if sensor = 1 then
    high led
    else
    low led
    endif
    pause 500
    goto loop
    end</code>

    I previously programmed BASIC stamps so i have some programing experience.

    Thanks in advance:

    Chris

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


    Did you find this post helpful? Yes | No

    Default

    You're 99% of the way there... here's an amendment that should get you all the way...

    Led Var PORTC.1
    Sensor var PORTC.2

    TRISC=%00000100

    high Led
    pause 5000
    low led
    loop:
    if sensor = 1 then
    high led
    else
    low led
    endif
    goto loop
    end

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    On the PIC16F688 RC1 & RC2 (and others - see datasheet) are A/D inputs by
    default on power-up. Add this to the first section of your code;

    ANSEL = 0

    That will allow use of these pins as digital.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Sony LanC Program
    By l_gaminde in forum Code Examples
    Replies: 2
    Last Post: - 25th September 2009, 18:51
  2. problem with input and output (18F452)
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th March 2008, 23:21
  3. LED "capacitance" won't get lower
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 3rd May 2007, 20:31
  4. 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
  5. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19

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