PIC 18F4550 serial communications with VB

(instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx

PIC 18F4550 serial communications with VB

Postby triode90 » Sun Nov 16, 2014 3:27 am

Hello,

I wrote a simple program in VB to communicate with my microcontroller (18F4550) via serial external (UART cp201) just to turn on four leds and then turn them off manually.
ric helped out on some of the code but am stuck at a compile error: "unable to resolve identifier "RCIF"

Using MPLABX and XC8 compiler.

xc.h is in my header file VB-LED.h

If someone has any ideas, will be much appreciated! :D

BTW- the 18f4550 is 8 bit correct?


Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include "VB-LED.h"

void main (void)
{
    TRISDbits.RD0 = 0;  //set portD bit 0 as output for pin RD0
    TRISDbits.RD1 = 0;  //set portD bit 0 as output for pin RD1
    TRISDbits.RD4 = 0;  //set portD bit 0 as output for pin RD4
    TRISDbits.RD5 = 0;  //set portD bit 0 as output for pin RD5
    OSCCON = 0x70;       //configure OSCCON register to internal oscilator
                        //check data sheet for this value

    while (1)
    {
      //program loop
    }
}
void config (void)
{
    // USART configuration
    TXSTAbits.TX9  = 0;    // 8-bit transmission
    TXSTAbits.TXEN = 1;    // transmit enabled
    TXSTAbits.SYNC = 0;    // asynchronous mode
    TXSTAbits.BRGH = 1;    // high speed
    RCSTAbits.SPEN = 1;    // enable serial port (configures RX/DT and TX/CK pins as serial port pins)
    RCSTAbits.RX9  = 0;    // 8-bit reception
    RCSTAbits.CREN = 1;    // enable receiver
    BAUDCONbits.BRG16 = 0; // 8-bit baud rate generator
    SPBRG = 51;            // "51" calculated using formula from table 20-1 in the PIC18F4550 datasheet
                           // 8MHz and 9600 baud for Asynchronous, BRGH=1 "high speed"
    TRISCbits.RC6 = 0; // make the TX pin a digital output
    TRISCbits.RC7 = 1; // make the RX pin a digital input


while (PIR1.RCIF == 0);    //wait until a character arrives
       
    {
        unsigned char buf = RCREG;    //read and save the character from the USART
        switch (buf)
        {
            case 'W':
                LATDbits.LATD0 = 1; //1= ON for pin RD0
                break;
            case 'R':
                LATDbits.LATD1 = 1; //1= ON for pin RD1
                break;
            case 'G':
                LATDbits.LATD4 = 1; //1= ON for pin RD4
                break;
            case 'Y':
                LATDbits.LATD5 = 1; //1= ON for pin RD5
                break;
            case 'S':
                PORTD = 0;         // 0= OFF for all pins port D
                break;

        } //end of "switch()" statement
    }
}
triode90
 
Posts: 1
Joined: Sun Nov 16, 2014 2:58 am

Re: PIC 18F4550 serial communications with VB

Postby vloki » Sun Nov 16, 2014 11:38 am

You forgot the bits in
while (PIR1.RCIF == 0); -->> while (PIR1bits.RCIF == 0);
vloki
Verified identity
 
Posts: 186
Joined: Wed May 28, 2014 8:42 am
Location: Germany
PIC experience: Professional 5+ years with MCHP products


Return to 16-Bit Core

Who is online

Users browsing this forum: No registered users and 14 guests

cron