Hi guys,
I have a big problem in serial communication in 18f452
After i programe the mcu to send a string to PC via RS 232, PC dont receive what i sent.it displays only two other characters in hyper terminal .
I ll give my code. Its in C18
my MCU is 18f452 in 10 MHz
i use a bootloader
Please help me guys
thank you
/* This program Blinks the LEDs in PORTB */
#include <stdio.h>
#include <P18CXXX.h>
#include <timers.h>
#include <usart.h>
#pragma code page // This code make sure the program starts from 0x0004, not from 0x0000
#pragma config WDT = OFF
//----------------------For LCD-----------------------------------------
#define RS PORTEbits.RE0
#define dirRS TRISEbits.TRISE0
#define RW PORTEbits.RE1
#define dirRW TRISEbits.TRISE1
#define E PORTEbits.RE2
#define dirE TRISEbits.TRISE2
#define DATALCD PORTD
#define dirDATA TRISD
#define LCDBusy PORTDbits.RD7
void LCDdata (unsigned char);
void busylcd(void);
void LCDinit (void);
void LCDDelay( void );
void lcdcmd(unsigned char);
void stringtoLCD(unsigned char *m);
//For USART
void OpenUSART( unsigned char config,unsigned int spbrg);
void putsUSART( char *data );
//---------------------------------------------------------------------
void delay (void) // user define delay function
{
long i,C;
for (i=0;i<3000;i++)
C = C+1;
}
void main (void) // main function
{
char LCDString[6]="kasun";
int integer=0;
char *LCDStringPtr;
LCDStringPtr=&LCDString[0];
TRISD = 0;
PORTD = 0;
TRISB = 0; // Port,pin direction configuration
PORTB = 0;
TRISC = 0;
PORTC = 0;
TRISCbits.TRISC7 = 1; // make sure this pin is input
ADCON1=2;
LCDinit();
//for USART
OpenUSART( USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH,64);
while (BusyUSART());
PORTB = 255;
putsUSART(LCDStringPtr);
while (1) // this is how to make a never ending loop.
{
lcdcmd(0x1);
lcdcmd(0x2);
stringtoLCD(LCDString);
delay();
}
}
//////////////////////////////////////////////////////////////////////////////////////
//LCD finctions------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////////////
void LCDdata (unsigned char value)
{
busylcd();
TRISD = 0;
DATALCD = value;
RS=1;
RW=0;
E=1;
LCDDelay();
E=0;
}
//--------------------------------------------------------------------------------------
void LCDinit(void)
{
TRISE=0;
lcdcmd(0x38); //set 8-bit mode and 2 lines
lcdcmd(0x10); //cursor move & shift left
lcdcmd(0x06); //entry mode = increment
lcdcmd(0x0c); //display on - cursor blink on
lcdcmd(0x01); //clear display
}
//-------------------------------------------------------------------------------------
void busylcd(void)
{
RS=0;
RW=1;
TRISD=255;
E=0;
LCDDelay();
E=1;
while(LCDBusy==1){
E=0;
LCDDelay();
E=1;
}
}
//-------------------------------------------------------------------------------------
void lcdcmd(unsigned char temp)
{
busylcd();
RS=0;
RW=0;
TRISD=0;
DATALCD=temp;
E=1;
LCDDelay();
E=0;
}
//--------------------------------------------------------------------------------------
void LCDDelay(void)
{
int i=0;
for (i=0;i<250;i++);
}
//---------------------------------------------------------------------------------------
void stringtoLCD(unsigned char *m)
{
unsigned char i;
i = 0;
while(m != 0)
{
LCDdata(m);
i++;
}
}