8051 Micro-controller

 The 8051 microcontroller is one of the most widely used microcontrollers in embedded systems development. It was originally developed by Intel in 1980 and has since become a popular choice due to its simple architecture, rich set of peripherals, and ease of programming. The 8051 is based on the Harvard architecture and typically includes features such as programmable I/O ports, timers/counters, serial communication interfaces, and interrupt handling capabilities. It is widely used in various applications, including industrial automation, consumer electronics, automotive systems, and more.

Here are some of purpose based projects on 8051:

4 Way traffic light

The 4-Way Traffic Light Controller project uses the 8051 microcontroller to control traffic lights at an intersection with four directions. It helps manage traffic flow safely and smoothly by changing the lights in the right order.


NOTE : THE SHARED CODE MIGHT NOT BE APPROPRIATE TO VIEW ON MOBILE DEVICES KINDLY PREFER LAPTOP/PC.


SOURCE CODE:



#include <reg51.h>

// Define port pins for traffic lights
sbit r1=P1^0;
sbit y1=P1^1;
sbit g1=P1^2;
sbit r2=P1^3;
sbit y2=P1^4;
sbit g2=P1^5;
sbit r3=P1^6;
sbit y3=P1^7;
sbit g3=P2^0;
sbit r4=P2^1;
sbit y4=P2^2;
sbit g4=P2^3;

void delay(unsigned int t); // Function for creating a delay
void signal1(); // Function for controlling traffic signal 1
void signal2(); // Function for controlling traffic signal 2
void signal3(); // Function for controlling traffic signal 3
void signal4(); // Function for controlling traffic signal 4

void main()
{
	while(1) {
		// Loop to control traffic lights in sequence
		signal1(); // Control traffic signal 1
		delay(1); // Delay between signals
		signal2(); // Control traffic signal 2
		delay(1); // Delay between signals
		signal3(); // Control traffic signal 3
		delay(1); // Delay between signals
		signal4(); // Control traffic signal 4
		delay(1); // Delay between signals
	}
}

void delay(unsigned int t)
{
	unsigned int i,j;
	for(i=0;i<=100*t;i++)
	{
		for(j=0;j<=1275;j++); // Delay for 1 second
	}
}

void signal1()
{
	// Traffic signal 1 sequence
	g1=y2=r3=r4=1; // Green light for signal 1, Red lights for other signals
	r1=y1=r2=g2=y3=g3=g4=y4=0; // Red light for signal 1, Yellow and Green lights off for all other signals
	delay(1); // Delay for signal stabilization
	g1=0; // Turn off green light
	delay(1); // Delay for signal transition
	g1=1; // Turn on green light
	delay(1); // Delay for signal transition
	g1=0; // Turn off green light
	delay(1); // Delay for signal transition
	g1=1;	// Turn on green light
	delay(1); // Delay for signal transition
	g1=0; // Turn off green light
	delay(1); // Delay for signal transition
	g1=1; // Turn on green light
}

void signal2()
{
	// Traffic signal 2 sequence
	g2=y3=r4=r1=1; // Green light for signal 2, Red lights for other signals
	r2=y2=g3=r3=y4=g4=y1=g1=0; // Red light for signal 2, Yellow and Green lights off for all other signals
	delay(1); // Delay for signal stabilization
	g2=0; // Turn off green light
	delay(1); // Delay for signal transition
	g2=1; // Turn on green light
	delay(1); // Delay for signal transition
	g2=0; // Turn off green light
	delay(1); // Delay for signal transition
	g2=1; // Turn on green light
	delay(1); // Delay for signal transition
	g2=0; // Turn off green light
	delay(1); // Delay for signal transition
	g2=1; // Turn on green light
}

void signal3()
{
	// Traffic signal 3 sequence
	g3=y4=r1=r2=1; // Green light for signal 3, Red lights for other signals
	y3=r3=g4=r4=y1=g1=y2=g2=0; // Red light for signal 3, Yellow and Green lights off for all other signals
	delay(1); // Delay for signal stabilization
	g3=0; // Turn off green light
	delay(1); // Delay for signal transition
	g3=1; // Turn on green light
	delay(1); // Delay for signal transition
	g3=0; // Turn off green light
	delay(1); // Delay for signal transition
	g3=1; // Turn on green light
	delay(1); // Delay for signal transition
	g3=0; // Turn off green light
	delay(1); // Delay for signal transition
	g3=1; // Turn on green light
}

void signal4()
{
	// Traffic signal 4 sequence
	g4=y1=r2=r3=1; // Green light for signal 4, Red lights for other signals
	y4=r4=r1=g1=y2=g3=y3=0; // Red light for signal 4, Yellow and Green lights off for all other signals
	delay(1); // Delay for signal stabilization
	g4=0; // Turn off green light
	delay(1); // Delay for signal transition
	g4=1; // Turn on green light
	delay(1); // Delay for signal transition
	g4=0; // Turn off green light
	delay(1); // Delay for signal transition
	g4=1; // Turn on green light
	delay(1); // Delay for signal transition
	g4=0; // Turn off green light
	delay(1); // Delay for signal transition
	g4=1; // Turn on green light
}





Student attendance system                                                                

The Student Attendance System is a digital tool for teachers to track student attendance in class. Each student has a unique PIN to check in when they arrive. The system records their attendance and shows the teacher how many students are present. It helps teachers manage classes better and keeps track of student attendance easily.  

SOURCE CODE:

#include <reg51.h>
#include <string.h>
#include <stdio.h>
#include "project1.h" // Header file for LCD functions
void role(); // Function to choose the role
void keypad();
void check(unsigned char pwd[4]); // Function to compare the PIN
unsigned char entered_pin[5] = "0000"; // Character array to store the PIN entered from the keypad
unsigned int k; // Loop counter
unsigned int present = 0; // Counter for the number of students present
unsigned int flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0, flag5 = 0, s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0;
unsigned char present_str[4] = "0000";
sbit sw1 = P3^5; // Switch for teacher
sbit sw2 = P3^7; // Switch for student
sbit r1 = P1^3;
sbit r2 = P1^4;
sbit r3 = P1^5;
sbit r4 = P1^6; // Rows of the keypad
sbit c1 = P1^0;
sbit c2 = P1^1;
sbit c3 = P1^2; // Columns of the keypad
void main()
{    lcd_start(); // Initialize the LCD   while(1)
{
        lcd_cmd(0x01); // Clear the LCD
        lcd_cmd(0x80); // Set the cursor to the first line
        string("SW1 FOR TEACHER");
        lcd_cmd(0xc0);
        string("SW2 FOR STUDENT");
        delay(5);
        role(); // Choose the role (Teacher or Student)
        keypad(); // Input the PIN
        check(entered_pin); // Check the entered PIN
    }
}
void check(unsigned char pwd[4]) 
{
    char pin1[5] = "1001";
    char pin2[5] = "1002";
    char pin3[5] = "1003";
    char pin4[5] = "1004";
    char pin5[5] = "1005";
    char pin_t[5] = "1234";
    
    if (strcmp(pwd, pin_t) == 0) 
    {
        lcd_cmd(0x01); // Clear the LCD
        lcd_cmd(0x80); // Set the cursor to the first line
        sprintf(present_str, "%d", present);
        string(present_str);
        lcd_cmd(0xc0);
        string("STUDENTS PRESENT");
    } 
    else if(strcmp(pwd, pin1) == 0 && flag1 == 0)
    {
        lcd_cmd(0x01); // Clear the LCD
        lcd_cmd(0x80); // Set the cursor to the first line
        string("PRESENT MARKED");
        flag1 = 1;
        delay(30);
        delay(10);

        present++;
    }

    else if(strcmp(pwd, pin1) == 0 && flag1 == 1) 
    {
        lcd_cmd(0x01); // Clear the LCD
        lcd_cmd(0x80); // Set the cursor to the first line
        string("ALREADY PRESENT");
    }
    else if(strcmp(pwd, pin2) == 0 && flag2 == 0)
    {

        lcd_cmd(0x01); // Clear the LCD
        lcd_cmd(0x80); // Set the cursor to the first line

        string("PRESENT MARKED");
        flag2 = 1;
        delay(30);
        delay(10);
        present++;
    }
    else if(strcmp(pwd, pin2) == 0 && flag2 == 1) 
    {
        lcd_cmd(0x01); // Clear the LCD
        lcd_cmd(0x80); // Set the cursor to the first line

        string("ALREADY PRESENT");

    }
    else if(strcmp(pwd, pin3) == 0 && flag3 == 0)
    {
        lcd_cmd(0x01); // Clear the LCd
        lcd_cmd(0x80); // Set the cursor to the first line
       string("PRESENT MARKED");
       flag3 = 1;
        delay(30);
        delay(10);
        present++;
    }
    else if(strcmp(pwd, pin3) == 0 && flag3 == 1) 
    {
        lcd_cmd(0x01); // Clear the LCD
        lcd_cmd(0x80); // Set the cursor to the first line
        string("ALREADY PRESENT");

    }
    else if(strcmp(pwd, pin4) == 0 && flag4 == 0)
    {
        lcd_cmd(0x01); // Clear the LCD

        lcd_cmd(0x80); // Set the cursor to the first lin
        string("PRESENT MARKED");

        flag4 = 1;

        delay(30);
        delay(10);
        present++;
    }
    else if(strcmp(pwd, pin4) == 0 && flag4 == 1) 
    {

        lcd_cmd(0x01); // Clear the LCD

        lcd_cmd(0x80); // Set the cursor to the first line
        string("ALREADY PRESENT");

    }
    else if(strcmp(pwd, pin5) == 0 && flag5 == 0)
    {
        lcd_cmd(0x01); // Clear the LCD
        lcd_cmd(0x80); // Set the cursor to the first line
        string("PRESENT MARKED");
        flag5 = 1;
        delay(30);
        delay(10);

        present++;
    }
    else if(strcmp(pwd, pin5) == 0 && flag5 == 1) 
    {
        lcd_cmd(0x01); // Clear the LCD
        lcd_cmd(0x80); // Set the cursor to the first line
        string("ALREADY PRESENT");

    }

    else 
    {
        lcd_cmd(0x01); // Clear the LCD
        lcd_cmd(0x80); // Set the cursor to the first line
        string("WRONG PIN");
        delay(30);
        delay(10);
    }
}
void role()
{
    while (1)
    {

        if (sw2 == 0) 
        {
            lcd_cmd(0x01); // Clear the LCD
            lcd_cmd(0x80); // Set the cursor to the first line
            string("STUDENT PIN:");
            break;

        } 

        else if (sw1 == 0)

        {

            lcd_cmd(0x01); // Clear the LCD
            lcd_cmd(0x80); // Set the cursor to the first line
            string("TEACHER PIN:");
            break;

        }

    }
}
void keypad()
{

    for(k = 0; k < 4; k++)

    {
        while(1)
        {

            r1 = 0;
            r2 = r3 = r4 = 1;
            // Check column 1
            if(c1 == 0)
            {
                lcd_data('*');
                while(c1 == 0);

                entered_pin[k] = '1';
                break;

            }
            // Repeat similar checks for column 2 and column 3
        }
    }
}






Voting machine

Introducing the Voting Machine - a modern solution for streamlined and secure voting. With simplicity at its core, voters can easily cast their ballots by pressing one of two switches representing their chosen party. There are no PIN codes or complex procedures, ensuring accessibility for all voters.

Administrators have the flexibility to set a predefined limit for successful votes, allowing for efficient management of the voting process. Additionally, a backend switch provides instant access to the current voting status, facilitating real-time monitoring and decision-making.

Source code:

#include <reg51.h>
#include <stdio.h>
#include <string.h>
#include "4bitlcd.h"
unsigned int j;
unsigned int count1=0;
unsigned int count2=0;
unsigned char count1_vote[4]="0000";
unsigned char count2_vote[4]="0000";
sbit sw1=P3^4;
sbit sw2=P3^5;
sbit sw3=P3^6;
void main()
{   lcd_start();
for(j=0;j<15;j++)
{
if(count1==10 || count2==10)
{			
lcd_cmd(0x01);//clear display
break;
}
lcd_cmd(0x01);//clear display
lcd_cmd(0x80);//first row
string("SW1 FOR CHAI");
lcd_cmd(0xC0);// SECOND LINE
string("SW2 FOR COFFEE");
while(1){
if(sw1==0)
{
lcd_cmd(0x01);//clear display
lcd_cmd(0x80);//first row	
string("VOTE MARKED TO");
lcd_cmd(0xC0);// SECOND LINE
string("CHAI");
delay(20);
count1++;
break;
}
if(sw2==0)
{
lcd_cmd(0x01);//clear display
lcd_cmd(0x80);//first row	
string("VOTE MARKED TO");
lcd_cmd(0xC0);// SECOND LINE
string("COFFEE");
delay(20);
count2++;
break;
}
if(sw3==0)
{
lcd_cmd(0x01);//clear display
lcd_cmd(0x80);//first row	
sprintf(count1_vote,"%d",count1);
string("CHAI VOTES:");
string(count1_vote);
lcd_cmd(0xc0);//first row	
sprintf(count2_vote,"%d",count2);
string("COFFEE VOTES:");
string(count2_vote);
delay(2);
break;
}
}//while loop
}// for loop
if(count1>count2 && count1==10)
{
lcd_cmd(0x01);//clear display
lcd_cmd(0x80);//first row	
string("CHAI HAS WINNED ");
lcd_cmd(0xc0);//first row
string("WITH ");	
sprintf(count1_vote,"%d",count1);		
string(count1_vote);
string(" VOTES");
}
if(count2>count1 && count2==10)
{
lcd_cmd(0x01);//clear display
lcd_cmd(0x80);//first row	
string("COFFEE HAS WINNED ");
lcd_cmd(0xc0);//first row
string("WITH ");	
sprintf(count2_vote,"%d",count2);		
string(count2_vote);
string(" VOTES");
}
}










Comments

Popular Posts