Experimenting the 2051 withC Programming using 89C2051

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;

Hardware & Software Tools
programming
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


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top