Sei sulla pagina 1di 38

Ex. No.

1
07-09-2015

1. INTRODUCTION TO KEIL VISION IDE

Keil Vision IDE is a window-based software development platform for 8051 and ARM
microcontrollers that combines a robust and modern editor with a project manager and make facility
tool. It integrates all the tools needed to develop embedded applications including a C/C++ compiler,
macro assembler, linker/locator, and a HEX file generator.
Vision GUI
The Vision GUI provides menus for selecting commands and toolbars with command buttons. The
Status Bar, at the bottom of the window, displays information and messages about the current
Vision command. Windows can be relocated and docked to another physical screen. The window
layout is saved for each project automatically and restored the next time the project is used. You can
restore the default layout using the menu Window Reset View to Defaults.
Vision has two operating modes, the Build Mode for creating applications and the Debug Mode for
analyzing applications, which offers additional Windows and Dialogs.
Debug Windows and Dialogs
Vision provides many debugging windows and dialogs. Some of them are

Breakpoints- Define stop conditions for program execution.


Code Coverage- Examine statistics about code execution, including branch testing.
Command Window- Enter and view executed commands.
Disassembly Window- Test programs at the level of assembly instructions.
Logic Analyzer - Investigate value changes of peripherals, registers, and variables on a time
graph.
Memory Map- Evaluate memory areas and their access rights.
Memory Window - Analyze and modify memory content.
Performance Analyzer - Evaluate time and call statistics on module or function level.
Registers Window- view and modify register content.
Serial Window is a communication interface between the application and the PC.
Status Bar - View debugging status information.
Symbols Window- Find debug symbol information used in program.
System Viewer Find peripheral register information and change property values at runtime.
Toolbox Use and define configurable buttons for executing debugging commands
interactively.

15EE51 Microcontrollers Laboratory

Page 1

Fig 1.1: KeilIDE showing the various Windows available

Introduction to Keil Vision IDE

15EE51 Microcontrollers Laboratory

Page 2

Introduction to Keil Vision IDE

Working with Keil Vision IDE


Getting started
1.OpenKeil Vision ,Click Project New Vision Project.

Fig.1.2:Creation of new project

2.Type a name and save the project file

Fig.1.3

15EE51 Microcontrollers Laboratory

Page 3

Introduction to Keil Vision IDE


3.Select Device for target as AT89S51as shown in Fig. 1.4

Fig.1.4

4.Right click Source Group 1 and select Add new Item to Source Group 1

Fig.1.5

15EE51 Microcontrollers Laboratory

Page 4

Introduction to Keil Vision IDE


Choose file type as ASM ,name the file and click Add

Fig. 1.6

5.Type the code ,press F7/Bulid icon

and Ctrl+F5 / Debug icon

Fig.1. 7

In Debug mode various simulations can be done with variety of tools like Logic Analyzer, Performance
Analyzer,etc.,Register and Memory status can be viewed during execution.

15EE51 Microcontrollers Laboratory

Page 5

Introduction to Keil Vision IDE


Logic Analyzer
To perform Logic Analysis,Click View Analysis WindowLogic Analyzer as shown in Fig 1.8

Fig. 1.8

The Logic Analyzer Window opens up.Click Setup and configure as shown below to observe waveform at P1.0

Fig. 9: Logic Analyzer Setup

15EE51 Microcontrollers Laboratory

Page 6

Introduction to Keil Vision IDE


Output waveform will be displayed as

Fig. 1.10: Logic Analyzer

Performance Analyzer
To perform analysis of various parts of the program,Click View Analysis Window Performance
Analyzer
Click Setup and configure as follows

Fig. 1.11: Setup Performance Analyzer

Output of performance is shown. Average execution time of a function and various other parameters
are shown to pave way for optimization

Fig. 1.12: Performance Analyzer

15EE51 Microcontrollers Laboratory

Page 7

Introduction to Keil Vision IDE

Register Window
To access Register Window ,Click View
Register Window .
Register window displays the contents of
Accumulator A ,register B,registers from R0
to R7,Program Status Word(PSW),Data
Pointer(DPTR),Stack Pointer(SP),Program
counter(PC),etc.,This makes
program
debugging easier

Fig. 1.13 : Register Window

Memory Window

To access Memory Window,Click View Memory Window Memory 1


We can view both code memory as well as data memory.
Code memory contains the opcodes.Data memory contains the contents of RAM.
To access code memory or data memory,use C: or D: followed by address.

Eg: C:0x00 D:0x00

Fig. 1.14 : Memory Window showing Code Memory

15EE51 Microcontrollers Laboratory

Fig. 1.15 : Memory Window showing Data Memory

Page 8

Introduction to Keil Vision IDE


Disassembly Window
Click View Disassembly Window.
Disassembly Window shows the opcodes for each instruction.

Fig. 1.16: Disassembly Window

Serial Window
Click View Serial Windows UART #1
This is useful for simulating Serial communication before downloading it to microcontroller.

Fig. 1.17 : Serial Window

Breakpoints
Program can be made to stop at a particular instruction so as to know the status of memory and
registers at that point.
To insert a breakpoint place on a particular line or instruction and press F9.Pressing F9 again will
remove the breakpoint.
Multiple breakpoints can be inserted and program will stop at breakpoints when run.

15EE51 Microcontrollers Laboratory

Page 9

Introduction to Keil Vision IDE

Fig. 1.18 Program having breakpoints at Line 4,11 and 13

Generating HEX file


To download the compiled program into the 8051 ,HEX file needs to be generated.To generate HEX
file ,click Flash Configure Flash Tools

Fig. 1.19

A dialog box opens up.Click the Output tab and check in Create HEX fileoption.ClickOK.

Fig.1.20

15EE51 Microcontrollers Laboratory

Page 10

Introduction to Keil Vision IDE


Press F7/Bulid icon

. Generated HEX file can be found in the Objects folder

Fig. 1.21 : HEX file in Objects folder

Fig.1. 22:Contents of the HEX file

Writing a sample program for blinking 8 LEDs connected to PORT 1 of 8051 periodically in Keil Vision IDE.

Additional software required: DLL files for LED simulation ( LED_CONTROL.DLL and LED_DATABASE.CDB )

ALGORITHM:
1.
2.
3.
4.
5.
6.

Start
Load 0xFF to Port 1.
Call Delay routine.
Load 0x00 to Port 0.
Call Delay routine.
Goto Start

15EE51 Microcontrollers Laboratory

Page 11

Introduction to Keil Vision IDE

PROGRAM:
ORG 0x0000
START:MOV P1,#0xFF
ACALL DELAY
MOV P1,#0x00
ACALL DELAY
AJMP START
DELAY:MOV R0,#0xFF
L2:MOV R1,#0xFF
L1:DJNZ R1,L1
DJNZ R0,L2
RET
SIMULATION:
Create a new project , add a new assembly file, type the above code and save it.
To simulate the blink LED program, we have to download DLL for LED control from Keil website.

Copy the LED_CONTROL.DLL and LED_DATABASE.CDB file to Keil\C51\BIN directory.


Add this line to [C51] section of Tools.ini in Keil directory.
AGSI2=LED_CONTROL.DLL ("LED simulation")
Restart Keil Vision IDE.
With the project open, press Ctrl+F5 to Enter debug mode.
Click Peripherals LED. The LED Window opens up.

Right Click and select add LED.New LED window opens up as shown in Fig. 1.23

Fig. 1.23

15EE51 Microcontrollers Laboratory

Page 12

Introduction to Keil Vision IDE

Setup the pins for LED as shown in Fig 1.24

Fig. 1.24

Similarly do the same for P1.1 ,P1.2,.P1.7

Fig. 1.25

Press F5 to run the program.

RESULT:
Thus the development, debugging features of Keil Vision IDE were studied and a sample program for blinking
LED was executed.

15EE51 Microcontrollers Laboratory

Page 13

Ex No.2

ASSEMBLY LANGUAGE PROGRAMMING IN 8051

10-10-2015

A.Timers /Counters
AIM:
i.
ii.
iii.

To operate the timer0 in mode 0 and generate square wave of 66 % duty cycle.
To operate the timer1 in mode 2 and generate a delay of 100 s.
Count clock pulses on P3.4 (T0 pin) and put it on Port 2

PROGRAM:
i.

For generating square wave of 66 % duty cyle using timer 0 in mode 0

L1:
SETB P1.5
ACALL DELAY1
CLR P1.5
ACALL DELAY2
SJMP L1
DELAY1:

L2:

MOV TH0,#0x00
MOV TL0,#0x00
SETB TR0
JNB TF0,L2
CLR TR0
CLR TF0
RET

;8 bit TH0 value


;5 bit TL0 value
;Start timer
;Poll TF0 flag

MOV TH0,#0x80
MOV TL0,#0x00
SETB TR0
JNB TF0,L3
CLR TR0
CLR TF0
RET

;8 bit TH0 value


;5 bit TL0 value
;Start timer
;Poll TF0 flag

DELAY2:

L3:

OUTPUT:

Figure 2.2 Waveform at P1.5

15EE51 Microcontrollers Laboratory

Page 14

ASSEMBLY LANGUAGE PROGRAMMING IN 8051

ii. To operate the timer1 in mode 2 and generate a delay of 100 s.


PROGRAM:
MOV TMOD,#0x20
MOV TH1,#-92

;Timer 1 in 8 bit autoreload mode (mode 2)


;100 s /1.085 s = 92 , 11.0592MHz ==> 1.085 s

LOOP:SETB P1.2
ACALL DELAY
CLR P1.2
ACALL DELAY
SJMP LOOP
DELAY:SETB TR1
L1:JNB TF1,L1
CLR TF1
CLR TR1
RET

;Start timer 1
; Poll TF1 flag

OUTPUT:

Figure 2.3 Timer 1 registers

15EE51 Microcontrollers Laboratory

Page 15

ASSEMBLY LANGUAGE PROGRAMMING IN 8051

Figure 2.4 Waveform at P1.2

iii.

Count clock pulses on P3.5 (T0 pin) and put it on Port 2

PROGRAM:
MOV TMOD,#0x50 ; Counter 1 ,8 bit mode
MOV TH1,#0x00 ; Autoreload value
SETB P3.5
AGAIN:SETB TR1
BACK:MOV A,TL1
MOV P2,A
JNB TF1,BACK
CLR TR1
CLR TF1
SJMP AGAIN
OUTPUT:

Figure 2.5

15EE51 Microcontrollers Laboratory

Page 16

ASSEMBLY LANGUAGE PROGRAMMING IN 8051


B.Serial Communication

AIM:

To turn on and turn off LEDs connected at PORT 1 by using serial communication. If y is sent LEDs are turned on
and if n is sent LEDs are turned off.Acknowledgment messages are also end.
PROGRAM:
ORG 0x00
MOV TMOD,#0x20
MOV SCON,#0x50
MOV TH1,#-3
SETB TR1

; Timer 1, 8 bit autoreload


; 8 bit,1 stop bit,Receive enabled
; 9600 baud rate for 11.0592 MHz

WAIT:JNB RI,WAIT
MOV R0,SBUF
CLR RI

;Poll RI flag bit

CJNE R0,#'y',C1
MOV P1,#0x00
SJMP DISPLAY_ON

;If y turn on LED

C1:CJNE R0,#'n',C2
MOV P1,#0xFF
SJMP DISPLAY_OFF

;If n turn off LED

C2:SJMP WAIT

STRING1:DB "LEDs ON",10,0


STRING2:DB "LEDs OFF",10,0

DISPLAY_ON:MOV DPTR,#STRING1
SJMP SEND
DISPLAY_OFF:MOV DPTR,#STRING2
SJMP SEND
SEND:CLR A
MOVC A,@A+DPTR
JZ WAIT
MOV SBUF,A
WT:JNB TI,WT
CLR TI
INC DPTR
SJMP SEND

15EE51 Microcontrollers Laboratory

;Place character to be transmitted in SBUF


;Poll TI flag bit

Page 17

ASSEMBLY LANGUAGE PROGRAMMING IN 8051


OUTPUT:

Figure 2.6 (a) Serial Communication

Figure 2.6 (b) Serial Communication

15EE51 Microcontrollers Laboratory

Page 18

ASSEMBLY LANGUAGE PROGRAMMING IN 8051


C.Interrupts
AIM:
To write a program for demonstrating external interrupt (edge triggered at P3.2) , timer overflow interrupt(Timer 0)
and serial communication interrupt.
PROGRAM:
ORG 0x0000
LJMP MAIN

;RESET INTERRUPT

ORG 0x0003
CPL P1.0
RETI

;EXTERNAL INTERRUPT 0

ORG 0x000B
CPL P1.1
RETI

;TIMER 0 OVERFLOW INTERRUPT

ORG 0x0023
;SERIAL COMMUNICATION INTERRUPT
LJMP SERIAL_ISR
ORG 0x0030
MAIN:
MOV SCON,#0x50
MOV IE,#0x93
MOV TMOD,#0x22
MOV TH0,#0x00
MOV TH1,#-3
SETB TR0
SETB TR1
SETB IT0
HERE:SJMP HERE

;ENABLE EXT ,TIMER 0 , SERIAL INTERRUPT

;EDGE TRIGERRED EXT. INTERRUPT

SERIAL_ISR:
CLR RI
MOV R0,SBUF
CJNE R0,#'y',C1
MOV P2,#0x00
C1:CJNE R0,#'n',C2
MOV P2,#0xFF
C2:RETI

15EE51 Microcontrollers Laboratory

Page 19

ASSEMBLY LANGUAGE PROGRAMMING IN 8051


External interrupt toggles the LED connected with P1.0 , timer overflow interrupt will generate square wave P1.1
and serial interrupt for turning ON and OFF LEDs at Port 2
OUTPUT:

Figure 2.7(a) Windows showing Interrupts,Serial Communication

Figure 2.6(b) Windows showing Interrupts,Serial Communication

15EE51 Microcontrollers Laboratory

Page 20

ASSEMBLY LANGUAGE PROGRAMMING IN 8051

RESULT:
Thus programs for Timers/Counters, Serial Communication and Interrupts were written in assembly and
simulated using Keil Vision IDE.
15EE51 Microcontrollers Laboratory

Page 21

Ex No.3

C LANGUAGE PROGRAMMING IN 8051

12-11-2015

A. Timers /Counters
AIM:
i.
ii.
iii.

To operate the timer0 in mode 0 and generate square wave of 66 % duty cycle.
To operate the timer1 in mode 2 and generate a delay of 100 s.
Count clock pulses on P3.4 (T0 pin) and put it on Port 2

PROGRAM:
i.

For generating square wave of 66 % duty cycle using timer 0 in mode 0

C CODE:
#include<reg51.h>
void delay1();
void delay2();
void main()
{
while(1)
{
P1|=(1<<5);
delay1();
P1&=~(1<<5);
delay2();
}
}
void delay1()
{
TH0=0x00;
TL0=0x00;
TR0=1;
while(!TF0);
TR0=0;
TF0=0;
}
void delay2()
{
TH0=0x80;
TL0=0x00;
TR0=1;
while(!TF0);
TR0=0;
TF0=0;
}

//Set bit P1.5


//Clear bit P1.5

//Start Timer 0
//Poll TF0 flag

//Start Timer 0
//Poll TF0 flag

15EE51 Microcontrollers Laboratory

Page 23

C PROGRAMMING IN 8051
OUTPUT:

Figure 3.1 Waveform at P1.5

ii. To operate the timer1 in mode 2 and generate a delay of 100 s.

C CODE:
#include<reg51.h>
void delay();
void main()
{
TH1=-92;
TMOD=0x20;
while(1)
{
P1|=(1<<2);
delay();
P1&=~(1<<2);
delay();
}
}

// 100 s/1.085 s = 92 for 11.592 MHz

//Set bit P1.2


//Clear bit P1.3

void delay()
{
TR1=1;
while(!TF1);
TF1=0;
TR1=0;

//Poll TF1 flag

}
15EE51 Microcontrollers Laboratory

Page 24

C PROGRAMMING IN 8051
OUTPUT:

Figure 3.2 (a) Timer registers

Figure 3.2 (b) Timer registers

iii.

Count clock pulses on P3.5 (T0 pin) and put it on Port 2

C CODE:
#include<reg51.h>
void main()
{
TMOD=0x50;
TH1=0x00;
T0=1;
while(1)
{
TR1=1;
while(!TF1)
P2=TL1;
TR1=0;
TF1=0;
}
}

//Counter 1 ,Mode 1

15EE51 Microcontrollers Laboratory

Page 25

OUTPUT:

C PROGRAMMING IN 8051

Figure 3.3 Counter output

15EE51 Microcontrollers Laboratory

Page 26

C PROGRAMMING IN 8051
B. Serial Communication

AIM:

To turn on and turn off LEDs connected at PORT 1 by using serial communication. If y is sent LEDs are turned on
and if n is sent LEDs are turned off.Acknowledgment messages LEDs ON and LEDs OFF are also sent.
C CODE:
#include<reg51.h>
void Serial_Init();
void Serial_Str_Transmit(char *);
char Serial_Char_Receive();
void main()
{
char ch;
Serial_Init();
while(1)
{
ch=Serial_Char_Receive();
switch(ch)
{
case 'y':
P1=0x00;
Serial_Str_Transmit("LEDs ON\n");
break;
case 'n':
P1=0xFF;
Serial_Str_Transmit("LEDs OFF\n");
break;
}
}
}

void Serial_Init()
{
TMOD=0x20;
SCON=0x50;
TH1=-3;
TR1=1;
}

// 9600 baud rate for 11.0592 MHz

char Serial_Char_Receive()
{
while(!RI);
//Poll RI flag
RI=0;
//Clear RI flag
return(SBUF);
}

15EE51 Microcontrollers Laboratory

Page 27

C PROGRAMMING IN 8051

void Serial_Str_Transmit(char *p)


{
while(*p!='\0')
{
SBUF=*p;
while(!TI);
//Poll TI flag
TI=0;
p++;
}
}
OUTPUT:

Figure 3.4 Serial Communication

15EE51 Microcontrollers Laboratory

Page 28

C PROGRAMMING IN 8051
C. Interrupts

AIM:
To write a program for demonstrating external interrupt (edge triggered at P3.2) , timer overflow interrupt(Timer 0)
and serial communication interrupt.
C CODE:
#include<reg51.h>
void Serial_Init();
void Interrupt_Init();
void Timer0_Init();
void main()
{
Serial_Init();
Interrupt_Init();
Timer0_Init();
while(1);
}

// Wait forever

void Serial_Init()
{
TMOD=0x20;
SCON=0x50;
TH1=-3;
TR1=1;
}
void Interrupt_Init()
{
IE=0x93;
IT0=1;
}
void Timer0_Init()
{
TMOD|=0x02;
TR0=1;
}
void ext_int0(void) interrupt 0
{
P1^=(1<<0);
}
void timer_int0(void) interrupt 1
{
P1^=(1<<1);
}

15EE51 Microcontrollers Laboratory

//Ext.Interrupt 0

//Timer interrupt 0

Page 29

C PROGRAMMING IN 8051

void serial_int(void) interrupt 4


{
RI=0;
if(SBUF=='y')
P2=0x00;
if(SBUF=='n')
P2=0xFF;
}

//Serial Interrupt

External interrupt toggles the LED connected with P1.0 , timer overflow interrupt will generate square wave P1.1
and serial interrupt for turning ON and OFF LEDs at Port 2
OUTPUT:

Figure 3.5 External ,Timer and Serial Communication interrupt

RESULT:
Thus assembly and C programs for Timers/Counters, Serial Communication and Interrupts in 8051
microcontroller were written and simulated using Keil Vision IDE.

15EE51 Microcontrollers Laboratory

Page 30

Ex No : 4

4. INTERFACING HARDWARE WITH 8051

16-11-15
AIM:
i.

To turn on only RED LED (P1.4) when key 1(P2.0) is pressed and turn only GREEN LED(P1.5)
when key 2(P2.1) is pressed
ii. To produce a single beep sound when key 1 is pressed and a double beep sound when key 2 is
pressed.
iii. To interface HD44780 compatible 16 2 LCD display in 8 bit mode.
iv. To interface a 4 4 Matrix keypad.
PROGRAM:
i.

To write a program to turn on only RED LED (P1.4) when key 1(P2.0) is pressed and turn only
GREEN LED(P1.5) when key 2(P2.1) is pressed.

#include<reg51.h>
sbit
sbit
sbit
sbit

RED =P1^4;
GREEN =P1^5;
KEY1=P2^0;
KEY2=P2^1;

void main()
{
while(1)
{
if(!KEY1)
{
RED=0;
GREEN=1;
}
if(!KEY2)
{
RED=1;
GREEN=0;
}
}

INTERFACING HARDWARE WITH 8051


OUTPUT:

Fig 4.1 RED LED glowing when Key1 is pressed

Fig 4.2 GREEN LED glowing when Key2 is pressed

ii. To produce a beep sound when key 1 is pressed and a beep sound twice when key 2 is
pressed.
#include <reg51.h>
void beep();
void delay_ms(int d);
sbit BUZZER = P3^4;
void main()
{
while(1)
{
if(!KEY1)
{
beep();
}
if(!KEY2)
{
beep();
delay_ms(200);
beep();
}
}

15EE51 Microcontrollers Laboratory

Page 31

INTERFACING HARDWARE WITH 8051

void beep()
{
unsigned char i = 25;
while (i--)
{
BUZZER = !BUZZER;
delay(5);
}
}
void delay_ms(int d)
{
int i;
TCON=0x01;
for(i=0;i<d;i++)
{
TH0=0x01;
TL0=0x40;
TR0=1;
while(!TF0);
TR0=0;
}
}
iii. To interface HD44780 compatible 16 2 LCD display in 8 bit mode.
#include<reg51.h>
sbit RS =P2^4;
sbit RW=P2^5;
sbit EN=P2^6;
#define CLEAR 0x01
void
void
void
void
void
void
void

LCD_Init();
LCD_SetCursor(char,char);
LCD_Cmd(char);
LCD_Data(char);
LCD_PrintChar(char);
LCD_PrintStr(char*);
delay_ms(int);

15EE51 Microcontrollers Laboratory

Page 32

INTERFACING HARDWARE WITH 8051


void main()
{
RW=0;
LCD_Init();
LCD_PrintStr("Jabez Winston");
delay_ms(1000);
LCD_SetCursor(1,0);
LCD_PrintChar("Jagdeesh");
while(1);
}

void LCD_Init()
{
delay_ms(100);
LCD_Cmd(0x38);
delay_ms(10);
LCD_Cmd(0x0C);
LCD_Cmd(0x06);
LCD_Cmd(CLEAR);
}
void LCD_SetCursor(char r,char c)
{
switch(r)
{
case 0: LCD_Cmd(0x80+c);
break;
case 1: LCD_Cmd(0xC0+c);
break;
}
}
void LCD_Cmd(char cmd)
{
EN=0;
RS=0;
P1=cmd;
EN=1;
delay_ms(10);
EN=0;
}

15EE51 Microcontrollers Laboratory

Page 33

INTERFACING HARDWARE WITH 8051


void LCD_Data(char ch)
{
EN=0;
RS=1;
P1=ch;
EN=1;
delay_ms(10);
EN=0;
}
void LCD_PrintChar(char ch)
{
LCD_Cmd(ch);
}
void LCD_PrintStr(char *s)
{
while(*s)
LCD_PrintChar(*s++);
}
void delay_ms(int d)
{
int i;
TCON=0x01;
for(i=0;i<d;i++)
{
TH0=0x01;
TL0=0x40;
TR0=1;
while(!TF0);
TR0=0;
}
}

15EE51 Microcontrollers Laboratory

Page 34

INTERFACING HARDWARE WITH 8051


OUTPUT:

Figure 4.3 Two strings printed on LCD

iv. To interface a 4 4 Matrix keypad.


#include<reg51.h>
unsigned char get_key();
void lcd_init();
void lcd_printc(char);
void lcd_prints(char);
void lcd_clear();
void lcd_write_cmd(unsigned char );
void lcd_write_data(unsigned char );
void delay(int);
sbit LCD_RS = P2^4;
sbit LCD_WR = P2^5;
sbit LCD_EN = P2^6;
int x;
char a[4][4]={"123E",
"456U",
"789D",
"*0#e"};

15EE51 Microcontrollers Laboratory

Page 35

INTERFACING HARDWARE WITH 8051


void main()
{
lcd_init();
while(1)
{
while(get_key()==-1);
x=get_key();
lcd_printc(x);
delay(100);
}
}
unsigned char get_key()
{
unsigned char i,j,k;
for(i=0;i<4;i++)
{
P1=~(1<<i);
delay(20);
for(j=4;j<=7;j++)
{
if(!((P1)&(1<<j)))
{
k = a[i][j-4];
return k;
}
}
}
return -1;
}
void lcd_init()
{
delay(15);
lcd_write_cmd(0x38);
delay(5);
lcd_write_cmd(0x38);
lcd_write_cmd(0x06);
lcd_write_cmd(0x0c);
lcd_write_cmd(0x0E);
lcd_clear();
15EE51 Microcontrollers Laboratory

// LCD Power on delay


// 8BIT, 2 LINE , 5x8 DOT Format font
// Small delay

Page 36

INTERFACING HARDWARE WITH 8051


}
void lcd_printc(char a_char)
{
lcd_write_data(a_char);
}
void lcd_prints(char *string)
{
while (*string)
lcd_printc(*string++);
}
void lcd_clear()
{
lcd_write_cmd(0x01);
}
void lcd_write_cmd(unsigned char cmd)
{
delay(10);
LCD_WR = 0;
LCD_EN = 0;
LCD_RS = 0;
// Reset LCD_RS for Command
P0 = cmd;
LCD_EN = 1;
// Pulse LCD_EN
LCD_EN = 0;
LCD_WR = 1;
}
void lcd_write_data(unsigned char val)
{
delay(10);
LCD_WR = 0;
LCD_EN = 0;
LCD_RS = 1;
// SET LCD_RS for DATA
P0 = val;
LCD_EN = 1;
// Pulse LCD_EN
LCD_EN = 0;
LCD_WR = 1;
}

15EE51 Microcontrollers Laboratory

Page 37

INTERFACING HARDWARE WITH 8051


void delay(unsigned int dval)
{
TMOD &= 0xF0;
TMOD |= 0x01;
while (dval) {
TR0 = 0;
TF0 = 0;
TH0 = 0xFA;
TL0 = 0x00;
TR0 = 1;
while (TF0 == 0);
dval--;
}
TR0 = 0;
}

Fig 4.4 Matrix keypad and 16 x 2 LCD display

RESULT:
Thus LED,buzzer,matrix keypad and LCD were interfaced with 8051 starter kit.

15EE51 Microcontrollers Laboratory

Page 38

Potrebbero piacerti anche