Society of Robots - Robot Forum

Software => Software => Topic started by: junior000 on March 24, 2009, 10:09:55 AM

Title: 18F4550 TRANSMITTING SOME GARBAGE VALUES
Post by: junior000 on March 24, 2009, 10:09:55 AM
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???
Title: Re: 18F4550 TRANSMITTING SOME GARBAGE VALUES
Post by: Admin on April 08, 2009, 01:37:01 AM
Did you ever get it to work?
Title: Re: 18F4550 TRANSMITTING SOME GARBAGE VALUES
Post by: junior000 on April 24, 2009, 01:27:37 AM
hi...
paul helped me with a way to find the baud rate...
i used the following code





char n;int value = 0,temp;
char d1,d2,d3;
void main(){
TRISCbits.TRISC7 = 1;
TRISCbits.TRISC6 = 1;   

while(1)
{
OpenUSART( USART_TX_INT_OFF &  USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW,value );
putrsUSART("VALUE");
while(BusyUSART());
temp  = value;
d1 = temp%10;
temp = temp/10;
d2 =  temp%10;
temp = temp/10;
d3 = temp%10;

d1 = d1|0x30;d2 = d2|0x30;d3= d3|0x30;
putcUSART(d3);
while (BusyUSART());
putcUSART(d2);
while (BusyUSART());
putcUSART(d1);
while (BusyUSART());
putrsUSART("\n\r");
while (BusyUSART());
value++;
if (value==500){value = 0;CloseUSART();Delay10KTCYx(100);}
   
}
}

the value turned out to be 77 for 2400 baud rate :)