I thought it was like riding a bike... Help please! 16f630 config


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    76

    Default I thought it was like riding a bike... Help please! 16f630 config

    I'm trying to write a very simple program but can't get off the ground. I don't read data sheets very well though I have spent hours trying. Much of it simply goes over my head. I feel sure that I'm not setting the chip up properly for digital I/O. Once I get the settings right I think I'm off and running. I've been very successful before with this but it has been a while and this is a new chip for me.

    The code below is intended to turn on LEDs and leave them on. What happens is that the first LED turns on, then goes OFF as the second LED turns on. Then the second LED turns off as the third turns on. It then stays on as the next two turn on and stay on (as I expect it to). So the end result is the first two LEDS are off and the last three are on.

    I suspect that PortA is not configured correctly. Can someone please help me.

    Thank you!!!

    Ross



    @_config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF
    ANSEL = 0
    CMCON = 7
    ADCON1 = 7
    TRISA = %111000
    TRISC = %111000
    porta = 0
    portc = 0

    Push var porta.4
    '************************************************* ******************************
    Start: while Push = 1 ' Wait for button push
    wend



    Run: High porta.0 ' Turn on LED on each port every two seconds
    Pause 2000
    High porta.1
    Pause 2000
    high porta.2
    pause 2000
    high portc.0
    pause 2000
    high portc.1

    End
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  2. #2
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: I thought it was like riding a bike... Help please! 16f630 config

    Shouldn't it be ADCON0=0? This will turn the comparators off. ADCON1=7 doesn't do anything.

    What I see is that none of your LEDs will turn off.

    If you want LED 1 on wait two seconds then off, then the same for LED 2, then LED 3 on stay on, LED 4 on stay on, then pause and all off it should look like:

    (Just the main program)

    RUN:
    high porta.1 ' led 1 on
    pause 2000
    low porta.1 'led 1 off
    pause 2000
    high porta.2 'led 2 on
    pause 2000
    low porta.2 'led2 off
    pause 2000
    high portc.0 'led3 on
    pause 2000
    high portc.1 'led4 on
    pause 2000
    low portc 'led3 and led4 off
    end

    Is this getting to more of what you want?
    There are more elegant ways to do this but this is the simplest to read.
    Last edited by AvionicsMaster1; - 9th February 2012 at 15:40. Reason: more clarification of adcon

  3. #3
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    76


    Did you find this post helpful? Yes | No

    Default Re: I thought it was like riding a bike... Help please! 16f630 config

    Hi,

    Thank you for your response!

    I want all of the LED's to stay ON. But the first two turn off. I don't understand why. I suspect I need to do something to PORTA that I have not done. PORTC is working fine.

    Thoughts?

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  4. #4
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    76


    Did you find this post helpful? Yes | No

    Default Re: I thought it was like riding a bike... Help please! 16f630 config

    I got it working. Here's the code I used:

    CMCON = 7
    TRISA = %111000
    TRISC = %111000
    porta = 0
    portc = 0

    Push var porta.4
    '************************************************* ***************
    Start: while Push = 1 ' Wait for button push
    wend



    Run: High porta.0 ' Turn on LED and leave it on
    Pause 2000
    High porta.1 ' Turn on LED and leave it on
    Pause 2000
    high porta.2 ' Turn on LED and leave it on
    pause 2000
    high portc.0 ' Turn on LED and leave it on
    pause 2000
    high portc.1 ' Turn on LED and leave it on

    End

    I thought I also had to set ANSEL but Microcode Studio balks at me for it. :-P I'm trying!

    Thank you!

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: I thought it was like riding a bike... Help please! 16f630 config

    Quote Originally Posted by rossfree View Post
    I thought I also had to set ANSEL but Microcode Studio balks at me for it. :-P I'm trying!
    The PIC16F630 has no ADC, so no analog selections are available. That's why it was balking at you.
    http://www.scalerobotics.com

Members who have read this thread : 1

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