On 19.08.2016 23:11, benja...@southpole.se wrote:
> Hi, I created some small examples for the C8051F***
> 
> https://github.com/merbanan/C8051F300_examples
> 
> I tried these examples on a F340 but something doesnt work correctly when
> I send data over the serial port and sdcc. If I use Keil it works fine.
> And the same code works fine on the F300.
> 
> I'd be happy to supply you with hardware if you are interested to
> investigate the issue. Currently I use Keil which works with what I want
> to do, but doing open stuff and needing a non free compiler causes an itch
> I want to scratch.
> 
> MvH
> Benjamin Larsson
> 

I have serial output on the C8051F330 board RDM6300 working via
putchar() (see attached code). But whenever I try to use printf(),
everything gets messed up: Garbage output on the serial line or the
device resets.

I've tried different memeory models and reentrency, but don't see a
change in behaviour. printf() takes us over 4K of flash, but the
C8051F330 has 8KB, so we should be ok.

Philipp

#include <stdio.h>

__sfr __at(0xe1) XBR0;
__sfr __at(0xe2) XBR1;
__sfr __at(0xa4) P0MDOUT;
__sfr __at(0xd9) PCA0MD;

__sfr __at(0x88) TCON;
__sfr __at(0x89) TMOD;
__sfr __at(0x8b) TL1;
__sfr __at(0x8d) TH1;

__sfr __at(0x98) SCON0;
__sfr __at(0x99) SBUF0;

int putchar(int c)
{
	while(!(SCON0 & 0x02));
	SCON0 &= ~0x02;
	SBUF0 = c;
	return (c);
}

unsigned char _sdcc_external_startup(void)
{
    PCA0MD = 0; // Disable watchdog timer

    return 0;  // perform normal initialization
}

void main(void)
{
	unsigned long int i = 0;

	// Initialize I/O pins
	P0MDOUT = 0x10;				// Set port P0.4 (Uart tx) to push-pull
	XBR0 = 0x01;				// UART0 on P0.4 and P0.5
	XBR1 = 0x40;				// Enable push/pull for Tx

	// Configure UART for 1200 baud, 8 data bits, 1 stop bit.
	TMOD = 0x20;
	TH1 = 150;
	TCON |= 0x40;
	SCON0 = 0x42;

	for(;;)
	{
putchar('A');
putchar('B');
putchar('C');
		for(i = 0; i < 147456; i++); // Sleep
putchar('D'); // Proof that its not just the watchdog resetting us
		for(i = 0; i < 147456; i++); // Sleep
printf("Hello World!\n");
		for(;;); // Proof that the device gets reset during printf()
	}
		
}




------------------------------------------------------------------------------
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to