PDA

View Full Version : Communication between PC and PIC16f876



knsteam
- 7th June 2007, 09:29
Hello

My project and to make a billposter unwinding, who shows what I send it of the PC.

Here is my problem I have to pass on a message (thus characters) of the PC towards a PIC16F876 via the connection RS232.

To send characters I use an interface Visual Basic and as composing of change of signals (+10 /-10V - > +5 / 0V) I use a SP233ACP.
When that I look at the signals of the component there is indeed communication between both but the PIC receive that zeros or then it does not understand what I send it.

I would like to know how to connect the PIC with the PC and if you have an interface to send a mesage I am a buyer.

Thank you

KNSTEAM

mackrackit
- 7th June 2007, 11:59
Welcome to the forum.

You need to provide more information before anyone can help.

Things like:
baud rate from PC
True or Inverted
How is the PIC setup
What format are you trying to use - SERIN, SERIN2, HSERIN

Some code to see if the command is used correctly.

Maybe all of the above is correct and the PIC understands the serial input but the problem is in another place - stuck in a loop for example.

Question for you. What is a "billposter unwinding" ?

knsteam
- 11th June 2007, 09:27
Hello Dave

Baud rate from PC: 19200bps, No Parity, 8 bits, and 1 stop bit.

The fastest i can transfer data at is 9600bps, so i need to fool the PIC to send data faster.
I do this by saying that I have a 10MHz oscillator, but in fact i am using a 20MHz oscillator. By doing this, everything will run twice as fast, therefore, 9600*2=19200.

Program:

' C O M M U N I C A T I N G W I T H T H E C O M P U T E R '


PCtalk:
i = 0 : pause 100
CTS = 1

SERIN PORTA.4,N9600,["@"],char

getserial:

Serin PORTA.4,N9600,char

write i, char


if char = EOM then
CTS = 0
Goto start
endif

i = i + 1

goto getserial


I hope to have given more information and that you can help me.
Excuse me for my English (I am French).

Knsteam

skimask
- 11th June 2007, 17:16
SERIN PORTA.4,N9600,["@"],char

Look thru the '876 datasheet...see if you can find anything special about PortA.4.

mackrackit
- 11th June 2007, 22:32
Look at this
http://www.picbasic.co.uk/forum/showthread.php?t=561

Playing with the clock speed might work, but I think you are asking for problems doing this.

Why not slow the VB program dow to 9600 or use the SERIN2/SEROUT2 command at the PIC. 19200bps is supported with SERIN2/SEROUT2.

mister_e
- 11th June 2007, 22:40
My 2 cents... why using SERIN anyways as this PIC have a built-in USART?

For once Skimask says a nice pointer...

ADCON1=7

Should help a little bit

Ca devrais marcher :D

skimask
- 12th June 2007, 00:18
My 2 cents... why using SERIN anyways as this PIC have a built-in USART?
For once Skimask says a nice pointer...
ADCON1=7
Should help a little bit
Ca devrais marcher :D

Not to mention the other 'special thing' about RA4...

mister_e
- 12th June 2007, 00:19
Yeah but... used as input i won't change anything... and it's not a A version, so no comparator thingy... even if... it's already disabled at POR...

knsteam
- 13th June 2007, 09:30
Hello everybody
Thank you for your answers

I would like to know how to initialize the UART.
Here is how I have make but that does not work.

(19200bps,No parity,8 bits,and 1 stop bit)

TXSTA = $20 '//Transmission sur 8 bits, pas de parité, mode asynchrone
RCSTA = $90
SPBRG=25

mister_e
- 13th June 2007, 14:56
Bonjour,
Depending how you want to use the USART, the initialization setup will be different. Let's say you want to read/write from the PIC USART register (RCREG/TXREG) yourself, your setup above is almost what you need but not not 100% exact. for a 9600 baud @4MHZ, the setup will be

RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 25 ' 9600 Baud @ 4MHz, 0.16%


But more than often we want to use the power of a PBP built-in command, hence HSERIN/HSEROUT. In that case the right setup will be.

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 25 ' 9600 Baud @ 4MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically


This also assume you're going to use the PIC dedicated I/Os (TX/RX)

I would suggest you to download and use my PicMultiCalc, yeah i know i sound like a broken record but... agreed it's an handy tool.

http://www.mister-e.org/pages/utilitiespag.html

Bonne chance!

knsteam
- 14th June 2007, 09:53
Merci Mister e

But I would like to know another thing if I pass by the UART to register the information which goes into the PIC, how I have to proceed.

This line of program is good:

CTS = 1

SERIN PORTC.7,N9600,["@"],char 'wait for char. @ from the PC and store second @ in char... this is just a wait line, no received data is used

getserial:

Serin PORTC.7,N9600,char 'receive at 9600bps and store in variable char

write i, char 'write each received character to the memory


if char = EOM then
CTS = 0
Goto start
endif

i = i + 1

goto getserial

I am going to try with your configuration of the UART
Good day

Regards

knsteam
- 26th June 2007, 10:59
Thank you for your help,
That works