ragi
Junior Member level 3
Hi,
I have started working on pic18f45k20 microcontroller and using pickit 3 as debugger.
I am doing simple echo program using uart with baud rate 115200 ,
The problem i am facing is , when i run my code , the hyperterminal starts taking some junk data continuously before i send any thing.
Can any one send echo code for pic18f45k20 ??
Here is my code ,
Thank you.
I have started working on pic18f45k20 microcontroller and using pickit 3 as debugger.
I am doing simple echo program using uart with baud rate 115200 ,
The problem i am facing is , when i run my code , the hyperterminal starts taking some junk data continuously before i send any thing.
Can any one send echo code for pic18f45k20 ??
Here is my code ,
Code:
//#define _XTAL_FREQ 8000000 //The speed of your internal(or)external oscillator
#define USE_AND_MASKS
//#include <xc.h>
//#include "config.h"
#include "p18f45k20.h"
#include <usart.h>
int i = 0 , j=0;
unsigned char UART1Config = 0, baud = 0;
unsigned char MsgFromPIC[] = "PIC Rocks\r";
void SetupClock(void);
void Delay1Second(void);
#pragma config FOSC = INTIO7, FCMEN = OFF, IESO = OFF // CONFIG1H
#pragma config PWRT = OFF, BOREN = SBORDIS, BORV = 30 // CONFIG2L
#pragma config WDTEN = OFF, WDTPS = 32768 // CONFIG2H
#pragma config LPT1OSC = ON, PBADEN = ON, CCP2MX = PORTC // CONFIG3H
#pragma config STVREN = ON, LVP = OFF, XINST = OFF // CONFIG4L
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF // CONFIG5L
#pragma config CPB = OFF, CPD = OFF // CONFIG5H
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF // CONFIG6L
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF // CONFIG6H
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF // CONFIG7L
#pragma config EBTRB = OFF
void main(int argc, char** argv) {
SetupClock(); // Internal Clock to 8MHz
TRISCbits.RC6 = 0; //TX pin set as output
TRISCbits.RC7 = 1; //RX pin set as input
UART1Config = USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_BRGH_HIGH & USART_SINGLE_RX ;
baud = 0x33;
OpenUSART(UART1Config,baud);
// for( j=0 ;j<3;j++) //infinite loop
while(1)
{
putsUSART(MsgFromPIC);
Delay1Second();
}
}
void SetupClock()
{
OSCCONbits.IRCF0 = 0;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF2 = 1;
}
void Delay1Second()
{
for(i=0;i<100;i++);
}
Thank you.
Last edited by a moderator: