Pic184550 usart

Discussion in 'General Electronics Chat' started by Dritech, Oct 24, 2013.

  1. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi all,

    I came across a tutorial on using USART with the PIC18F. The coding in the tutorial is the one below:

    Code ( (Unknown Language)):
    1. void main(void)
    2. {
    3.  
    4. TRISC.RC7= 1;      // Make UART RX pin input
    5.  
    6. TRISC.RC6= 0;      // Make UART TX pin output
    7.  
    8. /* asynchronous mode, 8-bit data, HIGH baud rate, transmit enabled */
    9.  
    10. TXSTA = 0X24;
    11.  
    12. /* 9600 BAUD RATE, Fosc=10MHZ, SO SPBRG VALUE IS SET AS 0X40 */
    13.  
    14. SPBRG = 0X40;
    15.  
    16. /* serial port enable bit is set HIGH */
    17.  
    18. RCSTA.SPEN = 1;
    19.  
    20.  
    21.  
    22. TXREG = 'S';      // Data loaded into TXREG Register
    23.  
    24. While (PIR1.TXIF == 0); //wait till TXIF bit is low
    When building the program, the attached errors are occurring. Why is that?

    I included the #include <usart.h> library. Is this the correct one?


    Thanks in advance.
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Try including the PIC's own dot h file.
     
  3. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi, if you are referring to the #include<p18f4550.h> , that is included.
     
  4. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Or does anyone know of an easy to understand tutorial of how to interface Visual Studio in C sharp with the PIC18F4550 ??
     
  5. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi again,

    Is it possible to do it this way? Why is it giving me errors please?

    Code ( (Unknown Language)):
    1. void main(void)
    2. {
    3.    Configurate_USART();
    4.    
    5.    char Temp_Instruction;
    6.  
    7. while(1)
    8. {
    9.  
    10.    if(PIR1bits.RCIF == 1) // if the USART receive interrupt flag has been set
    11.     {  
    12.           Temp_Instruction = RCREG;
    13.  
    14.         if(Temp_Instruction == 'a')
    15.         {
    16.              LATBbits.LATB0 = 1;   // RB-0 to High  
    17.              LATBbits.LATB1 = 1;   // RB-1 to High  
    18.  
    19.              RCREG = 0; //Empty register  
    20.         }
    21.  
    22.         if(Temp_Instruction == 'b')
    23.         {
    24.              LATBbits.LATB0 = 0;   // RB-0 to Low  
    25.              LATBbits.LATB1 = 0;   // RB-1 to Low
    26.  
    27.              RCREG = 0; //Empty register  
    28.         }
    29.     }
    30. }
    31.  
    32. }
     
    Last edited: Oct 24, 2013
Loading...