A Collection of STC89C52 Demos using SDCC
See this blog entry for the start of the series and background for this code.
And the entire STC89C52 SDCC series.
Prerequisites
- SDCC Compiler
- Meson Build System
- STC89C52RC development kit or bootstrap circuits explained here
- stcgal for flashing
Building
meson build
ninja -v -C ./buildFlashing
These examples use stcgal as flashing tool.
Flashing for particular versions of the firmware can be done via ninja.
My BSL version of the chip was not supported by the mainline stcgal, nrifes
version seemed to work better.
# Power target off
ninja -v -C ./build flash_<hexname>
# Power target on
# Power-cycle target to see new firmware runningDemos
The demos span multiple topics and are grouped by my respective blog posts.
0. Hello World
This demo is a simple hello world application that toggles a LED on pin
P2.0. This is covered in the first blog post of the series.
# Flash using ...
ninja -v -C ./build flash_00_hello
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.Manual boostrap of this example without a dev-kit should be doable as follows.
1. Basic LED and Button Interfacing
These examples are covered in this blog post of the series.
LED Button
This is a simple example that lights up an LED D1-D4 whenever the corresponding buttons K1-K4 are pressed on
the HC6800-ES development kit. The circuit connections are shown below note RxD and TxD map to P3.0 and P3.1 respectively.
# Flash using ...
ninja -v -C ./build flash_01_led_button
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.LED Button Timer
Uses timer interrupts to poll the button states and update the LED states accordingly in 50 ms intervals.
# Flash using ...
ninja -v -C ./build flash_01_led_button_timer
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.LED Button Timer with Debouncing
Same as above but adds simple debouncing to the button handling to avoid bouncing effects so the effective time is 1 s.
LED and Buzzer
This demo extends the button and LED demo by adding a buzzer that sounds whenever any button is pressed.
# Flash using ...
ninja -v -C ./build flash_01_led_buzzer
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.LED Multiplexing With 74HC595 Array
This demo shows how to use a 74HC595 shift register to drive an array of 8 LEDs using only 3 pins from the microcontroller.
Note on the HC6800-ES development kit, JP595 and JPOE need to be set to connect the 74HC595.
# Flash using ...
ninja -v -C ./build flash_01_led_74H595
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.LED Matrix 8x8 Display with 74HC595 Column Driver
Illustration how to use a 8x8 LED matrix display.
# Flash using ...
ninja -v -C ./build flash_01_led_matrix
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.LED Matrix and Hex Keypad

Expansion of the previous demo by adding a hex keypad to control the display.
# Flash using ...
ninja -v -C ./build flash_01_button_led_matrix
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.02 Seven Segment Displays
See the second blog post in the series here.
02 7-Segment Display
This demo shows how to interface a single 7-segment display to the STC89C52 microcontroller for displaying
a single digit number with a lookup table.
# Flash using ...
ninja -v -C ./build flash_02_7_segment
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.02 7-Segment Multiplexed Display
This demo shows how to interface a multiplexed 4-digit 7-segment display to the STC89C52 microcontroller
for displaying a 8-digit number with a lookup table and multiplexing.
# Flash using ...
ninja -v -C ./build flash_02_7_segment_dyn
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.03 LCD Displays
See the third blog post in the series here.
This demo shows how to interface a HD44780 based character LCD to the STC89C52 microcontroller.
# Flash using ...
ninja -v -C ./build flash_03_hd44780_lcd
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.04 Complex Graphic LCD Displays
04 ST7920 128x64 Graphic LCD
See my blog post about this here for more details.
Very simple demo to show text and graphics on a 128x64 pixel ST7920 based graphic LCD.
# Flash using ...
ninja -v -C ./build flash_04_st7920_lcd
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.04 Bitmap and Running Line Demo
Running line demo on the ST7920 128x64 graphic LCD.
Bitmap demo
# Flash using ...
ninja -v -C ./build flash_04_st7920_graph
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.06 Dallas DS18B20 Temperature Sensor
See my blog post about this here for more details.
This demo shows how to interface a Dallas DS18B20 temperature sensor to the STC89C52 microcontroller,
and builds upon the previous 7-Segment demo to display the temperature readings as digital thermometer.
# Flash using ...
ninja -v -C ./build flash_06_DS18B20_1wire
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.07 I2C EEPROM AT24C02
See my blog post about this here for more details.
This demo shows how to interface an I2C EEPROM AT24C02 to the STC89C52 microcontroller,
a button press to K3 writes a test pattern to the EEPROM, and pressing button K4 reads back the data.
# Flash using ...
ninja -v -C ./build flash_07_at24c02_i2c
# Adjust the meson.build file to point to the COM port your serial flasher enumerates to. And power-cycle the target after
# issuing the flash command.08 Infra red Remote Control
See my blog post about this here for more details.
This demo shows how to interface an infra-red remote control receiver to the STC89C52 microcontroller,
pressing buttons on the remote control displays the corresponding NEC code on the 7-segment display.
# Flash using ...
ninja -v -C ./build flash_08_irda
# Adjust the meson.build file to point to the COM port your serial flasher enumerates
# And power-cycle the target after issuing the flash command.

















