8051 Trainer Kit-User Manual - V1.0-22

Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

8051 Trainer Kit

Start Your Embedded System Design Journey Today..!


8051 essential development features a plug and play design that makes it easy for connections
and helps Students, hobbyists, enthusiasts, and professionals to focus more on Program /
application development. 8051 Trainer kit equipped with on board IO‟s, communication
interfaces & peripherals. It is really easy to design, experiment with, and test circuits without
soldering. It‟s used in many educational institutions and R&D LAB accros the world.

www.researchdesignlab.com RDL Technologies Pvt Ltd 1


8051 Trainer Kit

Features:

 Plug & Play Interface  4* 4 Matrix Keypad.


Connectivity.
 RS232, RS485, USB communication
 Professional EMI/RFI Complaint port.
PCB Layout Design  7 Segment Multiplexed Display.
 Modular Block design makes Easy
 16*2 LCD & OLED Display
access & quick Prototyping
 ADC & DAC Card.
 FRC connectivity features
minimize the connection Error.  8 bit 4 port IO.
 High Quality Grade PCB with  On Board WiFi /Bluetooth
wooden Enclosure. Connectivity
 The DIP40 locking device for reuse  3.3 to 5V Level Converter.
ATMEL microcontroller.  Power Supply 3.3V and 5V
 Supports 8051, AT89SXX and  SD CARD Interface.
AT89CXX series chips 40 pin DIP  RTC & EEPROM Interface.
package.  DC Motor/ Stepper Motor Driver.
 On Board Programming.  Relay, Buzzer.
 8 interfacing LED‟s.  1xTemperature Sensor.
 1 * 4 Menu keypad.
 3x Analog Test POT.

Scope of Learning Experiments:

 LED blinking.  Elevator Interface.


 8 bit LED Left shift, Right shift  Buzzer, Relay interface.
and counting operation.  RS232 serial, RS485 and USB
 Keypad Interrupt Interface communication.
 16*2 LCD interface.  UART Operation
 Matrix Keypad Interface.  RTC DS1307 I2C protocol
 ADC & DAC interface. interface.
 Traffic Light Signal Interface.  AT24C04 EEPROM I2C protocol
 8 bit DIP switch interface. interface.
 7 Segment interface.  RF/ WiFi Communication.
 L298 Driver for DC Motor and  Temperature Sensor Interface.
Stepper motor interface.

www.researchdesignlab.com RDL Technologies Pvt Ltd 2


8051 Trainer Kit

Technical Specification:

Specifications
MCU 89V51RD2,AT89S52,AT89SXX
and AT89CXX
Crystal Frequency 11.0592 MHz

Communication Port USB RS232 and RS485

Power Supply 12V,2A

Supported IDE Keil Version 2,3,4,5


Mikro c Pro

Dimension W 264 X L 199 X H 60

8051 Board Narration

www.researchdesignlab.com RDL Technologies Pvt Ltd 3


8051 Trainer Kit

1. Power Supply 13.1*4 Keypad Switches


2. Power ON Switch 14. RDL Bus FRC Connector
3. Heat Sink 15. Keypad Matrix

4. ADC (Variable Resistor POT) 16. 8051 Controller

5. OLED Display 17. 7 Segment Display

6. Digital Input Switch 18. 2*4 LED's


19. Jumper Settings for UART Selection
7. RTC Battery
Pin
8. Buzzer
20. 16*2 LCD Display
9. Relay
21. WiFi Module
10. SD Card Holder
22. Jumper Settings for UART TTL
11. Jumper Settings for I2C RTC
23. USB Port
12. Jumper Settings for EEPROM
24. DB-9 Serial Female Connector

www.researchdesignlab.com RDL Technologies Pvt 4


Ltd
8051 Trainer Kit

Application:

 Light sensing & controlling Industrial Control Devices


devices
 Process control devices
 Temperature sensing and
 Industrial instrumentation devices
controlling devices
 Industrial Applications
 Fire detection & safety devices
 IoT Applications
 Industrial instrumentation devices
 Application of microcontroller in

Package Includes:

 Development Board with Wooden Enclosure


 USB Cable.
 12V, 2A Adapter
 FRC Cable

www.researchdesignlab.com RDL Technologies Pvt 5


Ltd
8051 Trainer Kit

CONTENTS

Keil Setup For 8051 ................................................................................................................... 7


Nuvoton ISP-ICP Utility .......................................................................................................... 13
Blinking an LED ...................................................................................................................... 16
Liquid Crystal Display ............................................................................................................. 19
Seven Segment Display ........................................................................................................... 23
Hex Keypad ............................................................................................................................. 27
RTC (Real Time Clock) ........................................................................................................... 32
UART....................................................................................................................................... 41
EEPROM ................................................................................................................................. 45

www.researchdesignlab.com RDL Technologies Pvt 6


Ltd
8051 Trainer Kit

Keil Setup For 8051

Keil software can be downloaded from this link.

Download and install the Keil Microvission 5 for 8051.

Keil Setup Steps


Step1: Open the Keil software and select the New Microvission project from Project Menu as
shown below.

www.researchdesignlab.com RDL Technologies Pvt 7


Ltd
8051 Trainer Kit

Step2: Browse to your project folder and provide the project name(Ex: LED) and save it.

Step3: Once the project is saved a new pop up “Select Device for Target” opens, Select the
required 8051 series controller and click on OK.

Select Nuvoton  W78E052D  Click Ok  Click Yes

www.researchdesignlab.com RDL Technologies Pvt 8


Ltd
8051 Trainer Kit

Step4: Create a new file to write the program.

Step5: Type the code or Copy paste the code and save the file (Ex: Led.c).

www.researchdesignlab.com RDL Technologies Pvt 9


Ltd
8051 Trainer Kit

Compiling and building the C project using Keil Uvision IDE

Step6: In order to build your recently created C program go to Project tab and click on Build
Target on the menu bar. An alternate way to do this is by Clicking on Build icon or by pressing
the F7 key. If the code that you have written is correct, the code will successfully compile
without any errors.

Generating the hex file using Keil Uvision IDE

Step7: Right click on Target 1 and select  Options for Target „Target 1‟

www.researchdesignlab.com RDL Technologies Pvt 10


Ltd
8051 Trainer Kit

Step8: Set the Xtal (MHz) to 11.0592.

Step9: Click on Output tab, Make sure Create Hex File option is selected and the HEX format
should be HEX-80  Click Ok.

Step10: Add the file to the project, right click on Source Group 1  Add Existing files to‟
Source Group 1‟.

www.researchdesignlab.com RDL Technologies Pvt 11


Ltd
8051 Trainer Kit

Step11: Select the already Saved files and Click on Add.

Step12: Now the Led.c file should appear in Project Source Group.

www.researchdesignlab.com RDL Technologies Pvt 12


Ltd
8051 Trainer Kit

Nuvoton ISP-ICP Utility

For installing drivers and Nuvoton ISP-ICP Utility Software, CLICK HERE.

Uploading Hex File Using Nuvoton

Step1: Using a USB cable, connect the 8051 Trainer Kit to your computer.

NOTE: Before Uploading any hex file to the Trainer Kit, make the
below settings
1. Make FTRX and FTTX pins of DIP2 HIGH
2. Make all pins of DIP1 HIGH

Step2: Open Nuvoton Software to upload the hex File.

Step3: Click the radio button ISP by Com Port, Select the Com Port

NOTE: Ensure that you have the FTDI Com port driver loaded. Please
download and install from the link provided below if it is not installed.

Link: https://ftdichip.com/drivers/d2xx-drivers/
For Installation Guide , CLICK HERE

Step4: Select the IC (W78E052D)

www.researchdesignlab.com RDL Technologies Pvt 13


Ltd
8051 Trainer Kit
Step5: Click on Load file, select the Hex file created and click on Open.

Step6: Click on Upload Chip, and press the reset switch of the 8051 Microcontroller.

Reset Switch

www.researchdesignlab.com RDL Technologies Pvt 14


Ltd
8051 Trainer Kit

Step7: You will get a FAIL dialog Box, Click on Ok.

Step8: You will get a PASS dialog Box, Click on Ok.

www.researchdesignlab.com RDL Technologies Pvt 15


Ltd
8051 Trainer Kit

EXPERIMENT NO 1
Blinking an LED
Aim:
Interfacing LED‟s with 8051-Microcontroller.

Description:
Turning ON and OFF an LED‟s after Particular delay.

Hardware Requirement:
8051 Trainer Kit ,FRC cable and USB A to B cable.

Procedure:

1. Connect P2 port and SV2 (LED) port using FRC cable as shown above.
2. Connect the USB cable to the board.
3. Open Keil uVision,write the program to blink LED.Then click on Build to verify the code.
4. Open Nuvoton Software to upload the hex File.
6. Click the radio button ISP by Com Port, Select the Com Port.
7. Select the IC (W78E052D).

www.researchdesignlab.com RDL Technologies Pvt 16


Ltd
8051 Trainer Kit

8. Click on Load file, select the Hex file created and click on Open.
9. Click on Upload Chip, and press the reset switch of the 8051 Microcontroller.
10. You will get a FAIL dialog Box, Click on Ok.
11. You will get a PASS dialog Box, Click on Ok.
10. Press the reset switch of the 8051 Microcontroller and you can see the LED blink.

Program:

/*
* Project name:
8051 Development Board
* Copyright
(c) Researchdesignlab.com
* Description:

* Test configuration:
MCU: AT89S52
Dev.Board: 8051
Oscillator: 11.0592 MHz
Software: Keil uVision3

*/
#include<reg52.h> //special function register declarations
//for the intended 8051 derivative
void delay(); // Function prototype declaration

sbit LED0=P2^0; //Define Port Pin P2.0 as LED0


sbit LED1=P2^1; //Define Port Pin P2.1 as LED1
sbit LED2=P2^2; //Define Port Pin P2.2 as LED2
sbit LED3=P2^3; //Define Port Pin P2.3 as LED3
sbit LED4=P2^4; //Define Port Pin P2.4 as LED4
sbit LED5=P2^5; //Define Port Pin P2.5 as LED5
sbit LED6=P2^6; //Define Port Pin P2.6 as LED6
sbit LED7=P2^7; //Define Port Pin P2.7 as LED7

void main() //Main Code


{
P2=0x00; //Set Port 2 all bits to 0

while(1) // Continuous loop


{
LED0=1; //Turn ON LED0
delay(); //Wait for a small delay
LED1=1; //Turn ON LED1
delay(); //Wait for a small delay
LED2=1; //Turn ON LED2
delay(); //Wait for a small delay
LED3=1; //Turn ON LED3
delay(); //Wait for a small delay
LED4=1; //Turn ON LED4
delay(); //Wait for a small delay

www.researchdesignlab.com RDL Technologies Pvt 17


Ltd
8051 Trainer Kit
LED5=1; //Turn ON LED5
delay(); //Wait for a small delay
LED6=1; //Turn ON LED6
delay(); //Wait for a small delay
LED7=1; //Turn ON LED7
delay(); //Wait for a small delay

P2=0x00; //Turn OFF all LED's


delay(); //Wait for a small delay

}
}

void delay() // Delay Routine


{
unsigned int x=60000; // larger the value of x the more is the delay.
while (x--); // executes this statement until x decrements to 0;
}

www.researchdesignlab.com RDL Technologies Pvt 18


Ltd
8051 Trainer Kit

EXPERIMENT NO 2
Liquid Crystal Display

Aim:

Interfacing LCD Display with 8051-Microcontroller.

Description:

To display the message on the LCD screen.

Hardware required:

8051 Trainer Kit, FRC cable and USB A to B cable.

Procedure:

1. Connect P2 port and SV1(LCD 16*2 Display) port using FRC cable as shown above.

2. Connect the USB cable to the board.

3. Open Keil uVision,write the program to display the message in the LCD.Then click on
Build to verify the code.
4. Open Nuvoton Software to upload the hex File

www.researchdesignlab.com RDL Technologies Pvt 19


Ltd
8051 Trainer Kit

6. Click the radio button ISP by Com Port, Select the Com Port
7. Select the IC (W78E052D)
8. Click on Load file, select the Hex file created and click on Open
9. Click on Upload Chip, and press the reset switch of the 8051 development board.
10. You will get a FAIL dialog Box ,Click on Ok.
11. You will get a PASS dialog Box, Click on Ok.
10. Press the reset switch of the 8051 Microcontroller and you can see the message displayed
on the LCD.

Program:

#include<reg51.h>

sbit D7=P2^7;
sbit D6=P2^6;
sbit D5=P2^5;
sbit D4=P2^4;

sbit rs=P2^0; /* Register select pin */


sbit en=P2^1; /* Enable pin */

//#define LCD_Port P2
int LCD_Port ;

/* Function to provide delay Approx 1ms with 11.0592 Mhz crystal*/


void delay(unsigned int count)
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<112;j++);
}

void LCD_Command (char cmnd) /* LCD16x2 command funtion */


{
LCD_Port = (cmnd & 0xF0)>>4;/* Send upper nibble */
D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;
D4=LCD_Port&0X01;
rs=0; /* Command reg. */
// rw=0; /* Write operation */
en=1;
delay(1);
en=0;
delay(2);

LCD_Port = (cmnd & 0x0F);/* Send lower nibble */


D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;
D4=LCD_Port&0X01;

www.researchdesignlab.com RDL Technologies Pvt 20


Ltd
8051 Trainer Kit
rs=0;
en=1; /* Enable pulse */
delay(1);
en=0;
delay(5);
}

void LCD_Char (char char_data) /* LCD data write function */


{
LCD_Port =(char_data & 0xF0)>>4;/* Send upper nibble */
D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;
D4=LCD_Port&0X01;
rs=1; /*Data reg.*/
// rw=0; /*Write operation*/
en=1;
delay(1);
en=0;
delay(2);

LCD_Port = (char_data & 0x0F);/* Send lower nibble */


D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;
D4=LCD_Port&0X01;
en=1; /* Enable pulse */
delay(1);
en=0;
delay(5);

void LCD_String (char *str) /* Send string to LCD function */


{
int i;
for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL */
{
LCD_Char (str[i]); /* Call LCD data write */
}
}

void LCD_String_xy (char row, char pos, char *str) /* Send string to LCD
function */
{
if (row == 0)
LCD_Command((pos & 0x0F)|0x80);
else if (row == 1)
LCD_Command((pos & 0x0F)|0xC0);
LCD_String(str); /* Call LCD string function */
}

void LCD_Init (void) /* LCD Initialize function */


{
delay(20); /* LCD Power ON Initialization time >15ms */
LCD_Command (0x02); /* 4bit mode */
LCD_Command (0x28); /* Initialization of 16X2 LCD in 4bit mode */
LCD_Command (0x0C); /* Display ON Cursor OFF */
LCD_Command (0x06); /* Auto Increment cursor */

www.researchdesignlab.com RDL Technologies Pvt 21


Ltd
8051 Trainer Kit
LCD_Command (0x01); /* clear display */
LCD_Command (0x80); /* cursor at home position */
}

void main()
{
LCD_Init(); /* Initialization of LCD*/
LCD_String("RDL TECHOLOGIES"); /* write string on 1st line of LCD*/
LCD_Command(0xC0); /* Go to 2nd line*/
LCD_String_xy(1,0,"lcd display"); /*write string on 2nd line*/
while(1); /* Infinite loop. */
}

www.researchdesignlab.com RDL Technologies Pvt 22


Ltd
8051 Trainer Kit

EXPERIMENT NO 3
Seven Segment Display

Aim:
Interfacing Seven Segment Display with 8051-Microcontroller.

Description:
To display numbers in the seven segment.

Hardware Required:
8051 Trainer Kit,FRC cables and USB A to B cable.

Procedure:
1. Connect P2 port and SV4(Data) port and connect P1 port and SV3(Select) port using FRC
cable as shown above
2. Connect the USB cable to the board.
3. Open Keil uVision,write the program to display numbers in the seven segment.Then click
Build to verify the code.
4. Open Nuvoton Software to upload the hex File

www.researchdesignlab.com RDL Technologies Pvt 23


Ltd
8051 Trainer Kit

6. Click the radio button ISP by Com Port, Select the Com Port
7. Select the IC (W78E052D)
8. Click on Load file, select the Hex file created and click on Open
9. Click on Upload Chip, and press the reset switch of the 8051 development board.
10. You will get a FAIL dialog Box ,Click on Ok.
11. You will get a PASS dialog Box, Click on Ok.
10. Press the reset switch of the 8051 Microcontroller and you can see the displayed numbers
in the seven segment.

Program:

/*
* Project name:
8051 Development Board
* Copyright
(c) Researchdesignlab.com
* Description:

* Test configuration:
MCU: AT89S52
Dev.Board: 8051
Oscillator: 11.0592 MHz
Software: Keil uVision3

*/

#include<reg51.h>
unsigned int portb_index,portb_array[4],digit, COUNT=0;

unsigned short mask(unsigned short num) {


switch (num) {

case 0 : return 0xC0;


case 1 : return 0xF9;
case 2 : return 0xA4;
case 3 : return 0xB0;
case 4 : return 0x99;
case 5 : return 0x92;
case 6 : return 0x82;
case 7 : return 0xF8;
case 8 : return 0x80;
case 9 : return 0x90;
/*
case 0 : return 0x03;
case 1 : return 0x9F;
case 2 : return 0x25;
case 3 : return 0x0D;
case 4 : return 0x99;
case 5 : return 0x49;
case 6 : return 0x41;
case 7 : return 0x1F;

www.researchdesignlab.com RDL Technologies Pvt 24


Ltd
8051 Trainer Kit
case 8 : return 0x01;
case 9 : return 0x09;*/
} //case end

}
void timer0(void) interrupt 1 {

IE=0;
P1 = 0XFF; // Turn off all 7seg displays
P2= portb_array[portb_index]; // bring appropriate value to PORTB
if(portb_index==0)
P1 = 0XF7;
else if(portb_index==1) // turn on appropriate 7seg. display
P1 = 0XFB;
else if(portb_index==2) // turn on appropriate 7seg. display
P1 = 0XFD;
else if(portb_index==3) // turn on appropriate 7seg. display
P1 = 0XFE;

portb_index++ ;
if (portb_index > 4)
portb_index = 0; // turn on 1st, turn off 2nd 7seg.
TH0=0xA4; //TH0=-92
IE=0x82;
// Clear T0IF
}

void display(unsigned int number)


{

digit = number / 1000u ; // extract thousands digit


portb_array[3] = mask(digit); // and store it to PORTB array
digit = (number / 100u) % 10u; // extract hundreds digit
portb_array[2] = mask(digit); // and store it to PORTB array
digit = (number / 10u) % 10u; // extract tens digit
portb_array[1] = mask(digit); // and store it to PORTB array
digit = number % 10u; // extract ones digit
portb_array[0] = mask(digit); // and store it to PORTB array

}
void DELAY()
{
unsigned int X=60000;
while(X--);
}
void main() {

// Enable GIE, T0IE


TMOD=0x02;
TH0=0xA4; //TH0=-92
TR0=1;
IE=0x82;
P1 = 0xFF;
DELAY();
COUNT=0;
while(1)
{

www.researchdesignlab.com RDL Technologies Pvt 25


Ltd
8051 Trainer Kit

display(1111);
DELAY();
display(2222);
DELAY();
display(3333);
DELAY();
display(4444);
DELAY();
display(5555);
DELAY();
display(6666);
DELAY();
display(7777);
DELAY();
display(8888);
DELAY();
display(9999);
DELAY();
display(0000);

//COUNT=COUNT+15;
//if(COUNT>2000)
//COUNT=0;
}
}

www.researchdesignlab.com RDL Technologies Pvt 26


Ltd
8051 Trainer Kit

EXPERIMENT NO 4
Hex Keypad

Aim:

To interface 4x4 Hex keypad with 8051-Microcontroller.

Description:
To display the pressed key on the LCD Display.

Hardware Required:
8051 Trainer Kit,FRC Cables and USB A to B Cable .

Connect P0 port and


SV5 port using FRC
cable

Connect P2 port and


SV1 port using FRC
cable

Procedure:

1. Connect P0 port and SV5(4*4 Key Matrix) port and Connect P2 port and SV1 port
using FRC cable as shown above.
2. Connect the USB cable to the board.
3. Open Keil uVision,write the program to display the pressed key on the LCD
Display.Then click Build to verify the code.

www.researchdesignlab.com RDL Technologies Pvt 27


Ltd
8051 Trainer Kit

4. Open Nuvoton Software to upload the hex File


5. Click the radio button ISP by Com Port, Select the Com Port
6. Select the IC (W78E052D)
7. Click on Load file, select the Hex file created and click on Open
8. Click on Upload Chip, and press the reset switch of the 8051 development board.
9. You will get a FAIL dialog Box ,Click on Ok.
10. You will get a PASS dialog Box, Click on Ok.
11. Press the Reset Button of the 8051 Microcontroller, the number appears for each switch
pressed on the LCD Display.

Program:

#include<reg51.h>
sbit D7=P2^7;
sbit D6=P2^6;
sbit D5=P2^5;
sbit D4=P2^4;
sbit rs=P2^0; /* Register select pin */
sbit en=P2^1; /* Enable pin */

#define KeyPort P0
unsigned char check();
unsigned int LCD_Port;
void delay12(unsigned int time);
/* Function to provide delay Approx 1ms with 11.0592 Mhz crystal*/
void delay(unsigned int count)
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<112;j++);
}

void LCD_Command (char cmnd) /* LCD16x2 command funtion */


{

LCD_Port = (cmnd & 0xF0)>>4;/* Send upper nibble */


D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;
D4=LCD_Port&0X01;
rs=0; /* Command reg. */
// rw=0; /* Write operation */
en=1;
delay(1);
en=0;
delay(2);

LCD_Port = (cmnd & 0x0F);/* Send lower nibble */


D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;

www.researchdesignlab.com RDL Technologies Pvt 28


Ltd
8051 Trainer Kit
D4=LCD_Port&0X01;
rs=0;
en=1; /* Enable pulse */
delay(1);
en=0;
delay(5);
}

void LCD_Char (char char_data) /* LCD data write function */


{
LCD_Port =(char_data & 0xF0)>>4;/* Send upper nibble */
D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;
D4=LCD_Port&0X01;
rs=1; /*Data reg.*/
// rw=0; /*Write operation*/
en=1;
delay(1);
en=0;
delay(2);

LCD_Port = (char_data & 0x0F);/* Send lower nibble */


D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;
D4=LCD_Port&0X01;
en=1; /* Enable pulse */
delay(1);
en=0;
delay(5);

void LCD_String (char *str) /* Send string to LCD function */


{
int i;
for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL */
{
LCD_Char (str[i]); /* Call LCD data write */
}
}

void LCD_String_xy (char row, char pos, char *str) /* Send string to LCD
function */
{
if (row == 0)
LCD_Command((pos & 0x0F)|0x80);
else if (row == 1)
LCD_Command((pos & 0x0F)|0xC0);
LCD_String(str); /* Call LCD string function */
}

void LCD_Init (void) /* LCD Initialize function */


{
delay(20); /* LCD Power ON Initialization time >15ms */
LCD_Command (0x02); /* 4bit mode */
LCD_Command (0x28); /* Initialization of 16X2 LCD in 4bit mode */
LCD_Command (0x0C); /* Display ON Cursor OFF */

www.researchdesignlab.com RDL Technologies Pvt 29


Ltd
8051 Trainer Kit
LCD_Command (0x06); /* Auto Increment cursor */
LCD_Command (0x01); /* clear display */
LCD_Command (0x80); /* cursor at home position */
}

void main()
{
unsigned char VALUE=0;
LCD_Init(); /* Initialization of LCD*/
LCD_String("RDL TECHOLOGIES"); /* write string on 1st line of LCD*/
LCD_Command(0xC0); /* Go to 2nd line*/

while(1) /* Infinite loop. */


{
VALUE=check();
LCD_Char(VALUE);
}
}

unsigned char check()


{
unsigned char colloc=0,rowloc=0, colloc1,rowloc1;
unsigned char keypad[4][4]={'1','5','9','C',
'2','6','0','D',
'3','7','A','E',
'4','8','B','F'};
{

do
{
KeyPort = 0X0f;
do
{
colloc1 = KeyPort;
colloc1 &= 0x0F;
}while(colloc1 != 0x0F);

delay12(20);

do
{
colloc1=KeyPort;
colloc1 &= 0x0F;
}while(colloc1==0x0F);

delay12(20);

KeyPort = 0x0f;
colloc1=KeyPort;
colloc1 &= 0x0F;
if(colloc1==0x0E)
{
colloc=0;
}
else if(colloc1==0x0D)
{
colloc=1;
}

www.researchdesignlab.com RDL Technologies Pvt 30


Ltd
8051 Trainer Kit
else if(colloc1==0x0B)
{
colloc=2;
}
else if(colloc1==0x07)
{
colloc=3;
}
KeyPort = 0xf0;
rowloc1 = KeyPort;
rowloc1 &= 0xf0;
if(rowloc1 == 0xE0)
{
rowloc=0;
}

else if(rowloc1==0xD0)
{
rowloc=1;
}
else if(rowloc1==0xB0)
{
rowloc=2;
}
else if(rowloc1==0x70)
{
rowloc=3;
}
// CMD_WRT(0XC0);
// DATA_WRT(keypad[rowloc][colloc]);

return(keypad[rowloc][colloc]);

}while(1);
}
}

void delay12(unsigned int time)


{
unsigned int i;
for(i=0;i<time;i++);
for(i=0;i<10000;i++);
}

www.researchdesignlab.com RDL Technologies Pvt 31


Ltd
8051 Trainer Kit

EXPERIMENT NO 6
RTC (Real Time Clock)

Aim:
Interfacing Real Time Clock with 8051-Microcontroller.

Description:
To display Date and Time on the LCD Display using 8051 Trainer Kit.

Hardware required:
8051 Trainer Kit ,FRC Cable and USB A to B Cable.

Connect P2 port and


SV1 port using FRC
cable

Make the I2C pins ON

Procedure:

1. Connect P2 port and SV1(LCD 16*2 Display) port using FRC cable as shown above.
2. Make the I2C pins ON as shown.
3. Connect the USB cable to the board.

www.researchdesignlab.com RDL Technologies Pvt 32


Ltd
8051 Trainer Kit

4. Open Keil uVision,write the program to display Date and Time on the LCD Display.Then
click on Build to verify the code.
5. Open Nuvoton Software to upload the hex File
6. Click the radio button ISP by Com Port, Select the Com Port
7. Select the IC (W78E052D)
8. Click on Load file, select the Hex file created and click on Open
9. Click on Upload Chip, and press the reset switch of the 8051 development board.
10. You will get a FAIL dialog Box ,Click on Ok.
11. You will get a PASS dialog Box, Click on Ok.
12. Press the Reset Button of the 8051 Microcontroller, the Date and Time will be displayed on
the LCD Display.

Program:

#include "reg51.h"
#include <intrins.h>
#include <stdio.h>

#define LCD_Port P2

sbit rs=P2^0; /* Register select pin */


sbit en=P2^1; /* Enable pin */

//*****************************************

void delay12(); //Delay for LCD


void start_bit(); //Condition for start
bit to the I2C
void stop_bit(); //Condition for stop bit
to the I2C
void slave_add(unsigned char); //To send bit by bit data to the slave
void rtc_init();
unsigned char data_rd_display(); //
void display(unsigned char); //To read the data from EEPROM and
display on LCD

//*****************************************

sbit sda=P3^3; //SDA line


sbit scl=P3^2;

void start_bit(); //Condition for start


bit to the I2C
void stop_bit(); //Condition for stop bit
to the I2C

www.researchdesignlab.com RDL Technologies Pvt 33


Ltd
8051 Trainer Kit

void slave_add(unsigned char); //To send bit by bit data to the slave
void rtc_init();

/* Function to provide delay Approx 1ms with 11.0592 Mhz crystal*/


void delay12()
{
int i,j;
for(i=0;i<1;i++)
for(j=0;j<112;j++);
}

void delay(unsigned int count)


{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<112;j++);
}
void LCD_Command (char cmnd) /* LCD16x2 command funtion */
{
LCD_Port =(LCD_Port & 0x0F) | (cmnd & 0xF0);/* Send upper nibble */
rs=0; /* Command reg. */
en=1;
delay(1);
en=0;
delay(2);

LCD_Port = (LCD_Port & 0x0F) | (cmnd << 4);/* Send lower nibble */
en=1; /* Enable pulse */
delay(1);
en=0;
delay(5);
}

void LCD_Char (char char_data) /* LCD data write function */


{
LCD_Port =(LCD_Port & 0x0F) | (char_data & 0xF0);/* Send upper nibble
*/
rs=1; /*Data reg.*/
en=1;
delay(1);
en=0;
delay(2);

LCD_Port = (LCD_Port & 0x0F) | (char_data << 4);/* Send lower nibble
*/
en=1; /* Enable pulse */
delay(1);
en=0;
delay(5);

void LCD_String (char *str) /* Send string to LCD function */


{
int i;
for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL */
{
LCD_Char (str[i]); /* Call LCD data write */

www.researchdesignlab.com RDL Technologies Pvt 34


Ltd
8051 Trainer Kit
}
}

void LCD_String_xy (char row, char pos, char *str) /* Send string to LCD
function */
{
if (row == 0)
LCD_Command((pos & 0x0F)|0x80);
else if (row == 1)
LCD_Command((pos & 0x0F)|0xC0);
LCD_String(str); /* Call LCD string function */
}

void LCD_Init (void) /* LCD Initialize function */


{
delay(20); /* LCD Power ON Initialization time >15ms */
LCD_Command (0x02); /* 4bit mode */
LCD_Command (0x28); /* Initialization of 16X2 LCD in 4bit mode */
LCD_Command (0x0C); /* Display ON Cursor OFF */
LCD_Command (0x06); /* Auto Increment cursor */
LCD_Command (0x01); /* clear display */
LCD_Command (0x80); /* cursor at home position */
}

void main()
{
unsigned char lcd_cmd[]={0x38,0x0f,0x01,0x06,0X80}; //Commands for
the LCD
unsigned char i,ch;
unsigned char mes_1[]="TIME ";
unsigned char mes_2[]="DATE ";

//*****************************************************

LCD_Init();

//*****************************************************

rtc_init();

//*****************************************************
delay12();

while(1)
{
LCD_Command(0x80);

i=0;
while(mes_1[i])
{
LCD_Char(mes_1[i]);
i++;
}
start_bit();
delay12();
slave_add(0xd0);
delay12();

www.researchdesignlab.com RDL Technologies Pvt 35


Ltd
8051 Trainer Kit
slave_add(0x02);
delay12();
start_bit();
delay12();
slave_add(0xd1);
delay12();
ch=data_rd_display();
delay12();
stop_bit();
delay12();
display(ch);
delay12();
delay12();
delay12();

LCD_Char(':');

start_bit();
delay12();
slave_add(0xd0);
delay12();
slave_add(0x01);
delay12();
start_bit();
delay12();
slave_add(0xd1);
delay12();
ch=data_rd_display();
delay12();
stop_bit();
delay12();
display(ch);
delay12();
delay12();
delay12();

LCD_Char(':');

start_bit();
slave_add(0xd0);
slave_add(0x00);
start_bit();
slave_add(0xd1);
ch=data_rd_display();
stop_bit();
display(ch);
delay12();
delay12();

//***********************************

LCD_Command(0xc0);

i=0;
while(mes_2[i])
{
LCD_Char(mes_2[i]);
i++;
}

www.researchdesignlab.com RDL Technologies Pvt 36


Ltd
8051 Trainer Kit
start_bit();
slave_add(0xd0);
slave_add(0x04);
start_bit();
slave_add(0xd1);
ch=data_rd_display();
stop_bit();
display(ch);
delay12();
delay12();

LCD_Char('-');

start_bit();
slave_add(0xd0);
slave_add(0x05);
start_bit();
slave_add(0xd1);
ch=data_rd_display();
stop_bit();
display(ch);
delay12();
delay12();

LCD_Char('-');

start_bit();
slave_add(0xd0);
slave_add(0x06);
start_bit();
slave_add(0xd1);
ch=data_rd_display();
stop_bit();
display(ch);
delay12();
delay12();

}
}

//***********************************************
void start_bit()
{
sda=1;
scl=1; //Start bit condition
_nop_();
_nop_();
sda=0;
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
_nop_();
_nop_();
}

www.researchdesignlab.com RDL Technologies Pvt 37


Ltd
8051 Trainer Kit

//*****************************************************

void stop_bit()
{
sda=0;
scl=1;
_nop_();
_nop_();
sda=1;
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
_nop_();
_nop_();
_nop_();
_nop_();
scl=1;
}

//******************************************************

void slave_add(unsigned char add)


{
unsigned char t,i;
t=add;

for(i=0;i<8;i++)
{
t=(t&0x80);
if(t!=0)
sda=1;
else
sda=0;
scl=1;
_nop_();
_nop_();
_nop_();
scl=0;
t=add<<1;
add=t;
}
sda=1;
scl=1;
_nop_();
_nop_();
_nop_();
scl=0;
}

//*******************************************************

unsigned char data_rd_display()


{
unsigned char i,x=0;
unsigned char y;
y=0;

www.researchdesignlab.com RDL Technologies Pvt 38


Ltd
8051 Trainer Kit
sda=1;
for(i=0;i<8;i++)
{
scl=0;
_nop_();
_nop_();
_nop_();
scl=1;
if(sda==1)
x=x|0x01;
y=x;
x=x<<1;
scl=0;
}

sda=1;
scl=1;
_nop_();
_nop_();
_nop_();
scl=0;
return(y);
}

//*******************************************************

void rtc_init()
{
unsigned char
a[]={0x00,0x00,0x01,0x50,0x02,0x06,0x03,0x02,0x04,0x11,0x05,0x12,0x06,0x12};
unsigned char x=0;

start_bit();
slave_add(0xd0);
slave_add(a[0]);
slave_add(a[1]);
stop_bit();
start_bit();
slave_add(0xd0);
slave_add(a[2]);
slave_add(a[3]);
stop_bit();

start_bit();
slave_add(0xd0);
slave_add(a[4]);
slave_add(a[5]);
stop_bit();

start_bit();
slave_add(0xd0);
slave_add(a[8]);
slave_add(a[9]);
stop_bit();

start_bit();
slave_add(0xd0);
slave_add(a[10]);

www.researchdesignlab.com RDL Technologies Pvt 39


Ltd
8051 Trainer Kit
slave_add(a[11]);
stop_bit();

start_bit();
slave_add(0xd0);
slave_add(a[12]);
slave_add(a[13]);
stop_bit();

void display(unsigned char a1)


{
unsigned char b1;
b1=(a1 & 0x0f0);
b1=(b1>>4)+0x30;
LCD_Char(b1);
b1=(a1 & 0x0f);
b1=b1+0x30;
LCD_Char(b1);
}

www.researchdesignlab.com RDL Technologies Pvt 40


Ltd
8051 Trainer Kit

EXPERIMENT NO 7
UART
Aim:
Interfacing UART with 8051-Microcontroller.

Description:
Transmit/Receive Data using UART and display the data‟s on the terminal Software.

Hardware required:
8051 Trainer Kit ,USB to RS232 Converter,USB A to B Cable,Power Adapter 12V 2A.

Make 232TX and 232RX


Power RS232 pins of DIP2 HIGH
Supply Converter

Procedure:

1. Connect the USB Cable to the Board.


2. Open Keil uVision,write the program to display Transmit/Receive Data using
UART.Then click on Build to verify the code.
3. Open Nuvoton Software to upload the hex File
4. Click the radio button ISP by Com Port, Select the Com Port

www.researchdesignlab.com RDL Technologies Pvt 41


Ltd
8051 Trainer Kit

5. Select the IC (W78E052D)


6. Click on Load file, select the Hex file created and click on Open
7. Click on Upload Chip, and press the reset switch of the 8051 Microcontroller.
8. You will get a FAIL dialog Box ,Click on Ok.
9. You will get a PASS dialog Box, Click on Ok.
10. Remove the USB cable from the Board.
11. Connect the USB to RS232 converter to the Board and other side of the connector to the
Computer as shown above.
12. Make 232TX and 232RX pins of DIP2 HIGH
13. Open any of the Terminal Software to check the output
(Ex: Tera Term Software ,To Download this Software, CLICK HERE )
14. Open the Tera Term Software,Click on the radio button Serial and select the Port and
then click on OK.

15. Press the Reset Button of the 8051 Microcontroller, You can see the data on the terminal
software
16. Send the data from your keyboard, everything you type should be displayed in the
terminal window.

www.researchdesignlab.com RDL Technologies Pvt 42


Ltd
8051 Trainer Kit

Program:

/*
* Project name:
8051 Development Board
* Copyright
(c) Researchdesignlab.com
* Description:

* Test configuration:
MCU: AT89S52
Dev.Board: 8051
Oscillator: 11.0592 MHz
Software: Keil uVision3

*/
#include<reg51.h>

unsigned char SCI_ReceiveByte( void );


void TRANSMIT(unsigned char *);
void transmit_byte(unsigned char );
void DELAY();

void main()
{
unsigned char byte;
TMOD=0X20;
TH1=0XFD;
SCON=0X50;
TR1=1;
TRANSMIT("RESEARCH DESIGN LAB");
DELAY();
while(1)
{
byte=SCI_ReceiveByte();
transmit_byte(byte);
}

}
void DELAY()
{
unsigned int X=6000000;
while(X--);

void transmit_byte(unsigned char byte)


{
SBUF=byte;
while(!TI);
TI=0;
}

void TRANSMIT(unsigned char *string)


{
while(*string)

www.researchdesignlab.com RDL Technologies Pvt 43


Ltd
8051 Trainer Kit
transmit_byte(*string++);
}
unsigned char SCI_ReceiveByte( void )
{
unsigned char byte;
while(RI!=1);
byte = SBUF;
RI=0;
return byte;
}

www.researchdesignlab.com RDL Technologies Pvt 44


Ltd
8051 Trainer Kit

EXPERIMENT NO 7
EEPROM
Aim:
Interfacing the EEPROM IC with 8051-Microcontroller.

Description:
To display the erased and stored data.

Hardware required:
8051 Trainer Kit and USB A to B Cable.

Make the I2C pins ON

1. Connect the USB Cable to the Board.


2. Open Keil uVision,write the program to display the stored data.Then click on Build to
verify the code.
3. Open Nuvoton Software to upload the hex File
4. Click the radio button ISP by Com Port, Select the Com Port

www.researchdesignlab.com RDL Technologies Pvt 45


Ltd
8051 Trainer Kit

5. Select the IC (W78E052D)


6. Click on Load file, select the Hex file created and click on Open
7. Click on Upload Chip, and press the reset switch of the 8051 Microcontroller.
8. You will get a FAIL dialog Box ,Click on Ok.
9. You will get a PASS dialog Box, Click on Ok.
10. Open any of the Terminal Software to check the output
(Ex: Tera Term Software ,To Download this Software, CLICK HERE )
11. Open the Tera Term Software,Click on the radio button Serial and select the Port and
then click on OK.

12. Press the Reset Button of the 8051 Microcontroller, You can see the data on the terminal
window.

www.researchdesignlab.com RDL Technologies Pvt 46


Ltd
8051 Trainer Kit

Program:
#include"reg52.h"
#include "intrins.h"
#include"stdio.h"

sbit sda=P3^3; //SDA line


sbit scl=P3^2;

#define DEV_WR 0xa0


#define DEV_RD 0xa1

char data_write[]="123456";

void delay();

void TRANSMIT(unsigned char *);


void transmit_byte(unsigned char);

void startbit();
unsigned char data_read();
void slaveaddr(unsigned char m) ;
void stopbit();
void INIT_SERIAL();
int i=0;
//**********************************************

//*********************************************

void main()
{
unsigned char cmp=0,k;
INIT_SERIAL();

TRANSMIT("\n\r EERPOM 8051 \n\r");

for(i=0;i<6;i++)
{
startbit();
slaveaddr(DEV_WR);
slaveaddr(0x10+i);
slaveaddr(data_write[i]);
stopbit();
delay();
delay();
}

for( i=0;i<6;i++)
{
startbit();
slaveaddr(DEV_WR);
slaveaddr(0x10+i);

www.researchdesignlab.com RDL Technologies Pvt 47


Ltd
8051 Trainer Kit
startbit();
slaveaddr(DEV_RD);
k = data_read();
delay();
stopbit();
transmit_byte(k);
}
while(1);
}

void delay()
{
{
long int x=300;
while(x--);
}
}
void INIT_SERIAL()
{
TMOD=0X20;
TH1=0XFD;
SCON=0X50;
TR1=1;
}
//***********************************************************//

void transmit_byte(unsigned char byte)


{
SBUF=byte;
while(!TI);
TI=0;
}

void TRANSMIT(unsigned char *string)


{
while(*string)
transmit_byte(*string++);
}

void startbit()

{
sda=1;
scl=1;
//delay();
_nop_();
_nop_();
sda=0;
//delay();
//delay();
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;

www.researchdesignlab.com RDL Technologies Pvt 48


Ltd
8051 Trainer Kit
_nop_();
_nop_();

//**********************************************************

void stopbit()
{

sda=0;
scl=1;
//delay();
_nop_();
_nop_();
sda=1;
//delay();
//delay();
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
//delay();
_nop_();
_nop_();
_nop_();
_nop_();
scl=1;

//*********************************************************

void slaveaddr(unsigned char m)


{
unsigned char i;
unsigned char b;
b=m;
//scl=1;
for(i=0;i<8;i++)
{
b= (b & 0x80);
if(b!=0)
sda=1;
else
sda=0;

scl=1;
//delay();
_nop_();
_nop_();
_nop_();
scl=0;
b=m<<1;
m=b;
}
sda=1;

www.researchdesignlab.com RDL Technologies Pvt 49


Ltd
8051 Trainer Kit
scl=1;
//lay();
_nop_();
_nop_();
_nop_();
scl=0;
//delay();

//************************************************************

unsigned char data_read()


{
unsigned char i,a1,b1=0;
sda=1;
for(i=0;i<8;i++)
{
scl=0;
//delay();
_nop_();
_nop_();
_nop_();
scl=1;
//delay(); _nop_();

if(sda==1)
b1=(b1 | 0x01);
a1=b1;
b1=b1<<1;
scl=0;
}
sda=1;
scl=1;
//delay();
_nop_();
_nop_();
_nop_();
scl=0;

return(a1)
}

www.researchdesignlab.com RDL Technologies Pvt 50


Ltd

You might also like