1 #include <stdint.h> 2 #include <stdio.h> 3 4 #define DEVICE DEV_STM8S208 5 6 #include "stm8.h" 7 putchar(int c)8int putchar(int c) 9 { 10 while(!(USART->sr & USART_SR_TXE)); 11 12 USART->dr = c; 13 return c; 14 } 15 main(void)16void main(void) 17 { 18 unsigned long i = 0; 19 20 CLK->ckdivr = 0x00; // Set the frequency to 16 MHz 21 CLK->pckenr1 = 0xFF; // Enable peripherals 22 23 USART->cr2 = USART_CR2_TEN; // Allow TX and RX 24 USART->cr3 &= ~(USART_CR3_STOP1 | USART_CR3_STOP2); // 1 stop bit 25 USART->brr2 = 0x03; 26 USART->brr1 = 0x68; // 9600 baud 27 28 for(;;) 29 { 30 printf("Hello World!\n"); 31 for(i = 0; i < 147456; i++); // Sleep 32 } 33 } 34