Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

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??
 

arbj

Full Member level 4
Joined
Oct 5, 2008
Messages
238
Helped
31
Reputation
62
Reaction score
20
Trophy points
1,298
Activity points
2,601
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

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
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
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,508
  • Like
Reactions: chuat

    chuat

    points: 2
    Helpful Answer Positive Rating

upand_at_them

Full Member level 2
Joined
Feb 26, 2010
Messages
131
Helped
21
Reputation
42
Reaction score
21
Trophy points
1,298
Location
Pennsylvania, U.S.
Activity points
1,942
Wow, that looks pretty straightforward. In WinXP with VB6 you have to get a third-party library to allow access to the serial port.
 

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
thanks you....those link has enable me to start in the right direction.!! thanks so much!!!
 

arbj

Full Member level 4
Joined
Oct 5, 2008
Messages
238
Helped
31
Reputation
62
Reaction score
20
Trophy points
1,298
Activity points
2,601
you could also use MPASM assembler, serial communication is easily achieved with assembly, no need for C compilers
 

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
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?
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,508
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?
 

arbj

Full Member level 4
Joined
Oct 5, 2008
Messages
238
Helped
31
Reputation
62
Reaction score
20
Trophy points
1,298
Activity points
2,601
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.
 

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
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.
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,508
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

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
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
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,508
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)

MPLAB C Compiler for PIC18 MCUs Page with Docs

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
 

joseMiguel

Member level 5
Joined
Jan 10, 2011
Messages
83
Helped
10
Reputation
20
Reaction score
10
Trophy points
1,288
Location
Montpellier FRANCE
Activity points
1,864
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
 

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
yes...thanks so much...finally i can now know how to start it. :)
 

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
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


bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,508
What exactly is the error you're encountering? Are you getting any communication at all?

Please elaborate?
 

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
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top