Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1
07-09-2015
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
Page 1
Page 2
Fig.1.3
Page 3
Fig.1.4
4.Right click Source Group 1 and select Add new Item to Source Group 1
Fig.1.5
Page 4
Fig. 1.6
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.
Page 5
Fig. 1.8
The Logic Analyzer Window opens up.Click Setup and configure as shown below to observe waveform at P1.0
Page 6
Performance Analyzer
To perform analysis of various parts of the program,Click View Analysis Window Performance
Analyzer
Click Setup and configure as follows
Output of performance is shown. Average execution time of a function and various other parameters
are shown to pave way for optimization
Page 7
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
Memory Window
Page 8
Serial Window
Click View Serial Windows UART #1
This is useful for simulating Serial communication before downloading it to microcontroller.
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.
Page 9
Fig. 1.19
A dialog box opens up.Click the Output tab and check in Create HEX fileoption.ClickOK.
Fig.1.20
Page 10
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
Page 11
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.
Right Click and select add LED.New LED window opens up as shown in Fig. 1.23
Fig. 1.23
Page 12
Fig. 1.24
Fig. 1.25
RESULT:
Thus the development, debugging features of Keil Vision IDE were studied and a sample program for blinking
LED was executed.
Page 13
Ex No.2
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.
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
MOV TH0,#0x80
MOV TL0,#0x00
SETB TR0
JNB TF0,L3
CLR TR0
CLR TF0
RET
DELAY2:
L3:
OUTPUT:
Page 14
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:
Page 15
iii.
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
Page 16
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
WAIT:JNB RI,WAIT
MOV R0,SBUF
CLR RI
CJNE R0,#'y',C1
MOV P1,#0x00
SJMP DISPLAY_ON
C1:CJNE R0,#'n',C2
MOV P1,#0xFF
SJMP DISPLAY_OFF
C2:SJMP WAIT
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
Page 17
Page 18
;RESET INTERRUPT
ORG 0x0003
CPL P1.0
RETI
;EXTERNAL INTERRUPT 0
ORG 0x000B
CPL P1.1
RETI
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
SERIAL_ISR:
CLR RI
MOV R0,SBUF
CJNE R0,#'y',C1
MOV P2,#0x00
C1:CJNE R0,#'n',C2
MOV P2,#0xFF
C2:RETI
Page 19
Page 20
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
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.
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;
}
//Start Timer 0
//Poll TF0 flag
//Start Timer 0
//Poll TF0 flag
Page 23
C PROGRAMMING IN 8051
OUTPUT:
C CODE:
#include<reg51.h>
void delay();
void main()
{
TH1=-92;
TMOD=0x20;
while(1)
{
P1|=(1<<2);
delay();
P1&=~(1<<2);
delay();
}
}
void delay()
{
TR1=1;
while(!TF1);
TF1=0;
TR1=0;
}
15EE51 Microcontrollers Laboratory
Page 24
C PROGRAMMING IN 8051
OUTPUT:
iii.
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
Page 25
OUTPUT:
C PROGRAMMING IN 8051
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;
}
char Serial_Char_Receive()
{
while(!RI);
//Poll RI flag
RI=0;
//Clear RI flag
return(SBUF);
}
Page 27
C PROGRAMMING IN 8051
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);
}
//Ext.Interrupt 0
//Timer interrupt 0
Page 29
C PROGRAMMING IN 8051
//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:
RESULT:
Thus assembly and C programs for Timers/Counters, Serial Communication and Interrupts in 8051
microcontroller were written and simulated using Keil Vision IDE.
Page 30
Ex No : 4
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;
}
}
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();
}
}
Page 31
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);
Page 32
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;
}
Page 33
Page 34
Page 35
Page 36
Page 37
RESULT:
Thus LED,buzzer,matrix keypad and LCD were interfaced with 8051 starter kit.
Page 38