I'm trying to send a decimal number (from 0 to 255) from the computer to pic16F877. I'm using MAX232 for serial interface.I'm sure that the hardware is connected properly. The problem is that I want to receive the decimal number from RS232 in pic16f877 and to use it in the rest of the program comparing this decimal number with another decimal number (<,>,=) and taking a certain decision based on this comparison result.
I tried this code segment but the decimal number is not interpreted by PIC correctly. I'm using the function HSerIn [Dec input].
I don't know what is the problem. I think there might be something missing.
thanks

'************************************************* ***************

'* Name : UNTITLED.BAS *

'* Author : [select VIEW...EDITOR OPTIONS] *

'* Notice : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *

'* : All Rights Reserved *

'* Date : 6/17/2008 *

'* Version : 1.0 *

'* Notes : *

'* : *

'************************************************* ***************

Device = 16F877

XTAL = 4

HSERIAL_BAUD = 9600 ' Set baud rate to 9600

HSERIAL_RCSTA = %10010000 ' Enable serial port and continuous receive

HSERIAL_TXSTA = %00100000 ' Enable transmit and asynchronous mode

HSERIAL_CLEAR = On ' Optionally clear the buffer before receiving

Dim desired_pos As Byte ' the actually recieved byte

Dim actual_pos As Byte ' the actually converted word

Dim control As Byte

TRISA = %00000001 ' Configure AN0 (PORTA.0) as an input

TRISD = %00000000

ADCON1 = %10000000 ' Set analogue input on PORTA.0

AGAIN:

actual_pos = 128

HSerIn [Dec desired_pos]

control = desired_pos -actual_pos

If control>0 Then

PORTD.4=1

PORTD.5=0

PORTD.6=1

PORTD.7=0

HSerOut [Dec actual_pos]

EndIf


If control<0 Then

PORTD.4=0

PORTD.5=1

PORTD.6=0

PORTD.7=1

HSerOut [Dec actual_pos]

EndIf


If control=0 Then

PORTD.4=1

PORTD.5=1

PORTD.6=0

PORTD.7=0

HSerOut [Dec actual_pos]

EndIf

GoTo AGAIN