PDA

View Full Version : code problems



ngeronikolos
- 28th June 2005, 13:27
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

ngeronikolos
- 29th June 2005, 09:02
Any idea?

Please

Bruce
- 29th June 2005, 15:45
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;


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;


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?


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]