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

I've download your code and will attempt to fix the problem for you. If I have the time I test the VB.NET app as well.
 

OK,

I've download your code and will attempt to fix the problem for you. If I have the time I test the VB.NET app as well.

ok.....really really thanks so much~~~
 

Hi,

I saw you code.
put USART_RX_INT_ON on the openUSART,
Also, the irqHandler must be the most shorter possible.
Put the readUSART on a static or global variable and use it on the while(1) { }body.
The initialization code must be placed before the while(1) { } body because of you cab trouble the program, if it is always used on while(1) { } body.
Regards
JoseMiguel
 

Thanks for helping me checking the coding....but my coding got the error at
void rx_int (void)
{
_asm goto rx_handler _endasm
}

I don't know what is the problem of this coding....
 

Hi,
I have a build succeeded with this code::

#include <p18C452.h>
#include <usart.h>

void rx_handler (void);
static unsigned char get;

#pragma code rx_interrupt = 0x8
void rx_int (void)
{
_asm goto rx_handler _endasm
}
#pragma code

#pragma interrupt rx_handler
void rx_handler (void)
{
if (PIR1bits.RCIF) // interrupt from the receive USART
{
/* Get the character received from the USART */
get = ReadUSART();


PIR1bits.RCIF = 0;
}
}
#pragma code
void main(void)
{
TRISC = 0;
// configure USART
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,20 );

/* Enable interrupt priority */
RCONbits.IPEN = 1;
/* Make receive interrupt high priority */
IPR1bits.RCIP = 1;
/* Enable all high priority interrupts */
INTCONbits.GIEH = 1;

while(1)
{
if (get == '1' ) PORTC = 1;
else if (get == '2') PORTC = 0;
else if (get == '3') PORTC = 1;
else if (get == '4') PORTC = 0;
else if (get == '5') PORTC = 1;
else if (get == '6') PORTC = 0;
else if (get == '7') PORTC = 1;
else if (get == '8') PORTC = 0;
}
CloseUSART();
}

Regards
JoseMiguel
 

Thanks joseMiguel....may i know what is my coding problem intially and i am plan to use this coding to do serial communication by using RS232...Is it need to set for the Baud rate, port name and and other in this coding??
 

Hi,
Sorry i forget to put USART_RX_INT_ON and it misses a semicolon on void rx_handler (void); on your original code.

OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,20 );

For the baud rate, you need to see on the datasheet, the values to put on console.
If the value is not corrsponding to the transmitter you should have strange characters.

Regards
JoseMichel
 

hi, can anyone give information on the configuration RX and TX in pic18f4550 assembly language?
i'm using MPLAB. This is my 1st time on programming serial communication in pic18f4550.
 

can anyone give information on the configuration RX and TX in pic18f4550 assembly language?
i'm using MPLAB. This is my 1st time on programming serial communication in pic18f4550.

I want to caution you as to one of the most frequently encountered problems when programming the PIC18F series, particularly when the configuring the USART.

Understanding how to correctly configure the PIC's clock/oscillator and PLL,as well as knowing the actual system clock frequency that the PIC is currently operating, is absolutely critical.

A successful serial port connection is largely dependent on the correct BAUD rate being generated which is wholly dependent on the correct value being loaded into the SPBRG register.

The SPBRG register value can only be properly calculated if the actual system clock frequency is known.

Quite often individuals believe their PIC18F series device is operating at a system clock frequency of 4MHz, when in fact it is operating at 48MHz, therefore the calculated SPBRG register value is incorrect and finally resulting in an unsuccessful serial port connection.

If you post your code and schematic of your design, I should be able to advise you further.

BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top