PBP 16F876A 2 Way Communication
I am fairly new to PICs and PBP (v2.47). I have designed a small general purpose A/D I/O interface card utilizing a PIC 16F876A. It will be used by my students to gather and graph data using LabVIEW graphical programming language. It must communicate through a USB converter module (FTDI UM232R) because my students are online and use Macs or laptop PCs with no serial port.
Eventually, I would like to have the card execute several commands, and so need two way communication. So far, I have the Defines setup and a program written to read AD port 0 and send 10 bit result to the hardware serial port. It sends data continuously without a request from the PC. It works fine, except that if I stop receiving data, the serial buffer fills or overflows and when I start receiving data again, it is erratic for many seconds before it returns to normal operation. I need a program that tells the PIC chip to read A/D Port 0 and send result to the hardware serial port just once and then wait for another command. Any thread or archive with such a program? Any suggestions for writing one? Thanks for your help.
PBP 16876FA 2 way communication
Charles,
I understand only part of what you are saying. If I send a charactor from the PC and the PIC program running has a HSERIN comand in the loop, it will set bit 5 of the PIR register? How to I cause a result to be sent back to the PC? In other words, how do I read the PIR flag or register? Could you provide an example of this loop? Thanks for your help.
PBP 16F876A 2 Way Communication
Thank you Charles Linquis and Mister E. Both of your suggestions were helpful. I have incorporated your suggestions in the program below, but I get an error when the compiler reaches the HSERIN command.
ERROR Line 38: Expected '['.
I have tried many different ways to confugure the HSERIN command, but always get this or sometimes additional errors. Any suggestions?
Thanks again for your help.
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 10
adcVar VAR WORD
TRISA = %11111111
ADCON1 = %10000010
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 9600
DEFINE HSER_CLOERR 1
PAUSE 005
main:
If PIR1.5 = 1 THEN
HSERIN[char]
HSEROUT [DEC adcvar, 10, 13]
ENDIF
ADCIN 0, adcVar
PAUSE 50
GOTO main
PBP 16F876A 2 way Communication
Thanks Mat and Ioannis,
The HSERIN command now reads:
HSERIN [char var byte]
I still get the same error
ERROR Line 38: Expected '['.
Anything else I should try? Thanks everyone.
PBP 16876A 2 way Communication
Mat,
Thanks a million. The program now compiles ok, but it seems to hang during execution of the program. I have tried re-arranging the order of the instructions, but so far no luck. I will appreciate more suggestions
PBP 16F876A 2 Way Communication
Thanks to everyone, and a second time to Mister E for finding my typo. It now works like a charm! Have a great day!