PIC16F88 Serial COMMs

Thread Starter

steveonline

Joined Feb 8, 2009
11
Hi all, just joined this forum. :)

I bought a PIC16F88 a couple of days ago, and after a ton of problems, I finally got my first simple program going. (An LED blinking on and off controlled by a pushbutton)

I was wondering if anyone has access to or any information about how to set up the PIN8 as a serial output, and how to set this up at 9600 baud etc. Im coding in C since I have little knowledge of assembly.
Right now i would just like to send an ASCII code to a LED display I have here.

Thanks in advance,
 

beenthere

Joined Apr 20, 2004
15,819
Does your LED display require an RS-232 input? If so, you may want to look into a MAX-232 to handle that interfacing.
 

Thread Starter

steveonline

Joined Feb 8, 2009
11
No, it requires TTL/CMOS voltage levels, which is why i cant hook it up directly to my pc. Which is why im using a PIC to send it ascii characters manually.
I know I can use max232 to interface the LED display directly to the serial rs232 port on my pc, but i just wanted the LED display to be part of my project. (Im trying to build a wirelessly controlled programmable robot for a university project.)

I just have no idea how to set up serial communications with my PIC16F88 microcontrollers :(
 

Thread Starter

steveonline

Joined Feb 8, 2009
11
Sorry I guess I havent been very clear...
I was just wondering on this forum if anyone has any websites of information on how to write the code to setup the pins. I assume I have to change the config line 1, but its an overwhelming amount of information and im kind of new to this.

Youve also just told me that Pin 8 is serial input (RX) and pin 11 is output (Tx), but
from the datasheet, it says Pin 7 is SDI and Pin 8 is SDO.. Is that not serial data input/output ??

My pic is running at 4MHz I believe.. its an internal clock..
OSCCON = 0x60;
I think thats the command to set it for 4MHz

Also looking at the datasheet i cant find any information about changing CONFIG register bits to enable serial communication.. so there must be some other way.. the problem is all the code I find online is written in assembly, for instance:

http://www.electro-tech-online.com/micro-controllers/36567-help-pic16f88-serial-communication.html

on this website there is quite a lot of information, but i have a hard time translating it due to my lack of inexperience with assembly..

If anyone knows of any information about how to set up serial comms in C, that would be greatly appreciated!!

The LED does have a datasheet, and i'm aware that it just receives ASCI characters at either 9600 or 19200 baud rate ( http://www.rentron.com/SLED/SLED-C4.pdf )
Ive hooked it up my PICKit 2 programmer here, using the UART tool, and sent it a few ascii chars, it doesnt work too well though, i guess the UART tool on the pickit sends other bits tied in with the ascii for the UART communications(not too sure about how a UART works).
 

RiJoRI

Joined Aug 15, 2007
536
[i[]Youve also just told me that Pin 8 is serial input (RX) and pin 11 is output (Tx), but
from the datasheet, it says Pin 7 is SDI and Pin 8 is SDO.. Is that not serial data input/output ??[/i]

Yes and no. It is the Serial Input or Output for a synchronous serial communication protocol, such as I2C. The Tx/Rx is for an asynchronous serial communication protocol, such as is usually used with RS232.

HTH,
--Rich
 

Thread Starter

steveonline

Joined Feb 8, 2009
11
Here the setting for the serial in/out @ 9600,n,8,1 (UART initialization)


Code:
RCSTA = h90 ' Enable serial port & continuous receiveTXSTA = h24 ' Enable transmit, BRGH = 1SPBRG = 25 ' 9600 Baud @ 4MHz, 0,16%
Connect your serial device pin 1 to pic pin 11
Wow thanks for the heads up Alberto.

I am programming in C however, and I will need to define these, so I suppose I should have the following:

Rich (BB code):
#define RCSTA 0x18
#define TXSTA 0x98
#define SPBRG 0x
 
 
//main code etc bla bla routines etc
 
//Then setup UART
 
RCSTA = 0x90;
TXSTA = 0x24;
SPBRG = 25;         
 
//Then to transmitt with UART i need to set the bits in the TX register? 
And it does it automatically?  
Or am I just being hopeful here? E.g to send character "C"..
 
TXREG = C;



And finally

Yes and no. It is the Serial Input or Output for a synchronous serial communication protocol, such as I2C. The Tx/Rx is for an asynchronous serial communication protocol, such as is usually used with RS232.
Someone told me that the USART is much easier to work with than the serial interfaces, and on the assumption that this person knew what he was talking about, ive decided to have a try at programming the PIC for USART.

Thanks for the input Rich
(P.S what is HTH?)
 
Top