8051 Digital Clock On 7 Segment (Non Multiplexed)

Description

It’s an example of 8051 Digital Clock On 7 Segment (Non Multiplexed).

Circuit Diagram

Detail

In this example we have configured 8051 timer0 for time calculation. There are 4 different modes for timer0 in 8051. We have selected 8 bit auto reload mode. In this mode timer0 hardware is automatically reset upon overflow to a predefined value and again starts counting up. Timer0 counts up 1 after 12 clocks of main system clock oscillator. So if we are using 12 MHz crystal then timer0 input frequency will be 1 MHz.
Here in this project system clock is of 24 MHz and timer0 input clock is 2 MHz. It is reset to value 6 after each overflow. Simply each timer interrupt is occurred after 125 micro seconds. And so in this way if 8 interrupts has occurred then 1 millisecond has passed and if 8000 interrupts has occurred then 1 second has passed and so on. In this way we calculate hours and minutes also. This time is updated on 4 digit 7 segment displays regularly. For detail of 7 segment interfacing please see 8051 To 7 Segment Display Interfacing. Buttons are provided for time settings.

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.

Free Downloads

8051-Digital-Clock-On-7-Segment-Non-Multiplexed.zip

Related Projects

8051 Basic LED Flasher

8051 To 7 Segment Display Interfacing

8051 Timer0 As Second Counter On 7 Segment

Cricket Score Board using 8051 and 7 Segment Display

8051 Digital Clock On 16×2 LCD

More Projects

8051 Digital Clock On 16×2 LCD

Description

It’s an example of 8051 Digital Clock On 16×2 LCD.

Circuit Diagram

Detail

In this example we have configured 8051 timer0 for time calculation. There are 4 different modes for timer0 in 8051. We have selected 8 bit auto reload mode. In this mode timer0 hardware is automatically reset upon overflow to a predefined value and again starts counting up. Timer0 counts up 1 after 12 clocks of main system clock oscillator. So if we are using 12 MHz crystal then timer0 input frequency will be 1 MHz.
Here in this project system clock is of 24 MHz and timer0 input clock is 2 MHz. It is reset to value 6 after each overflow. Simply each timer interrupt is occurred after 125 micro seconds. And so in this way if 8 interrupts has occurred then 1 millisecond has passed and if 8000 interrupts has occurred then 1 second has passed and so on. In this way we calculate hours and minutes also. This time is updated on 16×2 LCD regularly. For detail of LCD interfacing please see 8051 To 16×2 LCD Interfaing. Buttons are provided for time settings.

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.

Free Downloads

8051-Digital-Clock-On-16×2-LCD.zip
HD44780 Datasheet

Related Projects

8051 Basic LED Flasher

8051 To 16×2 LCD Interfaing

8051 Timer0 As Second Counter On 7 Segment

8051 Digital Clock On 7 Segment (Non Multiplexed)

PC Serial RS232 Port Interface To 16×2 LCD

More Projects

PC Serial RS232 Port Interface To 16×2 LCD

Description

It’s an example of PC Serial RS232 Port Interface To 16×2 LCD.

Circuit Diagram

Detail

In this example we have interfaced 16X2 LCD with PC serial RS232 port. At PC side we have used a terminal software like hyperterminal that displays data coming from microcontroller and sends user input from keyboard to microcontroller. We can develop our customized software for serial communication on PC side. 8051 microcontroller dipslays data coming from PC on 16×2 LCD. This example also shows that how can we configure and use serial channel of 8051 microcontroller for sending and receiving data to PC.

In this example 8051 microcontroller first displays title information like

PC Serial Port Interface To 16x2 LCD

By    : Micro Digital
Web   : https://www.micro-digital.net
Email : udigital.solutions@gmail.com
Cell  : +92-332-555-8051

User inputs data in the following way

w,1,PC Serial RS232 

In the above example format whole line is comma separated. First character ‘w’ tells microcontroller that it is a write command. After 1st comma ‘1’ represents line number on which we want to write. After 2nd comma “PC Serial RS232 ” is the text to be displayed. So if we summaries above discussion then above line sent to microcontroller tells it that we want to write text “PC Serial RS232 ” on line number 1. Similarly we can write on 2nd line of LCD any text. For example

w,2,16x2 LCD Interface

In above example text is more than 16 characters and so whole text will not be displayed on LCD. Try to send text of not more than 16 characters.

Finally microcontroller shows text on 16×2 LCD according to command line sent. This is an interesting example in which we learn how can we configure 8051 serial channel, communicate with PC, extract data or text and command and then display text on 16×2 LCD.

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.

Free Downloads

PC-Serial-RS232-Port-Interface-To-16×2-LCD.zip
HD44780 Datasheet

Related Projects

8051 Basic LED Flasher

8051 To 16×2 LCD Interfaing

PC Serial RS232 Port Interface To 8051

PC Serial RS232 Port Interface To 7 Segment

8051 Calculator using PC Serial Port

8051 Digital Clock On 16×2 LCD

More Projects

PC Serial RS232 Port Interface To 7 Segment

Description

It’s an example of PC Serial RS232 Port Interface To 7 Segment.

Circuit Diagram

Detail

In this example we have interfaced seven segment display with PC serial RS232 port. In this example we have used PC screen for display and PC keyboard for user input to our 8051 microcontroller like in project 8051 Calculator using PC Serial Port. At PC side we have used a terminal software like hyperterminal that displays data coming from microcontroller and sends user input from keyboard to microcontroller. We can develop our customized software for serial communication on PC side. 8051 microcontroller dipslays data coming from PC on seven segment display. This example also shows that how can we configure and use serial channel of 8051 microcontroller for sending and receiving data to PC.

In this example 8051 microcontroller first displays title information then asks user to press a key from 0 to 9 as seven segment can only display numeric digits. Microcontroller will not display character input other than numeric values from 0 to 9.

PC Serial Port Interface To 7 Segment

By    : Micro Digital
Web   : https://www.micro-digital.net
Email : udigital.solutions@gmail.com
Cell  : +92-332-555-8051

Press a key from 0 to 9

User presses keys in the range from 0 to 9 and microcontroller will just display this value after converting it into seven segment patterns.

This is an interesting example in which we learn how can we configure 8051 serial channel, use PC monitor for microcontroller display, PC keyboard as keyboard attached to microcontroller and use seven segment as numeric digit display.

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.

Free Downloads

PC-Serial-RS232-Port-Interface-To-7-Segment.zip

Related Projects

8051 Basic LED Flasher

PC Serial RS232 Port Interface To 8051

8051 Calculator using PC Serial Port

PC Serial RS232 Port Interface To 16×2 LCD

Cricket Score Board using 8051 and 7 Segment Display

8051 Timer0 As Second Counter On 7 Segment

8051 Digital Clock On 7 Segment (Non Multiplexed)
More Projects

8051 Calculator using PC Serial Port

Description

It’s an example of 8051 Calculator using PC Serial Port.

Circuit Diagram

Detail

This example shows that how can we use PC screen for display and PC keyboard for user input to our 8051 microcontroller. At PC side we use a terminal software like hyperterminal that displays data coming from microcontroller and sends key strokes read to microcontroller. So this makes easy for a new programmer to display and read input from user without interfacing any LCD, seven segment or keypad. This example also shows that how can we configure and use serial channel of 8051 microcontroller for sending and receiving data to PC. In so many projects we need to share data or information to other devices.

In this example 8051 microcontroller first displays title information then asks user to select a choice from given choices like

8051 Calculator using PC Serial Port

By    : Micro Digital
Web   : https://www.micro-digital.net
Email : udigital.solutions@gmail.com
Cell  : +92-332-555-8051

Enter your choice
1) Add
2) Subtract
3) Multiply
4) Divide

User selects a choice by pressing appropriate key from 1 to 4. Then microcontroller asks user to enter 1st number or operand like

Enter 1st number (Max Length 4)
Num1 : 

Then user enters 1st integer value with maximum length 4. For example user enter 124 and presses enter. Then microcontroller asks user for 2nd number

Enter 1st number (Max Length 4)
Num1 : 124
Enter 2nd number (Max Length 4)
Num2 : 

Now user enters 2nd number for example 234 and presses enter.

Enter 1st number (Max Length 4)
Num1 : 124
Enter 2nd number (Max Length 4)
Num2 : 234
Ans  : 358
Press any key to continue...

Finally microcontroller shows answer and asks user to press any key for next calculation. This is an interesting example in which we learn how can we configure 8051 serial channel, use PC monitor for microcontroller display and PC keyboard as keyboard attached to microcontroller.

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.

Free Downloads

8051-Calculator-using-PC-Serial-Port.zip

Related Projects

8051 Basic LED Flasher

PC Serial RS232 Port Interface To 8051

PC Serial RS232 Port Interface To 7 Segment

PC Serial RS232 Port Interface To 16×2 LCD

More Projects

PC Serial RS232 Port interface To 8051

Description

It’s an example of PC Serial RS232 Port interface To 8051 microcontroller.

Circuit Diagram

Detail

It is an example of interfacing Serial RS232 port to 8051 microcontroller. This example show that how can we configure and use serial channel of 8051 microcontroller for sending and receiving data to other device like PC. In so many projects we need to share data or information to other devices. We can provide control between PC and other devices. After acquiring data from embedded device PC software can perform so many other processes to make this data useful information. For example we can read status of sensors using microcontroller and can control other part of our machinery. It is also possible to provide remote data acquisition and control in this way. Data can be read and be reported to a remote location using web & network. There may be several other possibilities.

This is a simple RS232 port interfacing example in which we are controlling 8 LEDs through PC serial port. A software like hyper-terminal can be used to send data to microcontroller. 8 LEDs can be replaced by transistors & relay switches to control and operate high volt devices.

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.

Downloads

PC-Serial-RS232-Port-interface-To-8051.zip

Related Projects

8051 Basic LED Flasher

8051 Calculator using PC Serial Port

PC Serial RS232 Port Interface To 7 Segment

PC Serial RS232 Port Interface To 16×2 LCD

More Projects

8051 I/O Ports Interfacing

Description

It’s an example of 8051 I/O Ports Interfacing.

Circuit Diagram

Detail

This example illustrates how can we use I/O ports of an 8051 based microcontroller. In this project I have used one port P1 for input and other port P2 for output. Each of these ports consists of 8 pins that can be accessed and used individually. There are 8 buttons connected to port P1 and 8 LEDs are connected on port P2. When user will press button B0 then LED D3 will toggle (on to off or off to on state). Similarly B1 controls LED D4, B2 controls LED D5 and so on.

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.

Free Downloads

8051-I-O-Ports-Interfacing.zip

Related Projects

8051 Basic LED Flasher

Electronic Dice using 8051

8051 To Seven Segment Display Interfacing

Cricket Score Board using 8051 and 7 Segment Display

2-Way Traffic Signal Controller

More Projects

8051 To 16×2 LCD Interfacing

Introduction

It’s an example of 8051 To 16×2 LCD Interfacing.

Circuit Diagram

Description

It is 16×2 LCD interfacing example with 8051 in 4 bit mode. In this project we can display results or outcomes of our system for users.

LCD

In embedded systems it is difficult to find status and errors generated by system software running inside of microcontroller. It is also necessary in so many other applications where we have to show results to users so that they can use system effectively. So there is a need of a display unit. There are more than one ways of displaying status or results of the system and LCD is one of these ways.

In this project we have used 16×2 means 16 columns and 2 rows LCD. This is based on HD44780 LCD controller. HD44780 is a generic dot matrix LCD controller made by Hitachi. This controller is installed on other sizes of LCDs like 16×1, 16×4, 20×2, 20×4 etc.

LCD.jpg
Click to Enlarge

Pin-Out

Pin Symbol Function
1 Vss ground (0 V)
2 Vdd power (4.5 – 5.5 V)
3 Vo contrast adjustment
4 RS H/L register select signal
5 R/W H/L read/write signal
6 E H/L enable signal
7-14 DB0 – DB7 H/L data bus for 4- or 8-bit mode
15 A (LED+) backlight anode
16 K (LED-) backlight cathode

This LCD can be operated in 4 or 8 bit data mode. In 4 bit mode 4 most significant data bits are used while in 8 bit mode all 8 data pins are connected to microcontroller. In this project we have used 4 bit mode of operation. In 4 bit mode each data or command byte is loaded in 2 iterations of 4 bit each. We can read & write data to LCD but to keep things simple we have hardwired R/W line to ground for only writing. It means we can only print on LCD but cannot read back content written in LCD RAM.

LCD commands used in this project are

  1. Function Set
  2. Entry Mode Set
  3. Display On/Off
  4. Clear Display
  5. Move Cursor/RAM Address Pointer

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.

Code

There is one header and two source/c files.

  1. main.c
  2. lcd4bit.h
  3. lcd4bit.c

Functional description of LCD functions is below

void init_lcd(void);

This function initializes LCD in 4 bit mode. First it confirms 4 bit interface of LCD then sets entry mode, switches on display and clears it.

void gotoxy_lcd(unsigned char col,unsigned char line);

Changes position of cursor on specified column and line by using cursor move command.

void putc_lcd(unsigned char byte);

This function prints single character on current position of cursor on LCD screen.

void print_lcd(char String[]);

This function prints a string on current position of LCD.

void delay_lcd (void);

This function is used to introduce delays needed before sending next command or to wait until previous command is executed.

void write_lcd(unsigned char Val);

This function writes/sends a byte (8 bits) by calling “write_nibble_lcd” function 2 times. It means 4 bits are transferred at one time. After this a delay is introduced to wait until for action is being performed by LCD according data/command sent.

void write_nibble_lcd(unsigned char Val)

This function writes/sends a nibble (4 bits) at one time.

Below is the main file code.

// Start of code.


///////////////////////////////////////////////////////////
// Company         : Micro Digital                       //
// Address         : Office # C7 Raza Plaza              //
//                   DAV College Road                    //
//                   Rawalpindi,                         //
//                   Pakistan.                           //
// Programmed By   : Rashid Mehmood                      //
// Project Name    : 8051 To 16x2 LCD Interfacing        //
// Crystal         : 24.000000 MHz                       //
// Microcontroller : AT89C51-C52-C55-S51-S52             //
///////////////////////////////////////////////////////////

#include <AT89X51.H>
#include "lcd4bit.h"

void main()
{
	unsigned char i = 0;
	init_lcd();
	print_lcd("  Micro Digital  \0");
	gotoxy_lcd(1, 2);
	print_lcd("micro-digital.net\0");
	while(1)
	{
	}
}

// End of code.

Free Downloads

8051-To-16×2-LCD-Interfacing.zip
HD44780 Datasheet

Related Projects

8051 Basic LED Flasher

Electronic Dice using 8051

8051 To Seven Segment Display Interfacing

Cricket Score Board using 8051 and 7 Segment Display

PC Serial RS232 Port Interface To 16×2 LCD

8051 Calculator with 16×2 LCD and Telephone Keypad

8051 4 Digit Electronic Code Lock with LCD and Keypad

More Projects

Unipolar Stepper Motor Interfacing To 8051

Description

It’s an example of Unipolar Stepper Motor Interfacing To 8051 microcontroller.

Circuit Diagram

Detail

It is simplest stepper motor interfacing example with 8051. In this project 8051 microcontroller controls unipolar stepper motor.

Stepper Motor

Stepper or stepping motors rotate through a fixed (pre-determined) angular step in response to input command provided by controller. On every next command motor advances one angular step. It means motor rotates in a series of angular intervals/steps with each step of same distance. If we reverse the order of input commands the direction of stepper motor also reverses.

Stepper.jpg
Click to Enlarge
Stepper Internal Circuit Diagram
Stepper-Internal-Circuit.jpg
Click to Enlarge

Above is the circuit diagram of 5 or 6 pin unipolar stepper motor. There are 2 main coils A and B. Each is further sub divided into 2 more coils resulting A0, A1, B0 and B1. Center tapped are usually connected to common supply source and command or command pattern is provided by its controller on inputs A0, A1, B0 and B1. For full step command sequence is given by

b1 b0 a1 a0 Hex Decimal
0 0 0 1 0x01 1
0 1 0 0 0x04 4
0 0 1 0 0x02 2
1 0 0 0 0x08 8

We can make software interface simple by interchanging pin a1 with b0. Now commands sequence will become

b1 a1 b0 a0 Hex Dec
0 0 0 1 0x01 1
0 0 1 0 0x02 2
0 1 0 0 0x04 4
1 0 0 0 0x08 8

We can use this unipolar stepper motor as bipolar stepper motor by ignoring center tapped input.

In the controller circuit diagram Port0 4 LSBs are connected to the inputs of 2 ULN2003A coil driver IC. Each ULN2003A contains 7 darling-ton pairs to provide interface between 8051 microcontroller and stepper motor. As microcontroller cannot drive stepper motors or coils directly. We know that coils produce back emf when these are switched from “on” to “off” or “off” to “on” state. ULN2003A also provides back emf protection diodes to remove back emf produce by coils. Each driver of ULN2003A can sink 500mA current maximum. We can parallel these drivers to handle more current according to stepper motor needs. In the above controller circuit diagram we have paralleled 3 drivers. We have connected 3 inputs together. Similarly 3 outputs of driver together. Each pair of 3 drivers is driving a single coils of stepper motor. We have used separate power supplies for controller and stepper motor.

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.

Code

Below is the simplest code of stepper motor demonstration.

// Start of code.


///////////////////////////////////////////////////////////
// Company         : Micro Digital                       //
// Address         : Office # C7 Raza Plaza              //
//                   DAV College Road                    //
//                   Rawalpindi,                         //
//                   Pakistan.                           //
// Programmed By   : Rashid Mehmood                      //
// Project Name    : Unipolar Stepper Motor Interfacing  //
//                   To 8051                             //
// Crystal         : 24.000000 MHz                       //
// Microcontroller : AT89C2051-C51-C52-C55-S2051-S51-S52 //
///////////////////////////////////////////////////////////

#include <AT89x051.h>

void delay(unsigned int del)
{
	while(del --);
}

void main()
{
	char i;
	while(1)
	{
		for(i = 0; i < 4; i ++)
		{
			// Output pattern for next step.
			P0 = 0x01 << i;
			// Give some suitable delay.
			// You can change this delay
			// depending on your motor 
			// maximum speed.
			delay(10000);
		}	
	}
}

// End of code.

This code can also be executed with little or no change on AT89C2051 microcontroller a small brother of AT89C51.

Related Projects

8051 Basic LED Flasher

More Projects

2-Way Traffic Signal Controller

Description

It’s a 2-Way Traffic Signal Controller using 8051 microcontroller. It controls 6 lights (2 red, 2 yellow and 2 green) for 2-Way Traffic. It is an interesting and another basic learning project for student and hobbies.

Diagram

Detail

In this project 8051 microcontroller controls 6 traffic lights of 2-Way traffic. A fixed time is assigned to each green signal of each way. This is also simple project that uses 6 LEDs of 3 colors, 8051 microcontroller and an optional 5V power supply regulator part. It’s algorithm is as follows

1- Initially microcontroller will switche on both red LED lights of both ways and switches off all other LED lights of both ways.

2- Then wait for time defined by RESET_DELAY.

3- Now start servicing way 0 by switching yellow LED light of that way. Give delay of defined by YELLOW_DELAY.

4- Now switch off red and yellow LED lights of way 0 and switch on green of that way. Wait for green way 0 as defined by GREEN0_DELAY.

5- Switch off green and switch on yellow LED light for way 0. Give delay of defined by YELLOW_DELAY.

6- Switch off yellow and switch on red LED lights for way 0. Give delay of defined by RED_DELAY.

7- Now servicing of way 0 is complete and it is the time to service 2nd way that is way 1. Similarly we repeat steps from 2 to 6 for way 1 also.

8- After servicing of way 1 we once again start from way 0 as discussed earlier.

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.

Code

// Start of code.

///////////////////////////////////////////////////////////
// Company         : Micro Digital                       //
// Address         : Office # C7 Raza Plaza              //
//                   DAV College Road                    //
//                   Rawalpindi,                         //
//                   Pakistan.                           //
// Programmed By   : Rashid Mehmood                      //
// Project Name    : 2-Way Traffic Light Controller      //
// Crystal         : 24.000000 MHz                       //
// Microcontroller : AT89C2051-C51-C52-C55-S2051-S51-S52 //
///////////////////////////////////////////////////////////

// Header file for AT89x051 microcontrollers regiter definitions.
#include <AT89x051.h>

sbit R0 = P1^0;
sbit Y0 = P1^1;
sbit G0 = P1^2;
sbit R1 = P1^3;
sbit Y1 = P1^4;
sbit G1 = P1^5;

void delay_ms(unsigned int del)
{
	unsigned int i,j;
	for(i = 0; i < del; i ++)
		for(j = 0; j < 1275; j ++);
}

#define RESET_DELAY 	1000	// (aprox 1 second)
#define RED_DELAY 	1000	// (aprox 1 second)
#define YELLOW_DELAY	1000	// (aprox 1 second)
#define GREEN0_DELAY	2000	// (aprox 2 second)
#define GREEN1_DELAY	3000	// (aprox 3 second)

void main()
{
	// Initialize all lights////////
	// Switch on all red signals.
	R0 = R1 = 0;
	// Switch off all other signals.
	Y0 = Y1 = G0 = G1 = 1;
	delay_ms(RESET_DELAY);
	////////////////////////////////

	while(1)
	{

		// First service way 0.////////////////////

		// Switch on yellow of way 0.
		Y0 = 0;
		delay_ms(YELLOW_DELAY);


		// Switch off red and yellow of way 0 and 
		// switch on green of way 0.
		R0 = 1;
		Y0 = 1;
		G0 = 0;
		delay_ms(GREEN0_DELAY);
			
		// Switch off green of way 0 and 
		// switch on yellow of way 0;
		G0 = 1;
		Y0 = 0;
		delay_ms(YELLOW_DELAY);

		// Switch off yellow of way 0 and 
		// switch on red of way 0;
		Y0 = 1;
		R0 = 0;
		delay_ms(RED_DELAY);
		/////////////////////////////////////////

		
		// Now service way 1.////////////////////

		// Switch on yellow of way 1.
		Y1 = 0;
		delay_ms(YELLOW_DELAY);


		// Switch off red and yellow of way 1 and 
		// switch on green of way 1.
		R1 = 1;
		Y1 = 1;
		G1 = 0;
		delay_ms(GREEN0_DELAY);
			
		// Switch off green of way 1 and 
		// switch on yellow of way 1;
		G1 = 1;
		Y1 = 0;
		delay_ms(YELLOW_DELAY);

		// Switch off yellow of way 1 and 
		// switch on red of way 1;
		Y1 = 1;
		R1 = 0;
		delay_ms(RED_DELAY);
		/////////////////////////////////////////
	}
}

// End of code.

This code can also be executed on AT89C2051 microcontroller a small brother of AT89C51.

Related Projects

8051 Basic LED Flasher

Electronic Dice using 8051

8051 To Seven Segment Display Interfacing

More Projects