1 slave 1 master 1 MAX232 1 problem ?


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I'll lead you by the hand on this...

    If you type a number 4 on the PC (eg Hyperterminal), it sends a character, but it doesn't send a numeric value of 4 as you expect, it sends something quite different...

    Do you have a BASIC Interpreter on your PC (like GWBasic or QBasic or VisualBasic)?

    Find out what happens when you do this...

    Print asc("4")

    and then this...

    Print chr$(52)

    what appears on your screen?

    Look up what the ASC instruction does in BASIC (I'm not taking about PIC BASIC here but a BASIC that you can run on your PC). The ASC instruction will lead you to understaning the relationship between a string "4" and a numeric decimal 52. It will lead you to a TABLE of CODES... this table cross-references numeric values with displayable values... I'm trying hard not to give you the name of this table, that is for you to find out and tell me.

    Now I know you say that "Read the Manual" is my answer to everything, but I'm insisting that you go to the MeLabs website, and download the latest manual. The TABLE of CODES are in an Appendix in the BACK OF THE MANUAL. Look for it.

    I've also looked at your pictures... I'll guarantee this code table will be found in every one of your PICBasic Books.

  2. #2
    Join Date
    May 2005
    Posts
    49


    Did you find this post helpful? Yes | No

    Wink Thanks Melanie now i understand.

    Yes i have visual basic 6.0 professional now i understan what u mean.
    Communication between pic and PC is a table of ASCII characters.I understand they re communicating not like as i think.For exmp when i am trying to sent 1 from pc to pic it sents 49 decimal number or 31 hex.If i try to compare numbers useing if i have to look 49 for 1 not look 1 then it will fail.
    Asking is not a shame but not learning is a SHAME!!!

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


    Did you find this post helpful? Yes | No

    Default

    Exactly! Now you can also understand the example code I posted.

    You can always convert numbers from ASCII to numeric decimal...

    So... in the example with the test variable, if you take the ASCII number and subtract 48, you will be left with the Decimal Numeric Value (but this is only valid for numbers).

    Look at my new example...
    Code:
    	test var byte
    
    loop:
    	hserin [test]
    	test=test-48
    	if test=4 then 
    		HSEROUT ["I've struck Gold",13,10]
    		else
    		HSEROUT ["No Cigar",13,10]
    		endif
    	goto Loop
    	end

  4. #4
    Join Date
    May 2005
    Posts
    49


    Did you find this post helpful? Yes | No

    Red face yes melanie but another how.

    yes now i do the same.But i don't understan 1 think.Now i can sent 1 digit numbers how can i sent 2 digit numbers?
    for example when i sent 15 it comes to pic 49 53.i try to use this code
    HSERİN [STR test\2]
    if test = 4953 then goto ok
    goto loop
    ok:
    HSEROUT ["OK MAN U DID IT!",13,10]
    goto loop
    end

    it will not work i know coz test is a byte that can't get numbers more than 255 if i make test a word PBP gives error i use str =string but it accepts charakters like a,b,c not numbers than what must i do ?
    test var byte[2] means 2 value but how can i put 2 value to pic?
    Last edited by SuB-ZeRo; - 30th July 2005 at 22:44. Reason: forgot to say something
    Asking is not a shame but not learning is a SHAME!!!

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    test(0) holds the first ASCII digit (tens) = example 49
    test(1) holds the second ASCII digit (units) = example 53

    Value var byte

    value=((test(0)-48)*10)+(test(1)-48)

    value using our example ASCII 49 53 will be decimal 15.

    If 'value' is likely to be bigger than 255, then it'll have to be a word.

    You now have the knowledge... be creative...

    I recon the hood in your avatar is stopping you seeing the big picture... lose the hood, buy a crate of beer...

  6. #6
    Join Date
    May 2005
    Posts
    49


    Did you find this post helpful? Yes | No

    Red face ok it's working

    test var byte
    test2 var byte
    value var byte
    loop:
    hserin [test,test2]
    value=((test-48)*10)+(test2-48)
    if value=15 then
    goto ok
    else
    goto fail
    endif
    goto loop
    ok:
    hserout ["you did it!",13,10]
    goto loop
    fail:
    hserout ["U re an idiot",13,10]
    goto loop
    end
    now did it and after i see u re code test(0) means 1 number.(0) useing this is a litle bit same like useing index in visual basic right?
    Asking is not a shame but not learning is a SHAME!!!

Similar Threads

  1. My code for TV remote and MIBAM for RGB control
    By idtat in forum Code Examples
    Replies: 4
    Last Post: - 12th January 2013, 21:52
  2. Delayed output 10 secs
    By lilimike in forum mel PIC BASIC Pro
    Replies: 37
    Last Post: - 14th October 2011, 07:28
  3. first project, and yes, doesn`t work
    By bogdan in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 28th April 2009, 07:13
  4. DS1820 headache
    By Calco in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 12th August 2004, 01:28
  5. New member
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 28th February 2004, 23:44

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