Home > Electronic Tutorials > Microcontroller Based Schematics > AT89C2051/4051 Driving Dot LED Circuit

Microcontroller Based Schematics, Projects, Tutorials

AT89C2051/4051 Driving Dot LED Circuit

Author : Wichit Sirichote

A basic circuit of the 89C2051 shown here can be made easily using point-to-point soldering with a universal PCB. Use an ordinary 20-pin socket, do not use a circle-pin socket. D1 is a small dot LED. U2 can be either 7805 or 78L05. U3 is optional for correcting any polarity DC adapter. Without the 2051 chip in the socket, checks the connection, then measures +5V between pin 20 and pin 10. Test the LED by shorting P1.7 pin to GND.

Basic 2051's circuit diagram

myfirst.c

MYFIRST.C
MYFIRST.HEX

Test your board with myfirst.c, a simple c program that makes LED blink every 0.5 second.

/*
 * myfirst.c
 * First C program for 2051 experiment
 * complement P1.7 every 0.5 sec
 * Copyright (C) 1999 Wichit Sirichote
 * compiled with Dunfield Micro-C for 8051 Release 3.2
 */

#include c:\mc\8051io.h  /* include i/o header file */
#include c:\mc\8051reg.h

extern register char cputick; // cputick was incremented every 10ms
register unsigned char sec100,flag1;

#define n 50

task1();  // functions declarations
task2();

main()
{
          flag1 = 0;
          sec100 = 0;
          serinit(9600); // set timer0 to be 16 bit counter
          while(1){

               while(cputick == 0)
                ;
                cputick = 0;
                task1();
                task2();
                  }
}

task1()                        // set bit 0 of flag1 every n*10ms
{
          sec100++;            // increment sec100
          if (sec100 >= n)
               {sec100 = 0;    // clear sec100
                flag1 |= 0x01; // set bit 0 of flag1
                }
}

task2()
{
         if ((flag1 & 0x01) != 0) // execute below if bit 0 of flag1 is set
                {
                // P1 ^= 0x80;    // exclusive or the latch bit 7 with 0x80
                 asm " CPL P1.7"; // complement P1.7
                 flag1 &= ~0x01;  // clear bit 0 of flag1
                }
}



Exercises
  • change blink rate to 5Hz with time on of 0.5 second.
  • swap c++ comment between P1 ^= 0x80 and asm " CPL P1.7", recompile with -iac, see the MYFIRST.ASM, difference of the compiled code between two lines, does it work? which one is better? why?
Note: To report broken links or to submit your projects please send email to Webmaster

Discover

     more......