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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/21/09 18:29
Modified:
  06/21/09 18:51

Read: times


 
#166313 - UART code porting to SDCC
Hi

I am working on porting a relatively simple piece of UART Code from Keil/Raisonance to SDCC. As I was expecting, this piece of code works perfect on Keil/Raisonance but does not on SDCC.
-On Raisonance, it sends out the character 'D' 100 times
-On SDCC, it sends out the character 'D' only once. (and thus indicating something to do with ISR)
-I am using the standard header files provided by each compiler
-I have verified that the registers used in my program have same values in the header files for both compilers. I have the values in my source code for comparison.
-Hardware target board is common

That was my first step to identify any difference

My next step as Erik suggests
- Slow down
- Go back and read the bible :-)

Any directions/tips/pointers or corrections in my code would be helpful


..
//#include <REG52.h>		/*  Use with Keil or Raisonance */
//#include <at89x52.h>		/*  Use with SDCC */
#include <p89v51rd2.h>		/*  Use with SDCC */
#include <stdio.h>
#include <string.h>

xdata char rcvbuf[256];
int ldptr,flptr,xmt_flag,opti_fooler;

void serial_intr(void) interrupt 4
{
	if(TI==1)
	{	TI=0;
		xmt_flag=1;
	 }
	if(RI==1)
	{ 	RI=0;
	  	rcvbuf[ldptr++]=SBUF; //get 1st char in array rcvbuf[]
		if(ldptr>=256)
		ldptr=0;				//to chk overflow of buffer
	}
}
 
void uart_send(char c)
{	
	xmt_flag=0;
	SBUF=c;
	//while(xmt_flag==0)
	while(1)
	{
		if ( xmt_flag != 0)
			break;
		else
			opti_fooler++;
	}
} 
 
void init_port(void)
{	
	RCAP2H=0xff;
	RCAP2L=0xFd;	//for 115kbps
	T2CON = 0x34;
	SCON = 0x50;
	IE = 0x90;
}
void main (void)
{
	int i;	
	init_port();
 	for (i = 0; i < 100;  i++)
 	{
 		uart_send('D');
 	}
	while(1);
}


#ifdef NEVER_DEFINED


Definitions for SDCC
/*  SCON  */
__sbit __at (0x98) RI   ;
__sbit __at (0x99) TI   ;

/* T2CON */
__sfr __at (0xC8) T2CON ;

/* RCAP2 L & H */
__sfr __at (0xCA) RCAP2L  ;
__sfr __at (0xCB) RCAP2H  ;

__sfr __at (0xA8) IE   ;
__sfr __at (0x99) SBUF ;

//--------------------
Definitions for Raisonance
/*  SCON  */
at 0x99 sbit TI    ;
at 0x98 sbit RI    ;

at 0xC8 sfr T2CON ;
at 0xCA sfr RCAP2L;
at 0xCB sfr RCAP2H;

at 0xA8 sfr IE    ;
at 0x99 sfr SBUF  ;

#endif 











 



List of 17 messages in thread
TopicAuthorDate
UART code porting to SDCC            01/01/70 00:00      
   doesn't SDCC warn about line 36?            01/01/70 00:00      
      that's it            01/01/70 00:00      
         ah ha            01/01/70 00:00      
            Don't blame the optimiser!            01/01/70 00:00      
      doesn't SDCC warn about line 36            01/01/70 00:00      
         hmmm            01/01/70 00:00      
         modified dog            01/01/70 00:00      
   I cannot remember now            01/01/70 00:00      
   xmt_flag., why "int"?            01/01/70 00:00      
      if you want to use it as "int" / "char"            01/01/70 00:00      
   You destroy succeding putchar()'s            01/01/70 00:00      
      "Volatile" Helps            01/01/70 00:00      
         "bit" is more useful            01/01/70 00:00      
            buzzzzz            01/01/70 00:00      
               family            01/01/70 00:00      
            stdbool            01/01/70 00:00      

Back to Subject List