-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_world.c
44 lines (36 loc) · 1.02 KB
/
hello_world.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <EFM8LB1.h>
#include <stdio.h>
#define SYSCLK 24500000L // SYSCLK frequency in Hz
#define BAUDRATE 115200L // Baud rate of UART in bps
char _c51_external_startup (void)
{
// Disable Watchdog with key sequence
SFRPAGE = 0x00;
WDTCN = 0xDE; //First key
WDTCN = 0xAD; //Second key
VDM0CN |= 0x80;
RSTSRC = 0x02;
// Use a 24.5MHz clock
SFRPAGE = 0x00;
CLKSEL = 0x00;
CLKSEL = 0x00;
while ((CLKSEL & 0x80) == 0);
P0MDOUT |= 0x10; // Enable UART0 TX as push-pull output
XBR0 = 0x01; // Enable UART0 on P0.4(TX) and P0.5(RX)
XBR1 = 0X00;
XBR2 = 0x40; // Enable crossbar and weak pull-ups
// Configure Uart 0
SCON0 = 0x10;
CKCON0 |= 0b_0000_1000 ; // Timer 1 uses the system clock.
TH1 = 0x100-((SYSCLK/BAUDRATE)/2L);
TL1 = TH1; // Init Timer1
TMOD &= ~0xf0; // TMOD: timer 1 in 8-bit auto-reload
TMOD |= 0x20;
TR1 = 1; // START Timer1
TI = 1; // Indicate TX0 ready
return 0;
}
void main (void)
{
printf( "Hello, world!\r\n" );
}