Can someone tell me if I am going in the right direction?


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Jun 2008
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Actually, it's not working, after making changes to my program, I realized that it isn't working at all. (nothing responded to any changes in the code, what I took to be working, was really just the serial connection powering a led directly, damn my optimism)

    Anyways, here is what I have now

    Transmitting Code:

    CLEAR

    DEFINE OSC 20 'Defines oscillator rate
    INCLUDE "modedefs.bas"
    ADCON1=%11111111 'Sets all ports to digital
    TRISD.0=0 'Sets Portd.0 to output
    LED VAR BYTE : LED=1 'Declares and defines LED variable
    LOOP: 'Start of main loop
    SEROUT PORTD.0,T2400,[LED] : PAUSE 50 'Sends LED value serially
    'out of portd.0
    GOTO LOOP 'Repeat forever
    END

    Receiving Code:

    CLEAR

    DEFINE OSC 20 'Defines oscillator
    INCLUDE "modedefs.bas"
    ADCON1=%11111111 'Sets all ports to digital
    TRISB=%00001000 'Sets Portb.4 to input
    LED VAR BYTE : LED=0 'Declares and sets LED variable to 0
    LOOP: SERIN PORTB.4,T2400,[LED]: PAUSE 50 'Checks portb.4 for serial imput
    IF LED=1 THEN 'If LED equals 1, turn LED 2 on and 3
    PORTB.1=1 'off, otherwise turn 3 on and two off
    PORTB.2=0
    ELSE
    PORTB.1=0
    PORTB.2=2
    ENDIF
    PAUSE 100 'Pause to see results
    GOTO LOOP 'Repeat
    END

    Thanks, I apologize for my lack of knowledge.
    Matt

  2. #2
    Join Date
    May 2008
    Location
    Florida
    Posts
    64


    Did you find this post helpful? Yes | No

    Default

    Matt

    In the transmitting code. you turn the LED on with
    LED=1

    Then you enter the loop to send to the Port.

    Then on the receiving side you keep reading the LED value.

    and apply some logic

    Code:
    IF LED=1 THEN 'If LED equals 1, turn LED 2 on and 3
    PORTB.1=1 'off, otherwise turn 3 on and two off
    PORTB.2=0
    ELSE 
    PORTB.1=0
    PORTB.2=2
    ENDIF
    Maybe you should check your logic and make sure it works on the LAB-X2 before you go to the Serial port.

    I might comment out this - 'SERIN PORTB.4,T2400,[LED]: PAUSE 50' and toggle the LED on and off. Then go from there.

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


    Did you find this post helpful? Yes | No

    Default

    Hello Matthew,
    I am writing from my wife's computer and that usually gets me in trouble, as I am unabel to test anything, having said that here goes . . . It looks as if you are sending out binary 1 or %00000001 and expecting to capture the same at the receiver. Methinks serin / serout doesn't work that way, I think it is looking for the hex or ASCII equiv. so if you serout 1 in binary, your receiver is looking for $31 or 49 Decimal, you could change the loop to send out $31, OR 49, and look to receive the same SERIN PortB.0,T2400,[#LED] . Just my thoughts, probably wrong.
    OR you can have the IF THEN loop expect anything except zero.
    JS
    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.

  4. #4
    Join Date
    Jun 2008
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Thank you everyone for the help...I have tried all your ideas, and though they seem to be getting me closer, it's not quite working right yet. I am sorry this is so hard for me to figure out, I am sure I am making some dumb mistake.

    Right now I am using portb.7 for the input pin, as to not interfere with the used components on the lab X2 pin. So far I have no response to anything from the output program, the codes I am currently using are as follows.

    Transmitting Program
    CLEAR

    DEFINE OSC 20 'Defines oscillator rate
    INCLUDE "modedefs.bas"
    ADCON1=%11111111 'Sets all ports to digital
    TRISD.0=0 'Sets Portd.0 to output
    LED VAR BYTE : LED=1 'Declares and defines LED variable
    LOOP: 'Start of main loop
    SERout PORTD.0,T2400,[LED] : PAUSE 50 'Sends LED value serially
    IF LED=1 THEN
    LED=0
    ELSE
    LED=1
    ENDif 'out of portd.0
    GOTO LOOP 'Repeat forever
    END

    Receiving Program:

    CLEAR

    DEFINE OSC 20 'Defines oscillator
    INCLUDE "modedefs.bas"
    ADCON1=%11111111 'Sets all ports to digital
    TRISB=%10000000 'Sets Portb.4 to input
    LED VAR BYTE 'Declares and sets LED variable to 0
    LOOP:
    SERIn PORTB.7,T2400,[LED]: PAUSE 50 'Checks portb.4 for serial imput
    IF LED=1 THEN 'If LED equals 1, turn LED 2 on and 3
    PORTB.1=1 'off, otherwise turn 3 on and two off
    PORTB.2=0
    ELSE
    PORTB.1=0
    PORTB.2=1
    ENDIF
    PAUSE 100 'Pause to see results
    GOTO LOOP 'Repeat
    END

    I am wondering is possibly I am not using the right defines?

    Thanks,
    Matt

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by MatthewM View Post
    Thank you everyone for the help...I have tried all your ideas, and though they seem to be getting me closer, it's not quite working right yet. I am sorry this is so hard for me to figure out, <b>I am sure I am making some dumb mistake.</b>

    Right now I am using portb.7 for the input pin, as to not interfere with the used components on the lab X2 pin. So far I have no response to anything from the output program, the codes I am currently using are as follows.

    Transmitting Program
    CLEAR

    DEFINE OSC 20 'Defines oscillator rate
    INCLUDE "modedefs.bas"
    ADCON1=%11111111 'Sets all ports to digital
    TRISD.0=0 'Sets Portd.0 to output
    LED VAR BYTE : LED=1 'Declares and defines LED variable
    LOOP: 'Start of main loop
    SERout PORTD.0,T2400,[LED] : PAUSE 50 'Sends LED value serially
    IF LED=1 THEN
    LED=0
    ELSE
    LED=1
    ENDif 'out of portd.0
    GOTO LOOP 'Repeat forever
    END

    Receiving Program:

    CLEAR

    DEFINE OSC 20 'Defines oscillator
    INCLUDE "modedefs.bas"
    ADCON1=%11111111 'Sets all ports to digital
    TRISB=%10000000 'Sets Portb.4 to input
    LED VAR BYTE 'Declares and sets LED variable to 0
    LOOP:
    SERIn PORTB.7,T2400,[LED]: PAUSE 50 'Checks portb.4 for serial imput
    IF LED=1 THEN 'If LED equals 1, turn LED 2 on and 3
    PORTB.1=1 'off, otherwise turn 3 on and two off
    PORTB.2=0
    ELSE
    PORTB.1=0
    PORTB.2=1
    ENDIF
    PAUSE 100 'Pause to see results
    GOTO LOOP 'Repeat
    END

    I am wondering is possibly I am not using the right defines?

    Thanks,
    Matt
    Hi Matt, well my other idea was wrong (again) so then, How are you setting the config statements? http://www.picbasic.co.uk/forum/showthread.php?t=543
    Do you have a blinky setup to confirm the chips are actually alive ? Have you checked the connections pin for pin to be sure corrupt old breadboard isn't killing your time? I just trashed another one yesterday . . .<b>BTW mistakes are not dumb, people who will not admit to them, well . . . it's your call.</b>
    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.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    It looks as if you are sending out binary 1 or %00000001 and expecting to capture the same at the receiver. Methinks serin / serout doesn't work that way, I think it is looking for the hex or ASCII equiv. so if you serout 1 in binary, your receiver is looking for $31 or 49 Decimal, you could change the loop to send out $31, OR 49, and look to receive the same SERIN PortB.0,T2400,[#LED] . Just my thoughts, probably wrong.
    OR you can have the IF THEN loop expect anything except zero.
    JS
    Nope, he's got it right. It only gets goofy if you start using the # or the quotes or other modifiers. If you LED=1 then SEROUT xxxx , [LED], you'll send a binary value of %00000001, same thing on the receiving end. If you SERIN xxxx , [LED] and LED contains %00000001, then you've received LED=1.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Nope, he's got it right. It only gets goofy if you start using the # or the quotes or other modifiers. If you LED=1 then SEROUT xxxx , [LED], you'll send a binary value of %00000001, same thing on the receiving end. If you SERIN xxxx , [LED] and LED contains %00000001, then you've received LED=1.
    Well then, here at Crownhill University, today I learned something
    Thanks
    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.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    Well then, here at Crownhill University, today I learned something
    Thanks
    Sorry...I hate it when other people do that to me...
    Now your head is just that much more cluttered with information.
    Today I learned not to spend 7 hours in the sunlight while mowing the lawn without sunscreen in a T-shirt.

  9. #9
    Join Date
    Jun 2008
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    As far as I can tell, the hardware is fine, they have both worked for other programs I have ran on them every time.

    Do I need the "INCLUDE "modedefs.bas"?

    Your codes worked intermittently to show that there was no serial signal received. In that one time it flashed both lights three times, then went dark...No amount of resetting or even reprogramming reproduced the results. I am going to try retesting the Lab X2 board, but last time I did, all components worked fine as expected (using a sample program off of melabs). Right now I can't get any of the light to light up...I have a feeling I haven't defined something right, but as far as I can tell, it's fine. This is really a odd set of results.

    Matt

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


    Did you find this post helpful? Yes | No

    Default

    "modedefs.bas" has the serout mode in it, you can use the mode command instead of T2400 if you prefer, it has some other stuff in it too, go ahead and open and inspect it to see for yourself what's in there. MAKE sure nothing is hooked to your OSC pins except the reasonator or crystal and caps. Make sure your config is set to the proper OSC for the freq. you are using XT for 4mhz HS for higher. If you are using the default configs without having changed it to HS then that is your first problem.
    Last edited by Archangel; - 21st June 2008 at 06:20.
    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.

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    TX Side:
    Send byte value of "1" continuously with 50ms between each byte sent (1 = %00000001, as in the number right after 0, just to keep us both straight here)
    Code:
    DEFINE OSC 20                   'Defines oscillator rate
    INCLUDE "modedefs.bas"
    CLEAR
    LED VAR BYTE : LED = 1 : ADCON1=$ff : TRISD.0=0
    LOOP: SEROUT PORTD.0,T2400,[LED] : PAUSE 50 : GOTO LOOP
    END
    Rx Side:
    Start with the LED off. If a byte of value = %00000001 is received, turn the LED on PortB.1 on.
    If a value of %0000001 is received, PortB.1 will turn on and stay on.
    If something other than a value of %00000001 is received, the SERIN command will take it and PortB.2 will flash for 1/10 second then go back to trying again.
    If nothing is received after 2 seconds, both LEDs will flash for 1 second then go back to trying again.
    Code:
    DEFINE OSC 20                       'Defines oscillator
    INCLUDE "modedefs.bas"
    CLEAR
    LED VAR BYTE : LED = 0 :ADCON1=$ff : TRISB=8
    LOOP: SERIN PORTB.4,T2400,2000,nothing,[LED]
    IF LED=1 THEN
     PORTB.1=1
    ELSE
     PORTB.2 = 1 : pause 100 : PORTB.2 = 0
    ENDIF
    GOTO LOOP
    nothing: PortB=3:pause 100:portb.0:pause 100:portb=3:pause 100:portb=0:pause 100
    PortB=3:pause 100:portb.0:pause 100:portb=3:pause 100:portb=0:pause 100
    PortB=3:pause 100:portb.0:pause 100:goto loop
    END
    Of course, this assumes all the hardware is working correctly...

Similar Threads

  1. Math help - rolling average Wind Direction
    By wjsmarine in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 23rd July 2009, 00:08
  2. How to detect sound direction?
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th December 2008, 04:53
  3. Replies: 10
    Last Post: - 8th April 2008, 21:07
  4. Replies: 5
    Last Post: - 12th September 2007, 15:59
  5. Replies: 26
    Last Post: - 2nd January 2006, 18:31

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