Summary of Experimenting the 2051 withC Programming using 89C2051
This article guides beginners on creating a simple C program for the 89C2051/89C4051 microcontroller, compiling it, and downloading the HEX code without an ICE or in-circuit programmer. It details hardware assembly, including the EASY-DOWNLOADER V1.1, and explains modifications to Micro-C startup code for timer interrupts.
Parts used in the 89C2051/89C4051 Experiment:
- 89C2051 or 89C4051 Flash Based Microcontroller chips
- X-tal 11.0592MHz with two ceramics 30pF
- RC Reset circuit (8.2k resistor and 10uF electrolytic capacitor)
- 78L05 or 7805 voltage regulator
- Bridge diode and filtering/bypassing capacitors (10uF, 470uF, 0.1uF)
- Universal PCB
- 20-pin IC socket
- DC jack
- 12VDC adapters
- EASY-DOWNLOADER V1.1 programmer
- Micro-C compiler from Dunfield Development System
Learn yourself, how to write a simple program using Clanguage for the 89C2051/89C4051. Write a C source program, compile,and download the HEX code to the chip directly, connect DC adapter, seewhat happen after power up the board. No need ICE, in-circuit programmer,everything can be made by yourself easily.
Introduction
This page was provided forBeginnerswho interested in using C and Assembly languageto do simple experiment with the 89C2051/89C4051 Flash microcontrollers.Exemplary of experiments are;
- drivingdot LED
- scanning7-segment display and keypad
- connectingdump terminal
- steppermotor
- driving AC load with SSR
- I2C serial EEPROM 24C16
- display driver 7219
- calculating CRC-16
- etc.
Hardware & Software Tools
Let begin with soldering the basic circuit. The hardware& software tools that needed for getting start are;
- 89C2051 or 89C4051 Flash Based Microcontroller chips,
- X-tal 11.0592MHz with two ceramics 30pF for stabilizing oscillator circuit,
- RC Reset circuit, 8.2k and 10uF electrolytic capacitor,
- 78L05 or 7805 voltage regulator,
- Bridge diode and filtering, bypassing capacitor, 10uF, 470uF, 0.1uF,
- universal PCB, 20-pin IC socket, DC jack, and any 12VDC adapters,
- don’t forget build the EASY-DOWNLOADER V1.1 , a programmer that used to write HEX code to the chip,
- and finally, C compiler, whichever you find, but the example shown in the following pages used Micro-C for 8051 from Dunfield Development System written by Dave Dunfield.
A Bit Modification of Micro-C Startup Code for TINY Model
The startup code for TINY memory model was modified byputting a service routine for timer0 interrupt that generating 10ms timebasefor many experiments. The service routine of timer0 increments CPUTICKvariable by one every 10ms. The others application programs that need thisvariable may used by using modifier EXTERN REGISTER CHAR CPUTICK; say.Initial codes have also set the timer interrupt, if user program won’tuse timer interrupt, in the C source, just put DISABLE( ) functions, itwill clear EA bit.
also for serinit(9600) function
serinit(9600) initializes SERIAL PORT to 9600 by usingTIMER1, but not for TIMER0. Since Dave used MOV immediate value for settingTIMER MODE, only for TIMER1, but not for TIMER0. I have modified withinthis function by setting the TIMER0 to 16-bit counter and RUN both timers.The application program that needs CPUTICK, must then have to invoked,say serinit(9600) before, see example in driving dot LED experiment.
Editing C source program
Use DOS editor, edits the source program, example is shownbelow. The program will make a complement bit 7 of P1’s latch every 500ms.
/*
* simple.c
* Simple demonstration programwritten in C Language
* Copyright 1999 W.Sirichote
* Compiled with DDS Micro-CTINY model
*/
#include c:\mc\8051io.h
#include c:\mc\8051reg.h
main()
{
while(1) // loop continuously
{
P1 ^= 0x80; //exclusive or P1’s latch with 0x80
delay(500); //delay 500 ms
}
}
Compiling using CC51
Simply invoke;
c:\mc\cc51 simple -il h=c:\mc m=t
compile C source program, simple.(C) with intel HEX fileand ASM listing file output, home directory is c:\mc, and memory modelis TINY.
To compile with output C as comments and Assembly program,try -iac
or with output listing file, -il
The listing file is very useful for debugging and studyinghow the compiler work.
For more detail: Experimenting the 2051 withC Programming using 89C2051
- Can I write a C program for the 89C2051 without an ICE?
Yes, you can write, compile, and download the HEX code directly to the chip using an EASY-DOWNLOADER V1.1 without needing an ICE or in-circuit programmer. - What is the best way to stabilize the oscillator circuit?
The text recommends using an X-tal of 11.0592MHz along with two ceramics of 30pF for stabilizing the oscillator circuit. - How do I initialize the serial port to 9600 baud?
You must invoke the serinit(9600) function before starting the application, which initializes the SERIAL PORT to 9600 using TIMER1. - Does the modified startup code use Timer0 for timebase?
Yes, the startup code includes a service routine for timer0 interrupt that generates a 10ms timebase by incrementing the CPUTICK variable every 10ms. - What command compiles the source program into an Intel HEX file?
You can invoke c:mccc51 simple -il h=c:mc m=t to compile the C source program with an intel HEX file output. - How can I disable the timer interrupt if not needed?
If the user program does not need the timer interrupt, you should put DISABLE() functions in the C source to clear the EA bit. - What editor is suggested for editing the C source program?
The article suggests using a DOS editor to edit the source program. - Which specific compiler example is shown in the text?
The example uses Micro-C for 8051 from Dunfield Development System written by Dave Dunfield.

