Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

USART C18 Issued(RFID)

Status
Not open for further replies.
usart transmitting garbage values!!

hi,
i am trying to test my 18f4550 hardware usart functions through windows hyperterminal...but it doesn't seem to respond.
sometimes the 18f4550 transmits some garbage values.please help!
i am programming the code using the usb bootloader software.

my external crytal is 11.092 MHZ.
so for 2400 baud rate

spbrg = (11092000/2400)/64 - 1 = 71.21

------------------------code---------------------------

#pragma udata
extern void _startup (void);
#pragma code _RESET_INTERRUPT_VECTOR = 0x000800
void _reset (void)
{
_asm goto _startup _endasm
}
#pragma code
#pragma code _HIGH_INTERRUPT_VECTOR = 0x000808
void _high_ISR (void)
{
;
}
#pragma code _LOW_INTERRUPT_VECTOR = 0x000818
void _low_ISR (void)
{
;
}
#pragma code
#include <p18f4550.h>
#include <usart.h>
void main(void)
{
OpenUSART( USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW,71 );
while(1)
{
putcUSART('f');
while (BusyUSART());
}
CloseUSART();
}

is there a problem with the code???
 
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++;
}

}
 

Attachments

  • Blink.c
    3.2 KB · Views: 230
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top