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 pic18f46k22

Status
Not open for further replies.

shreyas_patel21

Full Member level 3
Full Member level 3
Joined
Jan 4, 2011
Messages
181
Helped
15
Reputation
30
Reaction score
14
Trophy points
1,298
Activity points
2,325
hello everyone
i am trying to interface pic18f46k22 with pc
i used the code below from library.
but the hyperterminal shows random data
any suggestion would be helpful

Code:
#include<stdio.h>
#include<p18f46k22.h>
#include "usart.h"

//#define USE_OR_MASKS

unsigned char Rxdata[8];
unsigned char Txdata[] = "test";
void delay(unsigned int i)
{
	
	for(;i>1;i--);
}
void main(void)
{
    unsigned char config=0,spbrg=0,baudconfig=0,i=0,j='a';
	OSCCONbits.IRCF0 =1;
	OSCCONbits.IRCF1 = 1;
	OSCCONbits.IRCF2 = 1;
	OSCTUNEbits.PLLEN = 1;

    ANSELA = 0x00;
    ANSELB = 0x00;
    ANSELC = 0x00;
    ANSELD = 0x00;
    ANSELE = 0x00;
    
	TRISA=0x00;
	TRISB=0X0000;	//output
    TRISC=0Xffff;	//output
    TRISD=0X00;	//output
    TRISE=0X00;	//output
    
    Close1USART();  //turn off usart if was previously on

//-----configure USART -----
    config = USART_TX_INT_OFF | USART_RX_INT_OFF | USART_ASYNCH_MODE | USART_EIGHT_BIT | USART_SINGLE_RX | USART_BRGH_LOW;
//-----SPBRG needs to be changed depending upon oscillator frequency-------
    spbrg = 51;                    //At 8Mhz of oscillator frequency & baud rate of 2400.

    Open1USART(config, spbrg);        //API configures USART for desired parameters

    baudconfig =  BAUD_8_BIT_RATE | BAUD_AUTO_OFF;
    baud1USART (baudconfig);

//------USART Transmission ----
    while(Busy1USART());             //Check if Usart is busy or not
    puts1USART((char *)Txdata);                //transmit the string



    Close1USART();
    while(1);                        //end of program

}
 

check your bit rate:
- Does your PC configured for 2400 bps?
- Does your oscillator frequency is 8Mhz as in assumed by the code?

does both your PIC and PC uarts configured the same: bit-rate, stop bits, data length, parity bits etc. ?
 
thanks yuvko!

i have already solved it and problem was same as you said!
i changed oscillator configuration bits and baud rate in code.
also i used custom functions instead of using library functions.
now i can send and receive data.
 
thanks yuvko!

i have already solved it and problem was same as you said!
i changed oscillator configuration bits and baud rate in code.
also i used custom functions instead of using library functions.
now i can send and receive data.

Can you please upload the corrected code? i am in some troubles.
 

Check your communication settings (bit, baud rate...) they must match the pc settings)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top