shreyas_patel21
Full Member level 3
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
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
}