PIC16F88 Serial COMMs

Discussion in 'Embedded Systems and Microcontrollers' started by steveonline, Feb 8, 2009.

  1. steveonline

    Thread Starter Member

    Feb 8, 2009
    11
    0
    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,
     
  2. beenthere

    Retired Moderator

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

    Thread Starter Member

    Feb 8, 2009
    11
    0
    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 :(
     
  4. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Does the LED display have a data sheet? If it does, it will set forth all the parameters for serial data exchange.
     
  5. steveonline

    Thread Starter Member

    Feb 8, 2009
    11
    0
    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).
     
  6. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    [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
     
  7. steveonline

    Thread Starter Member

    Feb 8, 2009
    11
    0
    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:

    Code ( (Unknown Language)):
    1.  
    2. #define RCSTA 0x18
    3. #define TXSTA 0x98
    4. #define SPBRG 0x
    5.  
    6.  
    7. //main code etc bla bla routines etc
    8.  
    9. //Then setup UART
    10.  
    11. RCSTA = 0x90;
    12. TXSTA = 0x24;
    13. SPBRG = 25;        
    14.  
    15. //Then to transmitt with UART i need to set the bits in the TX register?
    16. And it does it automatically?  
    17. Or am I just being hopeful here? E.g to send character "C"..
    18.  
    19. [FONT=Arial][SIZE=1][FONT=Verdana][SIZE=2]TXREG = C;[/SIZE][/FONT][/SIZE][/FONT]
    20.  
    21.  



    And finally

    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?)
     
Loading...