serin trouble with PIC16F877A


Closed Thread
Results 1 to 20 of 20
  1. #1

    Default serin trouble with PIC16F877A

    I am trying to build a two part system where I will have a MC on a self-acquire satellite dish, and another MC in a handheld unit joined by BT. (This also allows for BT control from a phone or other SPP device) I fried my LCD, so I changed my attack plan to work from a terminal for now. I am having trouble getting the menu system to react properly so I hooked up another BT module TX/RX reversed and opened another terminal. I can see the terminal sending out "1" or "2" but the chip is registering it as [00]. I figured this out by putting in a debug line to echo it back before continuing the loop. I'm sure it's probly some formatting issue, but I sure don't see my error......

    #CONFIG
    __config _FOSC_HS & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF & _CP_OFF
    #ENDCONFIG


    DEFINE OSC 12


    TX var PORTC.6
    RX var PORTC.7
    CNT var word
    cereal var word
    i var byte


    goto MainMenu


    CLR:
    For i = 0 to 30
    serout TX, 2, [10]
    next i
    return


    MainMenu:
    gosub CLR
    serout Tx, 2, ["******** MAIN MENU ********", 13, 10, 10]
    serout Tx, 2, [" 1. Start Homing Sequence", 13, 10]
    serout Tx, 2, [" 2. Manual JOG Mode", 13, 10]
    serout Tx, 2, [" 3. Auto-Acquire Satellite", 13, 10]
    serout Tx, 2, [" 4. Stow Dish for Travel", 13, 10, 10]
    serout Tx, 2, ["Enter Your Selection:", 13, 10]
    Serin RX, 2, cereal

    If cereal = "1" then goto HomeDish
    If cereal = "2" then goto JogMode
    If cereal = "3" then goto AutoAcquire
    If cereal = "4" then goto StowDish
    serout TX, 2, [cereal] 'For debugging only
    pause 500
    goto MainMenu


    HomeDish:
    gosub CLR
    serout Tx, 2, ["******** HOME DISH ********", 13, 10, 10]
    serout Tx, 2, [" 1. Start Homing Sequence", 13, 10, 10]
    serout Tx, 2, [" 2 Abort Homing", 13, 10, 10]
    serout Tx, 2, ["Enter Your Selection:", 13, 10]
    Serin RX, 2, cereal
    if cereal = "1" then goto StartHoming
    if cereal = "2" then goto MainMenu
    serout TX, 2, [cereal] 'For debugging only
    pause 500
    goto HomeDish


    JogMode:
    gosub CLR
    serout TX, 2, [" JOG MENU ", 13, 10, 10]
    serout TX, 2, ["*** UNDER CONSTRUCTION *** ", 13, 10]
    pause 3000
    goto MainMenu


    AutoAcquire:
    gosub CLR
    serout TX, 2, [" AUTO-ACQUIRE ", 13, 10, 10]
    serout TX, 2, ["*** UNDER CONSTRUCTION *** ", 13, 10]
    pause 3000
    goto MainMenu


    StowDish:
    gosub CLR
    serout TX, 2, [" STOW DISH ", 13, 10, 10]
    serout TX, 2, ["*** UNDER CONSTRUCTION *** ", 13, 10]
    pause 3000
    goto MainMenu


    StartHoming:
    gosub CLR
    serout TX, 2, [" Begin Homing, Homie ", 13, 10, 10]
    serout TX, 2, ["*** UNDER CONSTRUCTION *** ", 13, 10]
    pause 3000
    goto MainMenu

  2. #2
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    Move the pause statement

    Code:
     MainMenu:
     gosub CLR
     serout Tx, 2, ["******** MAIN MENU ********", 13, 10, 10]
     serout Tx, 2, [" 1. Start Homing Sequence", 13, 10]
     serout Tx, 2, [" 2. Manual JOG Mode", 13, 10]
     serout Tx, 2, [" 3. Auto-Acquire Satellite", 13, 10]
     serout Tx, 2, [" 4. Stow Dish for Travel", 13, 10, 10]
     serout Tx, 2, ["Enter Your Selection:", 13, 10]
     Serin RX, 2, cereal
    
     If cereal = "1" then goto HomeDish 
     If cereal = "2" then goto JogMode
     If cereal = "3" then goto AutoAcquire
     If cereal = "4" then goto StowDish
     serout TX, 2, [cereal] 'For debugging only
     pause 500
     goto MainMenu
    to before the serin statement. Also with serial communication I always use timeouts and qualifiers where I can.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    OK, I put a pause 500 in front of the serin command with no change. Two questons... 1.Why did you think that would work? (Not being smart here, I assume you had logical reasoning or experience that might be of some use someday) 2. Can I use multiple qualifiers? Like if I want to reject everything except 1 2 3 or 4?? thanks!

  4. #4
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    Quote Originally Posted by thasatelliteguy View Post
    OK, I put a pause 500 in front of the serin command with no change. Two questons... 1.Why did you think that would work? (Not being smart here, I assume you had logical reasoning or experience that might be of some use someday) 2. Can I use multiple qualifiers? Like if I want to reject everything except 1 2 3 or 4?? thanks!
    You have made my day

  5. #5
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    You have a loop that is constantly being executed except for the 500 pause. You Tx then instantly Rx with no time for a response to be sent.

    Well that was my thinking but obviously there is more to it than I first thought.

    try

    Serin RX, 2, 500,MainMenu,cereal

    serin will wait 500 msecs waiting for data to come in. cereal you have as a word it only needs to be a byte.

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    serout Tx, 2, [" 3. Auto-Acquire Satellite", 13, 10]
    serout Tx, 2, [" 4. Stow Dish for Travel", 13, 10, 10]
    serout Tx, 2, ["Enter Your Selection:", 13, 10]
    pause 500
    Serin RX, 2, 500, MainMenu, cereal

    If cereal = "1" then goto HomeDish
    If cereal = "2" then goto JogMenu
    If cereal = "3" then goto AutoAcquire
    If cereal = "4" then goto StowDish
    serout TX, 2, [cereal] 'For debugging only
    serout TX, 2, ["Dingleberry"]
    pause 1500
    goto MainMenu

    Now I can see the 500 passing as the Main Menu 'blinks' from being called over and over, but still no go. The above code still yields:
    [00]Dingleberry

    instead of 1Dingleberry

  7. #7
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    Let me get this correct

    you are sending 1 from the terminal?

    but receive nothing?

  8. #8
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    and you send the menu instructions and receive them on the terminal?

    Are you sure this is not a hardware issue? Wires not connected to correct pins or something like that.
    Last edited by EarlyBird2; - 23rd May 2014 at 11:43.

  9. #9
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    TRISC=%10000000 is missing to set portsc.7 as input.

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    I did the input thing both ways...TRISC.7 = 1 and TRISC=%10000000 - no change

    I have two HC-05's hooked up to the RX and TX ports. They are hooked up backwards from one another. So I see the menu show up on one terminal screen, and I see the echo of what I type(a mirror of what the MC is receiving) show up in the other terminal on my screen on a different BT-com port. The second BT (as well as the MC presumably) receives 1 or 2 or whatever I type. But the when the menus didnt respond, I added the SEROUT and 1500 pause (to read it) and underneath the menu it'll only output [00] everytime no matter what key I hit. Just to be certain I added the next line for a total of:
    serout TX, 2, [cereal]
    serout TX, 2, ["Dingleberry"]
    pause 1500
    and I get

    [00]Dingleberry

    then after 1.5 seonds, it dissappears and the Main Menu is reborn to await another keystroke.....

  11. #11
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    Serin RX, 2, 500, MainMenu, cereal

    This line goes to MainMenu if nothing is received after 500 ms therefore [00]Dingleberry will only be printed if something is received.

    What is going on?

    Can you send the whole code again please?

  12. #12


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    you are correct. However, when that didnt work, I removed it again. But when its there, it just cycles back (basically blinks) to the Main Menu unless you send a keystroke, in which case you get [00]Dingleberry.

    [00] is Null is it not? Is it possible somewhere in the serin process it's trying to take the char before or after my keystroke? I tried 11, and 23 tho and still returns [00] even though 11 and 23 showed on the receiving terminal. I even tried it with a wait command llike wait for "A" then take the next char. Still same thing. And that was straight from the PBP manual....

    #CONFIG
    __config _FOSC_HS & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF & _CP_OFF
    #ENDCONFIG

    TRISC=%10000000
    DEFINE OSC 12

    el var PORTD.7
    TRISD.7 = 0
    low el
    az var PORTB.5
    TRISB.5 = 0
    low az
    dir var PORTD.5
    TRISD.5 = 0
    low dir
    TX var PORTC.6
    TRISC.6 = 0
    RX var PORTC.7


    CNT var word
    cereal var byte
    i var byte


    goto MainMenu


    CLR:
    For i = 0 to 30
    serout TX, 2, [10]
    next i
    return


    MainMenu:
    gosub CLR
    serout Tx, 2, ["******** MAIN MENU ********", 13, 10, 10]
    serout Tx, 2, [" 1. Start Homing Sequence", 13, 10]
    serout Tx, 2, [" 2. Manual JOG Mode", 13, 10]
    serout Tx, 2, [" 3. Auto-Acquire Satellite", 13, 10]
    serout Tx, 2, [" 4. Stow Dish for Travel", 13, 10, 10]
    serout Tx, 2, ["Enter Your Selection:", 13, 10]
    pause 500
    Serin RX, 2, 500, MainMenu, cereal

    If cereal = "1" then goto HomeDish
    If cereal = "2" then goto JogMenu
    If cereal = "3" then goto AutoAcquire
    If cereal = "4" then goto StowDish
    serout TX, 2, [cereal] 'For debugging only
    serout TX, 2, ["Dingleberry"]
    pause 1500
    goto MainMenu


    HomeDish:
    gosub CLR
    serout Tx, 2, ["******** HOME DISH ********", 13, 10, 10]
    serout Tx, 2, [" 1. Start Homing Sequence", 13, 10, 10]
    serout Tx, 2, [" 2 Abort Homing", 13, 10, 10]
    serout Tx, 2, ["Enter Your Selection:", 13, 10]
    Serin RX, 2, cereal
    if cereal = "1" then goto StartHoming
    if cereal = "2" then goto MainMenu
    serout TX, 2, [cereal] 'For debugging only
    pause 500
    goto HomeDish


    JogMenu:
    gosub CLR
    serout TX, 2, [" JOG MENU ", 13, 10, 10]
    serout TX, 2, ["1. Elevation", 13, 10]
    serout tx, 2, ["2. Azimuth", 13, 10]
    serout tx, 2, ["3. Skew", 13, 10]
    serout tx, 2, ["4. Main Menu", 13, 10, 10]
    serout tx, 2, ["Enter Your Selection:"]
    serin RX, 2, cereal
    goto MainMenu


    AutoAcquire:
    gosub CLR
    serout TX, 2, [" AUTO-ACQUIRE ", 13, 10, 10]
    serout TX, 2, ["*** UNDER CONSTRUCTION *** ", 13, 10]
    pause 3000
    goto MainMenu


    StowDish:
    gosub CLR
    serout TX, 2, [" STOW DISH ", 13, 10, 10]
    serout TX, 2, ["*** UNDER CONSTRUCTION *** ", 13, 10]
    pause 3000
    goto MainMenu


    StartHoming:
    gosub CLR
    serout TX, 2, [" Begin Homing, Homie ", 13, 10, 10]
    serout TX, 2, ["*** UNDER CONSTRUCTION *** ", 13, 10]
    pause 3000
    goto MainMenu

    TestPattern:
    HIGH el
    pause 1000
    low el
    pause 1000
    high dir
    pause 50
    high el
    pause 1000
    low el
    low dir
    pause 1000
    HIGH az
    pause 1000
    low az
    pause 1000
    high dir
    pause 50
    high az
    pause 1000
    low az
    low dir
    pause 1000
    goto TestPattern

  13. #13


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    Man! I know this has to be something crazy simple to fix. This was the basis of my very first PIC project 6 weeks ago when I used a PICaxe 20M2 to build a BT controlled tank to pull wire under houses. It worked beautifully! But alas, PICAXE is a lil different from PBP, and I wiped the bootloader from that chip as soon as I got my picKIT3. It sux too cuz I want my tank running again and I cant do that either until I solve this same issue.......

  14. #14
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    Quote Originally Posted by thasatelliteguy View Post
    Man! I know this has to be something crazy simple to fix. This was the basis of my very first PIC project 6 weeks ago when I used a PICaxe 20M2 to build a BT controlled tank to pull wire under houses. It worked beautifully! But alas, PICAXE is a lil different from PBP, and I wiped the bootloader from that chip as soon as I got my picKIT3. It sux too cuz I want my tank running again and I cant do that either until I solve this same issue.......
    I agree with you it has to be something simple.

    Cut down the program to the bare minimum and test.

    Code:
    #CONFIG
     __config _FOSC_HS & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF & _CP_OFF
     #ENDCONFIG
    
     DEFINE OSC 12
    
     TX var PORTC.6
     RX var PORTC.7
    
     cereal var byte
     i var byte
     
     For i = 0 to 30
     serout TX, 2, [10]
     next i
     
     MainMenu:
      serout Tx, 2, ["******** MAIN MENU ********", 13, 10, 10]
     serout Tx, 2, [" 1. Start Homing Sequence", 13, 10]
     serout Tx, 2, [" 2. Manual JOG Mode", 13, 10]
     serout Tx, 2, [" 3. Auto-Acquire Satellite", 13, 10]
     serout Tx, 2, [" 4. Stow Dish for Travel", 13, 10, 10]
     serout Tx, 2, ["Enter Your Selection:", 13, 10]
      Serin RX, 2, 500, MainMenu, cereal
    
      serout TX, 2, [cereal] 'For debugging only
     serout TX, 2, ["Dingleberry"]
     goto MainMenu

  15. #15
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    I do not understand how you are getting [00]Dingleberry surely it should be 00Dingleberry.

  16. #16
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    Your comment about getting "[00]Dingleberry" makes me wonder...

    Why would you get two zeros? Your not formatting "cereal" with DEC - or any qualifier. Perhaps you should; perhaps you are getting an ASCII non printing character "printed" to your output (a non-printing character of ASCII value 1 for example)? It seems to me that somewhere, something is happening as the 00 is coming from somewhere.

    You might also try adding a cereal = 65 prior to MainMenu; if you get an "A", then you'll know the serial input is getting nothing in the loop. If you don't... then something is changing the value...

  17. #17
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    Amoque,

    I really do not understand the []. Where do they come from?

  18. #18
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    Quote Originally Posted by EarlyBird2 View Post
    Amoque,

    I really do not understand the []. Where do they come from?
    I don't know... I was quoting the OP. If the output is a direct quote, there is much about it I don't understand. Why TWO zeros (in addition to the brackets)? PicBasic doesn't default to double digit display; perhaps the subroutine fails and runs through another subroutine or the WDT causes a second response. Perhaps the brackets were only added for clarity.

    For myself, I think that I'd:

    1) Set a default value for Cereal, so as to know it was changed (or not).
    2) Extend the timeout so that I could be sure that no amount of key-banging elicited an input.
    3) Format the output as DEC or BIN so as to standardize the output.

  19. #19


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    It was the pins. I was on the hardware TX/RX pins and I guess it didnt like it.

  20. #20
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: serin trouble with PIC16F877A

    Do you mean it works now?

    I wouldn't repaint the menu in my loop, I'd return right below it.

    Robert

Similar Threads

  1. Having trouble with SERIN command and MAX6675
    By emerson in forum mel PIC BASIC Pro
    Replies: 39
    Last Post: - 16th April 2017, 20:48
  2. Control de puertos PIC16F877A / Port Control PIC16F877A
    By martintorres in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th October 2013, 04:49
  3. i'm in trouble...help me please...
    By texas5 in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 25th September 2008, 20:50
  4. Trouble with P.W.M
    By Muller in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th April 2008, 22:18
  5. Replies: 9
    Last Post: - 4th February 2008, 20:12

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