Category: 8051


The popular 16 x 2 LCD can be interfaced with 89S52 in 4 bit or 8 bit mode. To save port pins of microcontroller , often the LCD is used in 4 bit mode.

The connection details are :

Data pins  D4  — P2.0  (pin 21)

                  D5  — P2.1 (pin22)

                  D6  — P2.2 (pin23)

                  D7  — P2.3 (pin24)

Control pins  RS  — P0.0 (pin 39)

                      EN  — P0.1 (pin 38)

                      R/W – GND  

 

89s51_lcd

 

A header file defining all Functions related to LCD control is created and available for Download here .

Including this header file into your project makes programming much easier.

To start with create a folder  for your project , say F:\LCD

Open the KEIL IDE

Click Project – > New uVision Project & browse to the location of the folder created F:\LCD

Provide a filename for the project & select the Target as AT89S52.

Click OK to get the Target1 on the project pane.

Right click the Target1 & click on “Options for Target Target1”

Image 2

 

On the Options windows , select the OUTPUT tab & then check mark the box which says “Create HEX file”

Image 3

Now copy the downloaded lcd.h Header file & paste it to the project folder .

Image 5

 

Back to KEIL IDE , Right click on “Source Group 1” & click on “Add Existing Files to Group “

Browse to the lcd.h file you’ve added to the project & select it.

Image 4

 

Now the Header file is included in to the project folder.

 

Image 6

Right click again on the Source Group 1 & click on “Add new item to Group “

Image 7

On the next screen select the first option “C File “ & provide a name to your C file.

 

Image 9

Feed in the following code :

—————————————-

#include<reg52.h> //including sfr registers for ports of 89s52
#include<lcd.h>  // lcd header file

//LCD Module Connections
sbit RS = P0^0;
sbit EN = P0^1;
sbit D4 = P2^0;
sbit D5 = P2^1;
sbit D6 = P2^2;
sbit D7 = P2^3;
//End LCD Module Connections
void Delay(int a)
{
  int j;
  int i;
  for(i=0;i<a;i++)
  {
    for(j=0;j<100;j++)
    {
    }
  }
   
}
void main()
{
  int i;
  Lcd_Init();
    Lcd_Clear();
  while(1)
  {
    Lcd_Set_Cursor(1,1);
    Lcd_Write_String("8051 LCD Interface");
    for(i=0;i<18;i++)
    {
      Delay(1000);
      Lcd_Shift_Left();
    }
    for(i=0;i<18;i++)
    {
      Delay(1000);
      Lcd_Shift_Right();
    }
    Lcd_Clear();
    Lcd_Set_Cursor(2,1);
    Lcd_Write_Char(‘S’);
    Lcd_Write_Char(‘E’);
    Delay(2000);
  }
}

————————————————

After feeding in the code , click the Save button.

Now click F7 or the Build button to start building target.

 

Image 10

If the code syntax are correct , you get “Creating HEX file “ display on the Output window.

 

Image 13

Now the HEX file is successfully created inside your project folder.

Image 11

 

Connect the ISP programmer to the Development board.Plug in the LCD module on to the LCD port connector.

Connect the USB cable to PC & open the PROGISP software.

Click on File & “Load Flash “ .Browse to the location of the HEX file & select it.

Click on AUTO to perform the programming.

 

Image 12

Now you can see the characters displayed on the LCD.You can adjust the small blue preset if nothing is seen on the LCD.

lcd1 (1)

LCD HEADER file & C file DOWNLOAD

Advertisements

There are 2 types of 7 segment displays , Common Anode & Common Cathode.In this post we shall see how to interface a Common Cathode display with 89S52 Microcontroller.

As the name indicates the cathode points of all segments are made common to GND .To make a segment Glow , the corresponding segment pin is made HIGH.

 

                Image 3

The PORT pins P2.0 to P2.6  are  connected to segments a through  g. The dot pin can be left out.

A NPN transistor is used at the common cathode point . When the base of transistor is made HIGH , it conducts & applies Ground to the Common Cathode point.The transistor is controlled by port pin P1.0

Image 1

 

Following table explains how to arrive at the HEX value for displaying each Digit.

For e.g , to display digit 1 , the segments b & c should be High & all others Low.This corresponds to 0x06 in Hex format.

Similarly to display digit 0 , all segments , except g should be made High, which is hex 0x3F.

For this demo , we do not use the Dot .Hence it is 0 for calculating all other digits.

 

Image 2

 

To start with create a folder say , F:\7segment  to store project files.

Open KEIL click on Project –> New uVision Project & browse to the location of the folder created.Provide a filename & Save.

Select the Target Device as ATMEL AT89S52.

Target1 is created in Project file window of KEIL.

Right click Target 1 & click on “Options for Target Target1”

Image 4

On the Options Window select the tab “ OUTPUT”

Check mark the box “Create HEX file” . This step is important & if you forget check marking this box , no HEX file will be generated.

 

Image 5

 

Now to add the C file to project , Right click Source Group 1 & click on “Add new item to Group “l

Image 6

 

Select the first option C File & provide a Name .Click on ADD

Image 8

 

You can see the .C file added to the project .

Image9

Type in the following  code :

—————————————————————

// Port pin P1.0 is used to Enable the 7 segment CC display
//Port pins of P2 are connected to each segment of CC display

#include<reg52.h>
sbit ledenable=P1^0;
void delay(void);

void main()
{
    P2 = 0x00;
    ledenable=0;
while(1)                  //indefinite loop
  {
     ledenable=1;           // Enable pin for Common cathode display
   P2=0x3f;                          //Display digit 0
   delay();
   P2=0x06;                          //Display digit 1
   delay();
   P2=0x5b;                          //Display digit 2
   delay();
   P2=0x4f;                          //Display digit 3
   delay();
   P2=0x66;                          //Display digit 4
   delay();
   P2=0x6d;                          //Display digit 5
   delay();
   P2=0x7c;                          //Display digit 6
   delay();
   P2=0x07;                          //Display digit 7
   delay();
   P2=0x7f;                          //Display digit 8
   delay();
   P2=0x6f;                          //Display digit 9
   delay();
  }
}
void delay(void)
{
    int j;
    int i;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10000;j++)
        {
        }
    }
}

—————————————–

Instead of a long code you can also use Array as below

First initialize all the segment hex values of the digits in an array.

 

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

Now take for loop and assign array values to the PORT2 with some time delay.

Here is the code using Array :

——————————————————-

#include<reg52.h>

sbit ledenable=P1^0;
void delay();
unsigned char digit[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
unsigned int k;
void main()
{
    P2 = 0x00;
    ledenable=0;
   
  while(1)                  //indefinite loop
   {
    ledenable=1;         // Enable pin for Common cathode display
    
       for(k=0;k<10;k++)
        {
           P2=digit[k];
           delay();
        }
   }
}

void delay()
{
    int j;
    int i;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10000;j++)
        {
        }
    }
}

———————————————————–

 

After Feeding in the code click on SAVE button & then F7 to build the project.

 

Image10

 

If all syntax are correct , compiling will be successful.

 

Image 11

Inside the Project folder you can see the HEX file created.This is the file we’re going to fuse on the Target chip.

Image13

 

Connect the ISP board to the Development board & finally connect the USB cable to pc.

Open the PROGISP software .The PRG ISP & USB ASP buttons should be activated.If any one is greyed out then check for the drivers to be installed for the ISP board.

Click on FILE –> LOAD FLASH & browse to the location of the project folder where the HEX file was generated.

Select the HEX file  .Click on AUTO button to perform the programming.

image12

Once the HEX file is fused , you can see the result on the 7 segment display counting from 0 to 9.

 

7SEG21

The main & first part of your embedded project is creation of .HEX file from the C or Assembly code.For 8051 devices KEIL MICROVISION is a well known IDE .

The free version of KEIL has a limitation of 2k code size.  Programs that generate more than 2 Kbytes of object code will not compile, assemble, or link in the free version.

This software is an integrated development environment (IDE), which integrates a text editor to write programs & a compiler which converts your source code to hex file.This HEX file is then fused on to the target chip.

The free version can be downloaded from :

https://www.keil.com/demo/eval/c51.htm

Install the downloaded KEIL software & open it.

The IDE is simple with 3 windows : Project Workspace , Editing Window & the Output window

Image 2

 

Before starting with your new  project , create a folder for your project. For this e.g we create a folder F:\blinkled

Click on Project – > New uvision project  & browse to the location of the folder we created in F:\

Image 3

 

Provide a filename as “blinkled” & click on Save.

Image 4

 

Device selection window opens automatically. Select the target device as AT89S52 & click OK.

Image 6

 

Confirm with YES button on the next screen.

Image 7

You can see the TARGET1 created under the Project space.

 

Image 8

Right Click on that Target1 & select Options for Target

Image 22

A new Options window opens.Click on the OUTPUT tab .Tick mark against “Create Hex File “.

If you forget to check this option , you will not find the HEX file in the project folder after a Build.

 

Image 10

 

Click OK to close the Options window.

To add the .C file Right click on Source Group1 under Target1 & click on “ Add New item to Group”

Image 11

 

On the next screen select the first option C File ,provide a name & click on ADD.

 

Image 12

 

Now your .c file is added to the Source Group.

Image 13

 

Enter the following code in to the Editor window.

This sample code makes the LED connected to port pin P1.0 BLINK .

 

————————————–

// Program to blink an LED at Port pin P1.0 (physical pin 1 of IC)

#include<reg52.h>  // special function register declarations for 89s52                

#include<stdio.h>  // prototype declarations for I/O functions

sbit LED = P1^0;    // defining pin P1^0 as LED

void delay(void) ;  //delay function prototype declaration

void main (void)
   
{
    LED = 0 ;              // Make LED pin as Output
    while(1)                //indefinite loop
    {
       LED = 0;           // LED Off
       delay();
       LED = 1;          // LED ON 
       delay();
    }
}

void delay(void)
{
    int j;
    int i;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10000;j++)
        {
        }
    }
}

—————————————————–

After entering the code click on the SAVE icon .Now the * mark will vanish on the main.c file.

Image 19

 

Press F7 or click on the BUILD  button to start compiling the code.

Image 20

If there is no syntax error , a HEX file is created inside your project folder.

Image 21

This .HEX file has to be fused on to the Target chip using the ISP programmer & PROGISP software.

This Fusing procedure is explained in the next post.

 

SIMULATION :

KEIL’s inbuilt Debug can be used for Simulation of the code , without any physical Hardware.

Click on Debug – > Start/stop Debug session.

 

Image 23

Now your project workspace window shows most of the SFRs as well as GPRs r0-r7. Also one more window “Watches “ is now open. In this window you can see different variable values.

To add variable in watch window goto "watch#1" tab. Type F2 to edit and enter the name of your variable .

To see the output on ports ,under Peripherals—> select I/O ports – > Port 1.

You can give input to port pins by checking or unchecking the check box. here the check mark means digit 1 and no check mark means 0. The output on the pin will be shown in same manner

To run the program you can use any of the option provided "go", "step by step", "step forward", "step ove" etc.

 

Image 24

 

Press F5 to start simulation .The port pin 1.0 starts blinking to show the result.

Image 25

Click on Debug – > Stop to Exit simulation.

Image 26

 

The 8051 development board can be used as a learners kit as well as a project board.

An ISP programmer is required to fuse the HEX file on to the target 40 pin IC (89S 51 or 89S 52).

The HEX file is created using KEIL software. See previous post to create HEX file

clip_image002

Care should be taken while connecting the ISP programmer with the Development board.Look out for the GND connection printed on the boards .

The GND of ISP must match the GND of Development board.

Connect the USB cable of ISP programmer to USB port of your PC.

No external power is required for the Development board.Power is sourced from USB port of PC.

clip_image004

PROGISP is the software used to load the HEX file on to the target chip.

KEIL Microvision is the software to create HEX file using C code or Assembly language.

Download the software here :

http://www.alselectro.com/files/8051_isp.zip

The drivers for the ISP Programmer is found inside the Drivers folder of PROGISP.

clip_image005

Open the DEVICE Manager of your PC while connecting the ISP programmer to USB port.If you get an exclamation mark against device , Update driver & browse to the location of Drivers inside PROGISP folder you’ve downloaded.

Once the Drivers are installed you get the USBasp under Device manager.

The setup is now ready to load the HEX file.

clip_image006

We use the PROGISP application to load the HEX file on to the target IC. No installation is required for this software , it’s a standalone one.

Double click progisp.exe to open the application.

The PRG ISP & USB ASP buttons should be bright .If it’s greyed out , then check the USB cable connection & the driver installation.

clip_image008

Select the target chip (here 89S 52) from the “Select Chip “ drop down menu.

Ensure that following buttons are Enabled :

Verify Signature

Chip Erase

Program Flash

Verify Flash

If you enable the LOCK CHIP button , others can’t make a copy of your chip.

clip_image010

Click on FILE — > LOAD FLASH & browse to the location of the HEX file you’ve created using KEIL.

clip_image012

clip_image014

Once the HEX file is loaded , click on AUTO button to perform the tasks you’ve enabled.

clip_image016

The status bar at the bottom indicates the progress of operation.

clip_image018

clip_image020

Finally the HEX is successfully loaded on to the target chip.

clip_image022

If the PROGRAM FLASH button is not enabled , you get Flash Verify Error while fusing.

clip_image023 clip_image025

alselectro@gmail.com Technical Blog : http://www.alselectro.wordpress.com

 

First time in India , VEGA ROBOKITS has engineered a development board universal to both AVR & 8051 ICs.The board has in built Programmer capable of programming both AVR & 8051 family ICs.

 

board2

 

A 40 pin ZIF socket is used as Target to hold the 8051 IC. Additional 40 pin ZIF socket with modified connection is provided to host AVR ICs.This additional ZIF socket should be placed over the on- board ZIF socket to use AVR ICs.

 

 

image4

 

board1

 

8051 PROGRAMMER & DEVELOPMENT

To start with we shall see how to use this board for 8051 development.

Select switch 1 to USB position ,if you connect the board to PC using A to B USB cable.Now the power is taken from USB itself. If this switch is selected to other side , the board needs an external 12v/1A adapter.

Select the ISP switch (switch 2 near the middle of board) to ON position.This makes sure that you’re going to program the chip .

Put the jumper (found on top of I2C EEPROM IC) on 8051 position.

 

WILPRO’s WLAR software is used as an application to fuse the HEX files.Download the zip file from :

http://www.alselectro.com/files/wlpro_v220_setup.rar

No installation is required.It is a standalone application.

Download the drivers required for this board from :

http://www.prolific.com.tw/UserFiles/files/PL2303_Prolific_DriverInstaller_v1_10_0_20140925.zip

Unzip the driver file & double click on  “PL2303_Prolific_DriverInstaller_v1.10.0 “  EXE file to install the drivers.

Connect the USB cable of board to PC & open the DEVICE MANAGER.

If the PORT allotted is within range 1 to 9 , you can start the WLPRO application and proceed to load HEX file.

If the port allotted is a double digit , then WLPRO will enter DEMO mode .Only in ON LINE Mode you can load the HEX file.

 

g1

 

To solve this , RIGHT CLICK on the port allotted inside Device Manager & select PROPERTIES.

Under PROPERTIES window select PORT SETTINGS

 

g2

Click on ADVANCED button under PORT SETTINGS.

 

     g3

From the DROP DOWN you can select a PORT number between 1 & 9  &  click OK.

If the port number is not free , you can try overwriting the pre allotted port number & confirm.

 

g4

 

g6

 

g5

 

After PORT setting to single digit  , open the WILLAR software . Now you can see ONLINE MODE at the bottom of screen.

 

g7

Click on DEVICE button & select the target device as AT89S51@ISP 

If you select plain AT89S51 , DEVICE ID ERROR will be returned while programming .So make sure to select the ISP version as device.

Image 6

Click on LOAD button & browse to the location of the HEX file to be fused.Select the HEX file & then click OPEN.

 

g9

 

On the next LOAD FILE window leave the File type as “INTEL HEX” & CLICK ok.

g10

 

You’ll see LOAD FILE SUCCESSFUL display.

Image 7

 

Now click on the PROGRAM button on the left pane.

prog1

 

Programming is DONE & you get Program Successful display.

Image 8

 

If you click the AUTO mode button , all functions like Erase,Blank check ,Program,Verify & code copy Protect will be done automatically one by one.

Image 9

To test the program loaded , change the switch 2 to ISP OFF position .Push RESET button to see the result of blinking LED .

 

AVR PROGRAMMER &DEVELOPMENT

 

Select USB ON (switch 1)

Select the ISP (switch2) to ON position.

Put the Jumper on top of I2C chip to AVR position.

Place the converter socket on the ZIF socket & lock it.Make sure that the handles of sockets match.Do not place the socket in REVERSE as it may damage the target IC.

 

Image 15

On WILLAR IDE select the DEVICE as ATMEGA16L@ISP 

Ensure to select ISP version of IC & not the plain one.

Image 11

 

Select File type as INTEL HEX & click OK.

 

Image 12

 

Click on LOAD & browse to the location of AVR HEX file .

Click OPEN to LOAD the file.

Image 13

 

After LOAD SUCCESSFUL display click on PROGRAM to fuse the file.

 

Image 14

 

Watch this support video  :

 

8051 / AVR UNIVERSAL DEVELOPMENT BOARD WITH PROGRAMMER

For availability of this board contact :  

 

http://www.alselectro.com/8051_avr-2-in-1-development-board-with-programmer-.html

 

cooltext753793315   cooltext753790696