Am 25.09.2013 12:45, schrieb Rogier Wolff:
> 
> Hi,
> 
> I just got myself an STM8 discovery board. I'm trying to get the
> development environment working. I cloned the SVN repository for the
> latest version of SDCC.
> 
> I found an stm8 example, at: 
> https://github.com/vdudouyt/sdcc-examples-stm8/
> 
> The blinky.c file starts out by including the stm8l.h header. sdcc
> cannot find this file. And neither can I. 
> 
> Where is that header supposed to come from?
> 
> (I have an STM8S processor, not STM8L, but I'm hoping that findind
> stm8l.h will help me find stm8s.h too... :-) )
> 
>       Roger. 
> 

I have attached my own blinky example. This one is a bit more
complicated, since it uses a timer instead of a delay loop. It does not
use any stm8-specific header (the header file just contains some
defines). It ist meant for the STM8L, but by adjusting the defines,
could be used for STM8S.

Philipp

#include <stdint.h>

#define PE_ODR	(*(volatile uint8_t *)0x5014)
#define PE_DDR	(*(volatile uint8_t *)0x5016)
#define PE_CR1	(*(volatile uint8_t *)0x5017)

#define CLK_DIVR	(*(volatile uint8_t *)0x50c0)
#define CLK_PCKENR2	(*(volatile uint8_t *)0x50c4)

#define TIM1_CR1	(*(volatile uint8_t *)0x52b0)
#define TIM1_PCNTRH	(*(volatile uint8_t *)0x52bf)
#define TIM1_PCNTRL	(*(volatile uint8_t *)0x52c0)
#define TIM1_PSCRH	(*(volatile uint8_t *)0x52c1)
#define TIM1_PSCRL	(*(volatile uint8_t *)0x52c2)

unsigned int clock(void)
{
	unsigned char h = TIM1_PCNTRH;
	unsigned char l = TIM1_PCNTRL;
	return((unsigned int)(h) << 8 | l);
}

int main() {
	CLK_DIVR = 0x00; // Set the frequency to 16 MHz
	CLK_PCKENR2 |= 0x02; // Enable clock to timer

	// Configure timer
	// 1000 ticks per second
	TIM1_PSCRH = 0x3e;
	TIM1_PSCRL = 0x80;
	// Enable timer
	TIM1_CR1 = 0x01;

	// Configure pins
	PE_DDR = 0x80;
	PE_CR1 = 0x80;
	// Loop
	do {
		PE_ODR &= 0x7f;
		if (clock() % 1000 <= 500)
			PE_ODR |= 0x80;
	} while(1);
}

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to