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;
And to see how various modifiers work in action;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]
The PC will also send data to your PIC in ASCII. I.E. if you type in 17, and hitCode: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]
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?
A little experimentation goes a long way....;o]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




Bookmarks