STC8G1K08A minimal UART hello world demo
Also see::
- Concerned about firmware size? Check out STC8G1K08A tiny 349 byte UART hello world demo
This minimal demo is based on the sdcc compiler and the FwLib_STC8 library. It initializes the UART at 115200 baud and continuously prints Hello, world from UART1! followed by a newline.
main.c
#include "fw_hal.h"
/* Configure UART1 for a plain 8N1 style debug console at 115200 baud.
* Timer1 is used as the baud-rate generator because that is the default setup
* already used by the other small demos in this repository.
*/
static void UART_Init(void)
{
UART1_Config8bitUart(UART1_BaudSource_Timer1, HAL_State_ON, 115200);
}
void main(void)
{
/* Load the clock trim values from fw_conf.h and switch the MCU to the
* configured operating frequency before any peripheral timing is derived
* from SYSCLK.
*/
SYS_SetClock();
/* Bring UART1 up once so the loop below can send human-readable output. */
UART_Init();
while(1)
{
/* Push a single NUL-terminated string out through UART1.
* The library transmits one byte at a time until it reaches '\0'.
*/
UART1_TxString("Hello, world from UART1!\r\n");
/* Wait roughly one second so the terminal output stays readable and
* the message cadence is easy to verify on a serial adapter.
*/
SYS_Delay(1000);
}
}How to flash
See our post How to flash STC8G1K08A using stcgal
How to check the serial output
Check the output using
monitor.sh
picocom -b 115200 /dev/ttyUSB0Memory usage
example.txt
===== Memory usage summary for uart_hello_world =====
Internal RAM layout:
0 1 2 3 4 5 6 7 8 9 A B C D E F
0x00:|0|0|0|0|0|0|0|0|Q|Q|Q|Q|S|S|S|S|
0x10:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0x20:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0x30:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0x40:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0x50:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0x60:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0x70:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0x80:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0x90:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0xa0:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0xb0:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0xc0:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0xd0:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0xe0:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0xf0:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
0-3:Reg Banks, T:Bit regs, a-z:Data, B:Bits, Q:Overlay, I:iData, S:Stack, A:Absolute
Stack starts at: 0x0c (sp set to 0x0b) with 244 bytes available.
No spare internal RAM space left.
Other memory:
Name Start End Size Max
---------------- -------- -------- -------- --------
PAGED EXT. RAM 0 256
EXTERNAL RAM 0x0001 0x0057 87 1024
ROM/EPROM/FLASH 0x0000 0x0856 2135 8192
===============================================If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow