LCD Interfacing with 8051 Microcontroller

Liquid crystal display interfacing with 8051 Microcontroller

INTRODUCTION:

  • It is a popular technology employed in various electronic devices as of the modern century.
  • It makes use of the light properties of liquid crystals.

ADVANTAGES:

  1. They consume less light than LED.
  2. They have more input connections compared to LED.
  3. Constant backlight and it works on the principle of blocking the light instead of emitting it, thus displaying the characters.

 

INTERFACING LCD WITH 8051:

  • The LCD can be interfaced with 8051 microcontroller chip to display many characters or strings in different languages.
  • It is employed in many public areas for displaying shop logos or boards so that it makes it attractive.
  • The corresponding connections are given.

CONNECTION PROCEDURE:

  1. Initially the connections are made as per the pin description table above.
  2. The reset pin( 9th pin) of the micro-controller is connected to the 5V port initially before powering on the circuit.
  3. After powering on the reset pin is connected to ground to enable the displaying of letters.
  4. My name is given as the string to be displayed on the LCD screen.
  5. The LCD initialisation process takes place first after that command is given for cursor and positioning cursor.
  6. Finally the data is displayed using PORT  of the micro-controller with a delay of 50 ms between each letter of “KEVIN MATHEW”.
Program for LCD Interfacing with 8051 Microcontroller (AT89S52)

#include<reg51.h>

#define display_port P1 //Data pins connected to port 2 on microcontroller

sbit rs = P0^2;  //RS pin connected to pin 2 of port 3

sbit rw = P0^3;  // RW pin connected to pin 3 of port 3

sbit e =  P0^4;

sbit DB0= P3^0;

sbit DB1 = P3^1;

sbit DB2= P3^2;

sbit DB3=P3^3;

sbit DB4 =P3^4;

sbit DB5 =P3^5;

sbit DB6=P3^6;

sbit DB7 =P3^7;//E pin connected to pin 4 of port 3

 

void msdelay(unsigned int time)  // Function for creating delay in milliseconds.

{

unsigned i,j ;

for(i=0;i<time;i++)

for(j=0;j<1275;j++);

}

void lcd_cmd(unsigned char command)  //Function to send command instruction to LCD

{

display_port = command;

rs= 0;

rw=0;

e=1;

msdelay(1);

e=0;

}

void lcd_data(unsigned char disp_data)  //Function to send display data to LCD

{

display_port = disp_data;

rs= 1;

rw=0;

e=1;

msdelay(1);

e=0;

}

void lcd_init() //Function to prepare the LCD  and get it ready

{

lcd_cmd(0x38);  // for using 2 lines and 5X7 matrix of LCD

msdelay(10);

lcd_cmd(0x0F);  // turn display ON, cursor blinking

msdelay(10);

lcd_cmd(0x01);  //clear screen

msdelay(10);

lcd_cmd(0x81);  // bring cursor to position 1 of line 1

msdelay(10);

}

void main()

{

unsigned char a[15]=”KEVIN MATHEW; //string of 14 characters with a null terminator.

int l=0;

lcd_init();

while(a[l] != ‘\0’) // searching the null terminator in the sentence

{

    lcd_data(a[l]);

    l++;

    msdelay(50);

}

}

Click here to see the video of LCD Interfacing with 8051 Microcontroller

C program to print the unique elements in an unsorted array

Write a C program to print the unique elements in an unsorted array.

In this c program, we have to print the unique elements for the given Unsorted Array of length N. For example : If there are three occurrences of 7 then we have to print 7 only once.
We can find the unique element in an array by traversing the array from index 0 to N-1 and for each element again traversing the array to find any duplicated element.

C Programming Code

#include<stdio.h>

int main()

{

int n;

printf(“Enter array size: “);

scanf(“%d”, &n);

int a[n];

printf(“Enter %d numbers: “, n);

for(int i=0; i<n; i++)

scanf(“%d”, &a[i]);

int temp = a[0];

for(int i=1; i<n; i++)

{

temp = temp ^ a[i];

}

printf(“Unique element in the array is: %d”, temp);

return 0;

}

Logic behind the Program

Take input from the users and store it in an array(lets call it inputArray).
We will start traversing input Array from index 0 to N -1 and for any element at index i(inputArray[i]), we will search for duplicate element from index 0 to i.
If we find a duplicate element then we skip current element otherwise print it on screen.

Interfacing Seven Segment Display to 8051 Microcontroller with Circuit Diagram

INTERFACING SEVEN SEGMENT DISPLAY WITH 8051 MICROCONTROLLER

INTRODUCTION:

  • It is primarily an electronic device used for displaying alphanumeric values or decimal values.
  • The Seven segment display more commonly used on display board in various complexes and shopping malls.
  • The pivotal role of this display board is to show some command or instructions to the humans that is understandable to them.

CIRCUIT DIAGRAM:

WORKING:

Common Anode Configuration:

  • Depending on the decimal digits to be displayed the particular set of LED’S are forward biased.
  • Example:  If we want to light the digit 8 seven digits has to be lighted up in order to display it.

TRUTH TABLE:

 

  • The above table indicates the corresponding LED’s to be displayed in order to get the corresponding numbers.(0-9).
  • Both common cathode and common cathode is present.

PIN DIAGRAM:

CODING FOR SINGLE DIGIT:

#include<reg51.h>

void delay(int k) //delay function

{

int i,j;

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

 for(j=0;j<1275;j++);

}

void main()

{

unsigned char i;

unsigned char arr[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};

P2=0x00;

while(1)

{

 for(i=0;i<10;i++)

 {

  P2=arr[i];

  delay(100);

 }

}

}

PROCEDURE:

  1. Firstly burn the program to microcontroller.
  2. Then make the connections as per circuit diagram.
  3. We must make sure that pins a to g of seven segment are given to P2.0 to P2.6 of microcontroller(PORT 2).
  4. Switch on the power supply then he numbers 0 – 9 starts displaying after some interval.
  5. This process repeats itself in an infinite loop.

CONNECTION DIAGRAM:

PROJECT EXECUTION VIDEO:

Click here to see the Video

C Program to Print the Age and Name of Employee.

Write a C program to print the age and name of employee using fprintf() and fscanf() operations.

So far we have seen many programs. This is not enough if we need to write characters, strings, and integers in one single file, in that case, we use fprintf() function. The fprintf() function is used to write set of characters into the file. It sends formatted output to a stream.
The fscanf() function is similar to scanf() function except for the first argument which is a file pointer that specifies the file to be read.

C Programming Code:

#include<stdio.h>

struct emp
{
   char name[10];
   int age;
};

void main()
{
   struct emp e;
   FILE *p,*q;
   p = fopen(“one.txt”, “a”);
   q = fopen(“one.txt”, “r”);
   printf(“Enter Name and Age:”);
   scanf(“%s %d”, e.name, &e.age);
   fprintf(p,”%s %d”, e.name, e.age);
   fclose(p);
   do
   {
       fscanf(q,”%s %d”, e.name, e.age);
       printf(“%s %d”, e.name, e.age);
   }
   while(!feof(q));
}

LED Interfacing with 8051 Microcontroller with Circuit Diagram Tutorial

LED INTERFACING WITH  8051 MICROCONTROLLER:

INTRODUCTION:

LED is a light emitting diode.It is used for lighting purposes in many electronic devices.

8051 Development board:

EXPLANATION:

  • Here on the development board  we can see 8 LEDS meant for interfacing with the 8051 microcontroller family.
  • The steps involved in this project are as follows:-
  1. Compiling source code on Keil using C language.
  2. Programming the microchip using debugger.
  3. Interfacing the chip with LED through 8051 development board.
  4. Creating the schematic capture simulation diagram using Proteus software.
  5. Verifying the simulation and thereby compiling the schematic after verification is done.

VIDEO OF LED TOGGLING:-

SOURCE CODE:

#include<reg51.h>

sbit LED=P1^0;

void toggle(void);

void delay(int a);

int main(void)

{

toggle();

while(1)

{

  LED=0;

  delay(50000);

  LED=1;

  delay(50000);

}

}

void toggle(void)

{

P2=0x00;

}

void delay(int b)

{

int i;

for(i=0;i<b;i++);

}

CIRCUIT WORKING:

  • Here in this circuit I have toggled the second LED (left to right from port 0) by the interfacing the 8051 microcontroller using the PORT 1 of the microcontroller.
  • Initially the Reset pin (9th pin of 8051 chip) is connected to the 5V pin before connecting the 9V Power supply.
  • After 5V passes through circuit then the RESET  pin is connected to ground.
  • A wire connection is given from the P2.0 of port 2 (single bit) to the second LED .
  • The LED starts to glow white.
  • The value of 50,000 USING Keil generates around 1s between on and off time. This is for the crystal oscillator of frequency 11.0592 Mhz.

PROTEUS SCHEMATIC:

C Program to Sort N Names in Alphabetical Order

Write a C program to sort N names in alphabetical order.

In the following C program user would be asked to enter a set of N names and the program would sort and display them in ascending alphabetical order.Learn How To Sort Names in Alphabetical Order in C Programming Language. The program is successfully compiled and tested

C Programming Code

 #include <stdio.h>

  #include <string.h>

  void main()

  {

      char name[10][8], tname[10][8], temp[8];

      int i, j, n;

      printf(“Enter the value of n \n”);

      scanf(“%d”, &n);

      printf(“Enter %d names n”, \n);

      for (i = 0; i < n; i++)

      {

          scanf(“%s”, name[i]);

          strcpy(tname[i], name[i]);

      }

      for (i = 0; i < n – 1 ; i++)

      {

          for (j = i + 1; j < n; j++)

          {

              if (strcmp(name[i], name[j]) > 0)

              {

                  strcpy(temp, name[i]);

                  strcpy(name[i], name[j]);

                  strcpy(name[j], temp);

              }

          }

      }

      printf(“\n—————————————-\n”);

      printf(“Input NamestSorted names\n”);

      printf(“——————————————\n”);

      for (i = 0; i < n; i++)

      {

          printf(“%s\t\t%s\n”, tname[i], name[i]);

      }

      printf(“——————————————\n”);

  }

 

Climate Control in Green House Using Intelligent Control Monitoring System

CONTROLLING GREENHOUSE USING INTELLIGENT CONTROL  MONITORING SYSTEM

INTRODUCTION:

  • The sole purpose of this project is to protect the nurturing plants and additional system of control is employed to conserve energy as it is the vital source for power.
  • This intelligent contraption involves the combination of sensors and microcontrollers.
  • Specific agricultural plants require specific amount of humidity, hence the application of humidity sensor is found here since it’s a big hassle for the farmers to accurately measure from the soil.

DIGITAL SENSOR:

Light sensor:

  • It is a type of resistance that can be varied.
  • Then a specific intensity of light falls on the microcontroller the controller activates the sensor and after some time it turns off.
  • This controller facilitates automatic switching of lights in order to save energy.
  • PIC16F887A is the microcontroller used in this project.

HUMIDITY SENSOR:

  • This is employed in agricultural farms since both low levels or high levels can prove detrimental to the life expectancy of the crops sown by our hardworking farmers.
  • HS1101 is an unique type of humidity sensor.
  • If the humidity in air exceeds a specific value then the microcontroller gives signal to the relay.
  • The frequency so measured is calculated  using some preallocated algorithm within the microcontroller.

MOISTURE SENSOR:

  • It is used to measure the moisture present in the soil.
  • For thism, a wire strip is inserted into the soil.
  • The way it works is like whenever the moisture content is less, the resistance of the strip goes high and vice versa.
  • Therefore the PIC16F877A is used to control the functioning of water pump using the moisture sensor.

APPLICATIONS:

  1. Wireless sensor can be incorporated along with this  circuit in order to inform the values and measurements. user who is not at a remote location.
  2. In absolutely any existing greenhouse for employing self automated control of devices.

 

C Program to Sort N Names in Alphabetical Order.

Write a C program to sort N names in alphabetical order.

Learn how to sort names in alphabetical order in c programming language. This C Program To Arrange Names in Ascending Order. In the following C Program, the user would be asked to enter some names as input & then sorts them in an alphabetical order.

C Programming Code

#include <stdio.h>                                                                                  

  #include <string.h>

  void main()

  {

      char name[10][8], tname[10][8], temp[8];

      int i, j, n;

      printf(“Enter the value of n \n”);

      scanf(“%d”, &n);

      printf(“Enter %d names n”, \n);

      for (i = 0; i < n; i++)

      {

          scanf(“%s”, name[i]);

          strcpy(tname[i], name[i]);

      }

      for (i = 0; i < n – 1 ; i++)

      {

          for (j = i + 1; j < n; j++)

          {

              if (strcmp(name[i], name[j]) > 0)

              {

                  strcpy(temp, name[i]);

                  strcpy(name[i], name[j]);

                  strcpy(name[j], temp);

              }

          }

      }

      printf(“\n—————————————-\n”);

      printf(“Input NamestSorted names\n”);

      printf(“——————————————\n”);

      for (i = 0; i < n; i++)

      {

          printf(“%s\t\t%s\n”, tname[i], name[i]);

      }

      printf(“——————————————\n”);

  }

What is PIC Microcontroller ? PIC Microcontroller Architecture, Working and Application

PIC MICROCONTROLLERS

INTRODUCTION:

  • It is created by microchip technology which originated from the PIC160.
  • The early versions of PIC had only a Read only memory and Erasable Programmable Read only memory.
  • The abbreviation originally stood  for Peripheral interface controller but was later changed to Programmable intelligent computers.
  • These PICS were introduced in 1975 for the sole purpose of off-loading Input/Output tasks from the CPU in order to enhance the efficiency of the processor.

FEATURES:

 

  • Low cost.
  • Wide availability.
  • Different communication protocols are compatible such as:-

 

 

1.CAN

2.I2C

3.UART(Universal Asynchronous Receiver transmitter)

4.USB(UNIVERSAL SERIAL BUS)

CORE ARCHITECTURE:
  • Harvard architecture is employed here in this family.
COMPONENTS:

 

1.) DRAM(DATA MEMORY):

  • The PIC family comprises of a special registers that function as general purpose RAM.
  • These devices are employed with have banking mechanisms in order to extend memory.
  • An important point to note is that the external memory is not addressable.

   2.) CODESPACE:

  • There exists no facilities for the provision of external memory in the absence of such module.
  • Therefore usually the memory storage takes place on the following:-
    • ROM
    • PROM
    • EPROM

Exceptions: – PIC18  and PIC17.

   3.) WORD SIZE:

  • Program memory is usually implemented in single word instructions instead of bytes.
  • The addresses are handled in 8-bit format by these PIC microcontroller.
  • PIC 12 and PIC 16 have addresses of the same size as the instruction width size.
  • PIC 18 has address memory size as 8-bit increments which differs from instruction width of 16 bits.

    4.) STACKS:

  • Generally the PIC devices had a hardware module known as cell stack for the sole purpose of  storing return addresses.
  • The stacks present in the earlier versions was not accessible for software editing.
  • However the latest one PIC 18 has enabled software editing for the stack hardware module.

    5.) INSTRUCTION SET

  • Te Programmable intelligent controllers(low end ) has 35 bit instructions.
  • Whereas the high end one’s have over 80 instruction sets.
ADVANTAGES:-
  1. Reduced instruction set(RISC).
  2. Internally embedded oscillator with tunable speeds.
  3. Inexpensive microcontrollers.
  4. The wide availability of Dual inline Packages which makes it convenient for usage
LIMITATIONS:
  • Unfortunately only a single accumulator is available.
  • Operations and registers are not repetitive implying that sometimes single.
  • The cell stacks that are software programmed  will not be that efficient for addressing memory.

PAGED PROGRAM MEMORY:

  • We have two separate page memories pose a problem.
  • One is known s CALL whereas the other one is called GOTO(usually implemented in lookup tables)
  • They both comprise of 11 addressing bits so the page is 2048 instruction words.

BOOTLOADING:

  • Most of the modern flash based PIC’s can self-program itself.However there exists an alternative solution for programming.
  • The bootloader firmware enables the user to load on the PIC microchip using  The Inline serial port in conjunction with specific program software.

ADVANTAGES OF BOOTLOADER:

  • Quicker programming when compared to ICSP programming.
  • On the spot execution along with programming.
  • Programming and debugging can both be done using the same cable.

HARDWARE FEATURES:

1.EEPROM

2.Flash features

3.Watchdog timer

4.Sleeping modee

5.Various oscillator crystal configurations.

DEVICE PROGRAMMERS:

  • These devices are used to feed the program coding into the PIC chip.
  • Some of the famous programmers/ debuggers are:-
  1. MPLAB ICE
  2. MPLAB ICD4

In circuit emulators:

  • MPLABICE2000 is an example of a  full circuit emulators.
  • These tools are used in conjunction with the debuggers previously mentioned above for source level of target code.

PERFORMANCE:

  • Speed to cost ratio maximized here.
  • The  latency of interrupts is constant at three instruction cycles.
  • Timing and the design of microcircuit are efficiently saved.
  • The peculiar feature is that by default all the internal interrupts are already synchronized whereas the external interrupts have to be produced simultaneously with the four input clock cycles.

APPLICATIONS:

In most modern devices such as:-

  1. Mobile phones
  2. Vehicle systems
  3. Aerospace mechanisms

C Program to Merge two Sorted Array

Write a C Program to Merge the Elements of 2 Sorted Array.

This C Program teach you how to merge the elements of 2 sorted array.

C Programming Code

 #include <stdio.h>

  void main()

  {

      int array1[50], array2[50], array3[100], m, n, i, j, k = 0;

      printf(“\n Enter size of array Array 1: “);

      scanf(“%d”, &m);

      printf(“\n Enter sorted elements of array 1: \n”);

      for (i = 0; i < m; i++)

      {

          scanf(“%d”, &array1[i]);

      }

      printf(“\n Enter size of array 2: “);

      scanf(“%d”, &n);

      printf(“\n Enter sorted elements of array 2: \n”);

      for (i = 0; i < n; i++)

      {

          scanf(“%d”, &array2[i]);

      }

      i = 0;

      j = 0;

      while (i < m && j < n)

      {

          if (array1[i] < array2[j])

          {

              array3[k] = array1[i];

              i++;

          }

          else

          {

              array3[k] = array2[j];

              j++;

          }

          k++;

      }

      if (i >= m)

      {

          while (j < n)

          {

              array3[k] = array2[j];

              j++;

              k++;

          }

      }

      if (j >= n)

      {

          while (i < m)

          {

              array3[k] = array1[i];

              i++;

              k++;

          }

      }

      printf(“\n After merging: \n”);

      for (i = 0; i < m + n; i++)

      {

          printf(“\n%d”, array3[i]);

      }

  }

Logic

  1. Create two arrays of fixed size and define their elements in sorted fashion.
  2. Take any two variables say i and j for the 0th position of these two arrays.
  3. Then the elements will be compared one by one using i and j in for loop, and whichever element is smaller than the other, that element will get inserted to final array will move by one, whereas the other array’s track position will remain in that same place.
  4. Above work will be done till we reach the end of either array. After that, one of the arrays whose elements are still to be added, its elements will get straightaway added to the final array.

En-Query

Your Name*
Subject*
Phone Number*
Email Address*

Message*