PDA

View Full Version : MS QuickBasic & PIC16F84A



JBKerner
- 19th November 2006, 02:19
I'm having a problem and it's driving me bonkers! I have a very simple QuickBasic program running on my laptop:

' Open communication channel to COM1 at 9600 Baud.
OPEN "com1:9600,n,8,1,cd0,cs0,ds0" FOR OUTPUT AS #1

'---- Default Settings ----
byte = 85 ' BIN %01010101

'---- Body ----
MainLoop:
INPUT "Just hit RET.", CHAR$
PRINT #1, byte;
GOTO MainLoop:

The program is supposed to send decimal-85 out of the COM1 port every time I hit return. OK, fine. It seems to work, and yes, I know I'm not closing the COM port.

The PIC is running the following program:

include "modedefs.bas" ' PIC is 16F84A
Sdata VAR PORTA.4 'serial input on pin RA4
CHAR VAR BYTE
TRISA = %00010111 ' set PORTA pins RA0-RA2, and RA4 to INPUT
TRISB = %00000000 ' set PORTB pins to output
PORTB = %00000000 ' Clear port B

main:
serin Sdata, N9600, char ' input byte
PORTB = CHAR
goto main

OK, that looks pretty straightforward, too! The problem is, the PIC thinks it's receiving decimal-32 (ASCII character for a space). Huh?? Can anyone explain why I'm getting decimal-32? I presume that the PC is sending 85 first, and 32 second, but I sure don't see how or why!

Jeff

Darrel Taylor
- 19th November 2006, 04:05
OMG!

Quickbasic, haven't used that in so many years. Just went down memory lane googling for an answer here. Can't really says it's an answer or not, but here's a few things I found.

Every example I found for OPEN looked like this

OPEN "COM1:9600,N,8,1,CD0,CS0,DS0,OP0" FOR OUTPUT AS #1

Couldn't for the life of me find out what the extra OP0 is for??

Then the PRINT statements would correlate to this...

PRINT #1, CHR$(85);

-- OR --

PRINT #1, CHR$(byte) ' for your program.
<hr>
On the hardware side, the PC puts out TRUE RS-232, but your PBP program is expecting Inverted RS-232. Can I assume you only have resistors in-between the PC and PIC? Or, is there a MAX232 (or equiv.), in which case you would need T9600 instead of N9600.

.

JBKerner
- 19th November 2006, 04:39
Hi Darrel,

I just had a Homer Simpson moment (Doh!) Yup, that was it! Yeah, I haven't used QuickBasic in a while either (could ya tell?)

Anyway, thanks for the help!

Jeff