Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Serial communication in PIC 18F4550

Status
Not open for further replies.

chuat

Member level 1
Joined
May 11, 2011
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,559
hi, Can anybody help me solve in serial communication between PIC18F4550 and laptop? I am currently doing the project the use vb 2010 in laptop to communicate with PIC 18F4550 to trigger on the LED light. But i don't know how to program the PIC 18F550 in order to communicate with vb 2010. Can anyone help me??
 

what compiler/assembler are you using to program the PIC ??

The serial interface in the 18F4550 is simple enough to program, have you developed any code ??

Use the Serial communication control in VB 2010.
 
  • Like
Reactions: chuat

    chuat

    Points: 2
    Helpful Answer Positive Rating
I am currently use mplab IDE to program the PIC......i havent start do the program yet.....because don't know how to start....did u have any example or tutorial can help me ? thanks
 

Depending on the PIC compiler/assembler you're using:

**broken link removed**

**broken link removed**

**broken link removed**

Serial Port Interfacing with VB.net 2010

Let me know if these links and code don't get you started in the right direction.
 
  • Like
Reactions: chuat

    chuat

    Points: 2
    Helpful Answer Positive Rating
Wow, that looks pretty straightforward. In WinXP with VB6 you have to get a third-party library to allow access to the serial port.
 

thanks you....those link has enable me to start in the right direction.!! thanks so much!!!
 

you could also use MPASM assembler, serial communication is easily achieved with assembly, no need for C compilers
 

is here anyone know the coding like configure the PIC 18F4550 in order to receive data from VB and also the coding for serial intterupt?
 

I'm not sure what your requirements are exactly, could you give an example application or elaborate more on the topic?

Also are we still talking VB.NET or VB6?
 

I assume you are using MPASM. Read the MPASM tutorials in the help file, read how an assembler program is made, also search the internet for a small MPASM program that flashes a LED. Read the datasheet for the device you are using and make a simple hardware schematic uses a few LEDs, you can then write programs to play around with these LEDs.

Once you learnt the basics you can go on to the advanced part like interrupts.

The datasheet for the device would also contain sample code for setting up the serial port module in the chip, read this carefully.

MPASM should not be difficult to master, you can easily do it in a few days.

If you have difficulty understanding a program, post your queries here. You could also post them in the Microchip forum.
 

Here are some very good tutorials covering programming PICs with both assembly and C:

**broken link removed**

Another good PIC site concentrating on PIC C programming:

PIC Sample Code in C

Hope these sites help you with your project.
 

Actually i am doing the project that call power monitoring system based on zigbee technology that function like i can control the LED at the VB interface by sending command to mircocontroller through zigbee wireless but for now i am just testing using VB to trigger on the LED by sending command to PIC without zigbee. That why i need to know how the coding for PIC to receive command from VB and the coding for VB to send the command to PIC to trigger on the LED.

---------- Post added at 21:02 ---------- Previous post was at 20:59 ----------

Actually i am using MPLAB IDE V8.63 for program the PIC. I am more familiar with this compiler since i am doing line follower using this compiler before. But just i don't know the coding for serial interface of PIC.
 

Are you using MPLAB with MPASM assembler, the C18 C compiler or another C compiler?

Let me know the language used with the PIC, assembler or C and if C whose compiler.

You are using VB.NET 2010 on the PC side correct?
 
  • Like
Reactions: chuat

    chuat

    Points: 2
    Helpful Answer Positive Rating
Thanks so much for your help~~ya..i am using MPLAB with MPASM assembler with c 18 c compiler. The pic side i am using c language with c compiler while the PC side ya i am using vb.net 2010
 

Ok,

An almost painless method of establishing a serial connection with the 18F series and C18 is the use of the C18 libraries:

MPLAB® C18 C COMPILER LIBRARIES (PDF)

**broken link removed**

The documenation PDF contains this simple example:

Code:
#include <p18C452.h>
#include <usart.h>
void main(void)
{
    // configure USART
   OpenUSART( USART_TX_INT_OFF &
                    USART_RX_INT_OFF &
                    USART_ASYNCH_MODE &
                    USART_EIGHT_BIT &
                    USART_CONT_RX &
                    USART_BRGH_HIGH,
                    25 );
   while(1)
   {
        while( ! PORTAbits.RA0 ); //wait for RA0 high
        WriteUSART( PORTD ); //write value of PORTD
        if(PORTD == 0x80) // check for termination
        break; // value
   }

  CloseUSART();

}

The code waits for PORTAbits.RA0 to go high and the grabs the value on PORTD and send it over the serial connection to whom ever, possibly your VB.NET program.

All you need to change to run the example of your PIC is:

#include <p18C452.h>

To

#include <p18C4550.h>


Code:
OpenUSART( USART_TX_INT_OFF &
                    USART_RX_INT_OFF &
                    USART_ASYNCH_MODE &
                    USART_EIGHT_BIT &
                    USART_CONT_RX &
                    USART_BRGH_HIGH,
                    [COLOR="red"]25[/COLOR] );

And the value 25 is calculated from your system clock frequency, depends on the crystal, ceramic resonator, etc used in your design.

There are other examples of using the USART in the C18 Library Doc PDF available in the link given previously.

Do you want an example in assembler?

I'll also try and find an example using VB.NET with the PIC 18F series.

Ciao
 
Hello,

Here below a small interrupt handler code for usart receiving characters.

//-------------------------------------------
void InterruptHandlerLow(void);

#pragma code InterruptVectorLow=0x18
void InterruptVectorLow()
{
_asm
goto InterruptHandlerLow
_endasm

}
#pragma code

#pragma interrupt InterruptHandlerLow
void InterruptHandlerLow()
{
char j=0;
//Check which interrupt flag caused the interrupt.
//Service the interrupt
//Clear the interrupt flag
//Etc.
if(PIR1bits.RCIF)
{
j=ReadUSART();
if(index>31) index=0;
RS232toBuffer[index]= j;

index++;
PIR1bits.RCIF=0;
}

} //This return will be a "retfie", since this is in a #pragma interruptlow section


#pragma code
//---------------------------------------

....
RCONbits.IPEN=1; // enable priority interrupts
IPR1bits.RCIP=0; // low priority interrupt for EUSART
INTCONbits.GIEL=1; // Enables all low priority peripheral interrupts when IPEN =1
INTCONbits.GIEH=1; // Enables all high priority interrupts when IPEN =1 to see if is it needed
 

yes...thanks so much...finally i can now know how to start it. :)
 
this is the coding of serial communication between PIC and VB 2010......But there is some error inside hope anyone can help me correct it??thanks
 

Attachments

  • serial communication.rar
    69.1 KB · Views: 131

What exactly is the error you're encountering? Are you getting any communication at all?

Please elaborate?
 

in the MPLAB the coding i write can't built at all it say got error at the intterupt part...but i can't solve it about the error so need help at that part......i havent test got communication or not yet since the coding i write for PIC got some error that i don't know how to solve~~~
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top