Serin serout problem


Closed Thread
Results 1 to 40 of 337

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I finally found where the problem lies but dont know how to fix it. The led blinks but after 4-5 blinks, with the subroutine , it stops. If I dont put a subroutine it keeps on blinking. here is my program.
    thanks

    INCLUDE "modedefs.bas"
    @ DEVICE PIC16F88 , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7

    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    ADCON1 = %00100010 ' Set PORTA analog and RIGHT justify result, ADCON1 = %10000010 for 10 bit
    ADCON0 = %10010010
    TRISA = %11111111 ' Set PORTA to all input
    TRISB = %10000000
    input1 var byte
    loop:

    ADCIN 6, input1
    pause 30

    if input1 > 255 then
    portb.3 =0
    else
    goto blinker
    endif
    goto loop

    Blinker:
    portb.3 =1 ' Turn on LED connected to PORTB.6
    Pause 500 ' Delay for .5 seconds
    portb.3 =0 ' Turn off LED connected to PORTB.4
    Pause 500 ' Delay for .5 seconds
    return

    end
    Last edited by lerameur; - 4th February 2007 at 02:20.

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


    Did you find this post helpful? Yes | No

    Default What is the value of input 1?

    Quote Originally Posted by lerameur View Post
    I finally found where the problem lies but dont know how to fix it. The led blinks but after 4-5 blinks, with the subroutine , it stops. If I dont put a subroutine it keeps on blinking. here is my program.
    thanks

    INCLUDE "modedefs.bas"
    @ DEVICE PIC16F88 , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7

    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    ADCON1 = %00100010 ' Set PORTA analog and RIGHT justify result, ADCON1 = %10000010 for 10 bit
    ADCON0 = %10010010
    TRISA = %11111111 ' Set PORTA to all input
    TRISB = %10000000
    input1 var byte
    loop:

    ADCIN 6, input1
    pause 30

    if input1 > 255 then
    portb.3 =0
    else
    goto blinker
    endif
    goto loop

    Blinker:
    portb.3 =1 ' Turn on LED connected to PORTB.6
    Pause 500 ' Delay for .5 seconds
    portb.3 =0 ' Turn off LED connected to PORTB.4
    Pause 500 ' Delay for .5 seconds
    return

    end
    Hi leramuer,
    do you know the numerical value of input1 ?
    Maybe the code is doing exactly what you asked it to do.
    if input1 is greater than 255 shut off LED, if code is less then goto blinker,

    maybe add in a debug and check value of input 1 as far as pic understands value.

    edit: your comments in the blinker sub tripped me up, thought it was switching two different ports.
    edit2: input var byte
    if input > 255 then . . . 255 that's all a byte will hold . . . correct?
    should not you select a number that is smaller?
    Last edited by Archangel; - 4th February 2007 at 04:39.
    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.

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    The comments are irrelevant for the ports in this case.
    It blinks a few times then stps, thats why I dont understand. I will need to solder some wires and hook up a lcd to see what is happening.

    ken

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


    Did you find this post helpful? Yes | No

    Default

    Here we observe a nice stack UNDERflow example...

    Change your GOTO Blinker to GOSUB Blinker

    OR change your RETURN FOR A GOTO Loop
    Last edited by mister_e; - 4th February 2007 at 18:57.
    Steve

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

  5. #5
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    yes thats, I knew it was software , could not get my finger on it. Thanks, it works.

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


    Did you find this post helpful? Yes | No

    Default

    Good!
    Something to remind: Always be careful when mixing Gosub, Goto and Return together

    Joe S. ... i'm a bit disapointed
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default Huh?

    Quote Originally Posted by mister_e View Post
    Joe S. ... i'm a bit disapointed
    what did I do?
    Edit:
    Ohhh I see, I missed his using a goto instead of gosub.
    You know why I missed this, because I never tried to run his code in hardware, so I never copied it to PBP compiler. I got lazy. Sorry
    Last edited by Archangel; - 5th February 2007 at 02:42.
    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.

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  3. serout and serin problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th April 2006, 19:44
  4. Replies: 11
    Last Post: - 13th July 2005, 19:26
  5. SerIn and SerOut
    By Dwayne in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 21st July 2004, 15:54

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