PDA

View Full Version : Help with serial comms with Qbasic & 16F877



Depot1
- 21st July 2006, 21:35
my name is steve
I have only 1 serial port com1 RS232
and want to interface Qbasic to PBP
I am using QB7.1
it's very great compiles to EXE & downward compatable
is there a way to use both Qbasic
and melabs loader at the same time on 1 port
i am using the Max232 so i would use true not inverted
but what is open & driven?
i am using pins 6 & 7 on Pic16F877
hardware USART,
i would like to use Asynchronous no hand shaking
It would be nice to see some completed programs
from those who dun it
----------------PBP
' PicBasic Pro program to send and receive from the hardware serial port

char VAR BYTE ' Storage for serial character

start: HSerout ["Hello World", 13, 10] ' Send text followed by carriage return and linefeed

loop: HSerin 10000, start, [char] ' Get a char from serial port

HSerout [char] ' Send char out serial port

GoTo loop ' Do it all over again

End
----------------------Qbasic
OPEN "COM1:9600,N,8,1,BIN" FOR OUTPUT AS #1
print #1 A$

----------
Thanks

mister_e
- 21st July 2006, 21:53
Unless you Close the COM port in your QBasic program, you won't be ale to use both at the time, the loader will prompt you a PORT ACCESS error.

The only way you can do it is to use a COM Port sniffer like HHD Software bellow
http://www.hhdsoftware.com/Family/serial-monitor.html

I guess it could be done in VB using the MSComm error but i never tested it as now... maybe i'm out ;)

As you're using the PIC USART you don't have to worry about the True/Inverted and all other terms. It will work AS IS using the MAX 232. The main Problem i see, is that you must disable the DTR pin in your QBasic program as this pin is used to RESET the PIC when using the Bootloader. If this pin is not disabled, your PIC will be always on RESET and nothing will happen. Never use QBasic as now so i can't confirm that this pin is not already disabled when you open the COM port.

You must configure the USART prior to using it, look in the HSERIN/HSEROUT section of your PBP manual, there's some specific define's to add to your Program header.

HTH

Depot1
- 23rd July 2006, 09:16
qbasic says device time out
it seems that the pic is not recieving
i have set the baud rate with define statement
i don't know what else could be
also i used the close statement QB71
in a seperate program
but bootloader still gives error for com1
my code for both below
-----Pic Basic Pro
' PicBasic Pro program to send and receive from the hardware serial port
DEFINE LOADER_USED 1
char VAR BYTE ' Storage for serial character
DEFINE HSER_BAUD 9600
HSerin 10000, start, [char] ' Get a char from serial port
start: HSerout ["Hello World", 13, 10] ' Send text followed by carriage return and linefeed
loop:
HSerout [char] ' Send char out serial port
GoTo loop ' Do it all over again
End
--------------------qbasic
10 CLS
20 SCREEN 9
30 COLOR 1, 60
35 A$ = "Hello World"
40 OPEN "com1:9600,n,8,1,bin" FOR OUTPUT AS #1
50 PRINT #1, A$
60 Input #1, B$
70 print B$
60 GOTO 50
----------
thanks