Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc-extra / historygraphs / hello-mcs51 / hello.c
blobbfe7ce664271b0e78cff0a2ddcb50545229d6482
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 <stdio.h>
9 #include <C8051F120.h>
11 int putchar(int c)
13 while(!(SCON0 & 0x02));
14 SCON0 &= ~0x02;
15 SBUF0 = c;
16 return (c);
19 unsigned char _sdcc_external_startup(void)
21 // Disable watchdog timer
22 WDTCN = 0xde;
23 WDTCN = 0xad;
25 return 0; // perform normal initialization
28 void main(void)
30 unsigned long int i = 0;
32 // Initialize I/O pins
33 SFRPAGE = 0xf;
34 XBR0 = 0x04; // UART0 on P0.0 and P0.1
35 P0MDOUT = 0x01; // Set port P0.0 (Uart tx) to push-pull
36 XBR2 = 0x40; // Enable crossbar
38 OSCICN = 0xc3; // Run at full 24.5 Mhz - gives better accuracy for baudrate
40 // Use PLL to get SYSCLK to 98 Mhz to get reliable 9800 baud
41 SFRPAGE = 0x0;
42 FLSCL = 0xb0;
43 SFRPAGE = 0xf;
44 PLL0CN = 0x01;
45 PLL0FLT = 0x01;
46 PLL0MUL = 0x04;
47 for (i = 0; i < 31; i++) // Wait 5 µs
49 __asm
50 nop
51 nop
52 nop
53 nop
54 __endasm;
56 PLL0CN = 0x03;
57 while (!(PLL0CN & 0x10));
58 CLKSEL = 0x02;
60 // Configure UART for 1200 baud, 8 data bits, 1 stop bit.
61 SFRPAGE = 0x0;
62 TMOD = 0x21;
63 SCON0 = 0x40;
64 TH1 = 203;
65 TCON |= 0x40;
66 SCON0 |= 0x02; // Tell putchar() the UART is ready to send.
68 for(;;)
70 printf("Hello, World!\n");
71 for(i = 0; i < 147456; i++); // Sleep