Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/12/06 11:06
Read: times


 
#120073 - help needed for uart c8051f005
Hello frineds
I wrote following code for c8051f005 which is interrupt driven
for crystal frequency 11.0592MHz and baud rate = 9600;
I use hypertemminal for testing with 9600baud rate/8 bit/noparity/and flow controll=none
I also short the (pin 7 and pin 8),pin4 and pin6 for pc end
I found that i receive garbage on pc screen;

Is there is any thing wrong with code?

#include<c8051f000.h>
#include<string.h>
//CRYSTAL=11.0592MHz BAUDRATE=9600
unsigned char TX_BUF[25]={"012345678901234567890123"};
unsigned char RX_BUF[25];
unsigned char TX_CNT,RX_CNT;
void DWELL(unsigned int k);
void UART0_Init (void);

void main(void)
{
//watch dog disable//
s WDTCN=0XDE;
WDTCN=0XAD;

XBR0=0x07;//Enable SM Bus/SPI/UART/
XBR1=0X04;
XBR2=0X40;

PRT0CF=0X5C;//Configure port Pins P0 SMbus/SPI/UART
DWELL(65000);

OSCXCN = 0x67;

DWELL(10000);
DWELL(10000);//I get external osillator is stable

OSCICN |= 0X08;//EXTERNAL CRYSTAL AS SYSTEM CLOCK
OSCICN &=0XFB;

DWELL(5000);

TI=0;
RI=0;
PCON|=0X80;//DOUBLE THE BAUD RATE
SCON=0X40;

CKCON=0X00;// TIMER1 CLOCK=SYSTEMS CLOCK/12
TMOD=0X20;//TIMER1 IN AUTO RELOAD MODE
TH1=0XFA;
TR1=1;
TX_CNT=0;
ES=1;
EA=1;
TI=1;
REN=1;
while(1);
}
void DWELL(unsigned int k)
{
unsigned int u;
for(u=0;u<k;u++)
{
;
}
}


void isr_uart(void) interrupt 4
{
if(TI)
{
TI=0;
{
if(TX_CNT<25)
{
SBUF=0X30;//TX_BUF[TX_CNT];
TX_CNT++;
}else
{
TX_CNT=0;
TI=1;
}


}
}
if(RI)
{
RI=0;
RX_BUF[RX_CNT]=SBUF;
RX_CNT++;
if(RX_CNT==25)
{
RX_CNT=0;
}
}
}

//best regards
//satish munot

List of 4 messages in thread
TopicAuthorDate
help needed for uart c8051f005            01/01/70 00:00      
   Code problems            01/01/70 00:00      
      More Code Problems            01/01/70 00:00      
         probelm solve            01/01/70 00:00      

Back to Subject List