Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc-extra / historygraphs / hello-stm8 / hello.c
blob2750dcb65df3499e9ffbe45f46b73b0c4f21fd77
1 // Source by Philipp Krause under CC0 1.0
3 // A "Hello, World!"-Program. We use it to make the board
4 // output something that can not be mistaken for output
5 // From a benchmark.
7 #include <stdint.h>
8 #include <stdio.h>
10 #define PD_DDR (*(volatile uint8_t *)0x5011)
11 #define PD_CR1 (*(volatile uint8_t *)0x5012)
13 #define CLK_CKDIVR (*(volatile uint8_t *)0x50c6)
14 #define CLK_PCKENR1 (*(volatile uint8_t *)0x50c7)
16 #define USART3_SR (*(volatile uint8_t *)0x5240)
17 #define USART3_DR (*(volatile uint8_t *)0x5241)
18 #define USART3_BRR1 (*(volatile uint8_t *)0x5242)
19 #define USART3_BRR2 (*(volatile uint8_t *)0x5243)
20 #define USART3_CR2 (*(volatile uint8_t *)0x5245)
21 #define USART3_CR3 (*(volatile uint8_t *)0x5246)
23 #define USART_CR2_TEN (1 << 3)
24 #define USART_CR3_STOP2 (1 << 5)
25 #define USART_CR3_STOP1 (1 << 4)
26 #define USART_SR_TXE (1 << 7)
28 #if defined(__CSMC__) // Cosmic weirdness
29 char putchar(char c)
31 while(!(USART3_SR & USART_SR_TXE));
33 USART3_DR = c;
35 return c;
37 #elif defined(__RCSTM8__) // Raisonance weirdness
38 int putchar(char c)
40 while(!(USART3_SR & USART_SR_TXE));
42 USART3_DR = c;
44 return(c);
46 #elif defined(__SDCC) && __SDCC_REVISION < 9624 // Old SDCC weirdness
47 void putchar(char c)
49 while(!(USART3_SR & USART_SR_TXE));
51 USART3_DR = c;
53 #else // Standard C
54 int putchar(int c)
56 while(!(USART3_SR & USART_SR_TXE));
58 USART3_DR = c;
60 return(c);
62 #endif
64 void main(void)
66 unsigned long i = 0;
68 CLK_CKDIVR = 0x00; // Set the frequency to 16 MHz
69 CLK_PCKENR1 = 0xFF; // Enable peripherals
71 PD_DDR = 0x20; // Put TX line on
72 PD_CR1 = 0x20;
74 USART3_CR2 = USART_CR2_TEN; // Allow TX and RX
75 USART3_CR3 &= ~(USART_CR3_STOP1 | USART_CR3_STOP2); // 1 stop bit
76 USART3_BRR2 = 0x03; USART3_BRR1 = 0x68; // 9600 baud
78 for(;;)
80 printf("Hello, World!\n");
81 for(i = 0; i < 147456; i++); // Sleep