code problems


Closed Thread
Results 1 to 3 of 3

Thread: code problems

  1. #1
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120

    Default code problems

    hello boys and girls,
    I have two problems with my code.
    First,I can not display the X byte using Herout command to my terminal.What I see is Address = ,after the = is blank.If I REPLACE it by DEC X everything is ok.Why it is happend?

    Second,I would like to compere X with SerData[0].You can see it in my code.It does not doing this comparison.Why?



    WHILE PORTA.3 = 1 AND PORTA.4 = 1
    GOSUB ADDRESS
    HSEROUT ["Address = ",x,13,10] ;USING X IT DOES NOT APPEAR NOTHING TO MY TERMINAL BUT IF I REPLACE IT WITH DEC X IT DOES
    wend

    DYNAMIC: IF RCIF = 1 THEN
    HSERIN 500,MAIN,[STR SERDATA\18]
    IF SerData[0] = x then ;compere X with SerData[0]
    HSEROUT ["You typed: ", str SerData\17,13,10]
    GOSUB OUT
    gosub SERTALLY
    ENDIF
    endif
    GOTO MAIN

    ...........................

    ADDRESS:
    FOR n = 0 to 50000 step 1
    If PORTA.2=1 then
    I = I + 1
    IF I > 8 THEN I = 1
    NICK1: pause 450
    WHILE PORTA.3 = 1
    SerData[i] = "1"
    GOSUB OUT
    PAUSE 400
    WEND
    WHILE PORTA.4 = 1
    SerData[i] = "0"
    GOSUB OUT
    PAUSE 400
    WEND
    ELSE
    GOTO NICK1
    ENDIF


    x.0 = SerData[1]
    x.1 = SerData[2]
    x.2 = SerData[3]
    x.3 = SerData[4]
    x.4 = SerData[5]
    x.5 = SerData[6]
    x.6 = SerData[7]
    x.7 = SerData[8]
    next n

    RETURN

  2. #2
    Join Date
    Feb 2005
    Location
    GREECE
    Posts
    120


    Did you find this post helpful? Yes | No

    Default

    Any idea?

    Please

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


    Did you find this post helpful? Yes | No

    Default

    It works with the DEC modifier because the PC expects to receive ASCII
    data, and this modifier changes the raw number into ASCII.

    X VAR BYTE

    X = 17
    HSEROUT [DEC X] ' sends ASCII 1 then 7. The PC termiinal displays 17

    The DEC modifier changes 17 to 2 ASCII characters. A 1 and a 7.

    The ASCII value for 1 is 49. The ASCII value for 7 is 55. Try this.

    X = 17
    HSEROUT [DEC X," : ",49,55] ' Try this

    Notice how the DEC modifier has done all the work for you. If you send the
    raw numbers 49,55 it displays the exact same thing 17.

    Now try this.
    HSEROUT [DEC X," : ",49,55," : ",1+"0",7+"0"," : ", 1+48,7+48]

    How come some numbers don't display when I don't use the DEC modifier?

    Look at any ASCII chart. Or print your own on-screen with this;
    Code:
     FOR X = 0 to 63
          Hserout [X]
        NEXT X
          Hserout [13,10] ' CR, LF
        
        FOr X = 64 to 127
          Hserout [X]
        Next X
          Hserout [13,10]
        
         FOR X = 128 to 191
          Hserout [X]
        NEXT X
          Hserout [13,10] ' CR, LF
        
        FOr X = 192 to 255
          Hserout [X]
        Next X
          Hserout [13,10]
    And to see how various modifiers work in action;
    Code:
    X = 17
        Hserout ["X unformatted = ",X,13,10]
        Hserout ["X with Idec modifier = ",Idec X,13,10]
        Hserout ["X with Ihex modifier = ",Ihex X,13,10]
        Hserout ["X with Ibin8 modifier = ",Ibin8 X,13,10]
        Hserout ["X with X + 48 = ",X+48,13,10]
    The PC will also send data to your PIC in ASCII. I.E. if you type in 17, and hit
    enter it sends two ASCII characters. 49 and 55.

    With the example below, what ASCII character do you need to send from
    your PC to PIC to stop the Waiting message from displaying every 5 seconds?
    Code:
    serdata VAR BYTE[2]
    X VAR BYTE
    
    X = "A" - "0"
        
        Hserin 5000,Waiting,[str serdata\2]
        IF (serdata[0]-"0") = X then
          Hserout ["Got ",serdata[0],13,10]
          Goto Yahoo
        ENDIF
        pause 2000
        goto Main   
        
    Waiting:
        Hserout ["Waiting",13,10]
        Goto Main
    
    Yahoo:
        Hserout ["You are now an ASCII master....;o]",13,10]
    
    Finished:
        Goto Finished
    A little experimentation goes a long way....;o]
    Regards,

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

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. Line following robot... problems with some code
    By nepstar in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 24th March 2005, 01:10
  5. Code dsigner lite problems
    By toalan in forum Off Topic
    Replies: 2
    Last Post: - 23rd February 2005, 20:08

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