Pic184550 usart

Thread Starter

Dritech

Joined Sep 21, 2011
901
Hi all,

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

Rich (BB code):
void main(void) 
{

TRISC.RC7= 1;      // Make UART RX pin input

TRISC.RC6= 0;      // Make UART TX pin output

/* asynchronous mode, 8-bit data, HIGH baud rate, transmit enabled */

TXSTA = 0X24;

/* 9600 BAUD RATE, Fosc=10MHZ, SO SPBRG VALUE IS SET AS 0X40 */

SPBRG = 0X40;

/* serial port enable bit is set HIGH */

RCSTA.SPEN = 1;

 

TXREG = 'S';      // Data loaded into TXREG Register

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.
 

Attachments

Thread Starter

Dritech

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

Thread Starter

Dritech

Joined Sep 21, 2011
901
Hi again,

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

Rich (BB code):
void main(void)
{
   Configurate_USART();
   
   char Temp_Instruction;

while(1)
{

   if(PIR1bits.RCIF == 1) // if the USART receive interrupt flag has been set
    {  
          Temp_Instruction = RCREG;

        if(Temp_Instruction == 'a') 
        {
             LATBbits.LATB0 = 1;   // RB-0 to High   
             LATBbits.LATB1 = 1;   // RB-1 to High  

             RCREG = 0; //Empty register   
        }

        if(Temp_Instruction == 'b') 
        {
             LATBbits.LATB0 = 0;   // RB-0 to Low   
             LATBbits.LATB1 = 0;   // RB-1 to Low 

             RCREG = 0; //Empty register   
        }
    } 
}

}
 
Last edited:
Top