Et 3491 Emb&iot
Et 3491 Emb&iot
Sub.Code: ET3491
1
SYLLABUS
PRACTICAL EXERCISES
Experiments using 8051
1. Programming Arithmetic and Logical Operations in 8051
2. Generation of Square Waveform using 8051
3. Programming using On-Chip ports in 8051
4. Programming using Serial Ports in 8051
5. Design of a Digital Clock using Timers/Counters in 8051
2
LIST OF EXPERIMENTS
3
EX NO:
1 Programming Arithmetic and Logical Operations
in 8051
AIM:
To perform arithmetic, logical, and bit manipulation operations using 8051.
APPARATUS REQUIRED:
1. 8051 KIT
A) 8-BIT ADDITION
ALGORITHM:
Clear Program Status Word.
Select Register bank by giving proper values to RS1 & RS0 of PSW.
Load accumulator A with any desired 8-bit data.
Load the register R 0 with the second 8-bit data.
Add these two 8-bit numbers.
Store the result.
Stop the program.
4
P ROGRAM
OUTPUT:
INPUT OUTPUT
9000 9004
9001 9005
9002
9003
5
(B) 8-BIT SUBTRACTION
ALGORITHM:
➢ Clear the carry flag.
➢ Initialize the register for borrowing.
P
ROGRAM
OUT P UT
INPUT OUTPUT
9000 9004
9001 9005
9002
9003
6
(C) 8-BIT MULTIPLICATION
ALGORITHM:
➢ Get the multiplier in the accumulator.
➢ Get the multiplicand in the B register.
➢ Multiply A with B.
PROGRAM
OUTPUT:
INPUT OUTPUT
9000 9000
9001 9003
7
(D) 8-BIT DIVISION
ALGORITHM:
➢ Get the Dividend in the accumulator.
➢ Get the Divisor in the B register.
➢ Divide A by B.
PROGRAM:
OUTPUT
INPUT OUTPUT
9000 9002
9001 9003
8
RESULT:
Thus the arithmetic, logical, and bit manipulation operations using 8051 has
been performed.
9
EX NO: 2
Generation of Square Waveform in 8051
AIM:
To perform Generation of square waveform using 8051.
APPARATUS REQUIRED:
1. 8051 KIT
ALGORITHM:
10
Program
RESULT:
Thus the Generation of square wave using 8051 has been performed
11
EX.NO:3 Programming using On-Chip ports in
8051
AIM:
APPARATUS REQUIRED:
1. 8051 KIT
1. Set the port you connected to the output lines of the ADC as an input port.
2. Make the Port connected to EOC pin high. The reason for doing this is that the ADC
sends a high to low signal when the conversion of data is complete.
3. Clear the data lines which are connected to pins ALE, START, and OE as all these pins
require a Low to High pulse to get activated.
4. Select the data lines according to the input port you want to select.
5. Now that we have selected the analog input pin, we can tell the ADC to start the
conversion by sending a pulse to the START pin.
6. Wait for the High to low signal by polling the EOC pin.
7. Wait for the signal to get high again.
8. Extract the converted data by sending a High to low signal to the OE pin.
12
13
ALGORITHM FOR DAC:
14
RESULT: Thus the programming in On-Chip ports board using 8051 is verified successfully
AIM:
APPARATUS REQUIRED:
1. 8051 KIT
2. Stepper motor
ALGORITHM:
15
RESULT: Thus the programming in serial port using 8051 is verified success
16
Interfacing ADC and DAC
AIM :
Equipment Needed:
1. Nvis 5004B board
2. Adapter 5volt/1Amp
3. USB Cable
4. DSO/Oscilloscope
5. 2mm Patch Chord
17
Procedure for DAC:
1. Connect the USB cable to USB port of your PC and UART0( B
Type USB) port of the board (in PC interface & ISP section)
provided on the board.
2. Change the position of Run/ISP switch placed in “PC Interface
& ISP Section” block on the ISP mode.
3. Turn ON switch no 1, 2 placed in “I2C & SPI ” block.
4. Connect the power cable to the board and switch ‘ON’ the power switch.
5. Start the Flash Magic (available in the all programs on the Start menu of
Windows OS: Start menu/All programs/Flash Magic/Flashmagic.exe.)
and select the appropriate port settings (use baud rate 9600).
6. Program “DAC Square generation .hex” file from the folder
you have saved. 7. Switch ‘OFF’ the power supply and change the
position of Run/ISP switch placed in “PC Interface & ISP
Section” block on the RUN mode.
8. Put 4 Dip switches provided in the ‘ADC Interface’ block in the
ON position
9. Switch ‘On’ the supply, then press reset switch.
10. Observe Signal on “Aout” with DSO/Oscilloscope.
Program //ADC
18
for(i=0;i<=Time;i++)
for(j=0;j<1275;j++);
}
void LCD_Init(void)
{
LCD_Cmd(0x38); /* Function Set 8bit : 2 Line 5x7 Dots
*/ LCD_Cmd(0x0C); /* Display On curser Off */
LCD_Cmd(0x01); /* Clear Display */
LCD_Cmd(0X06); /* Entry Mode */
}
19
LCD_Delay(10);
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */
}
for(i=0;i<=Time;i++)
for(j=0;j<110;j++);
}
void PLL_Init()
{
PLL0CFG = 0x24;
feed(); /* Enabling the PLL */ PLL0CON = 0x01;
feed(); /* Wait for the PLL to lock set frequency */ while(!(PLL0STAT &
PLOCK)); /* Connect the PLL as the clock source */ PLL0CON = 0x3;
Enabling MAM and setting number of clocks used for Flash memory fetch
(4 cclks in this
case) */
MAMTIM = 0x04;
MAMCR = 0x02; /* Setting peripheral Clock (pclk) to System
Clock (cclk)*/
VPBDIV = 0x01;
20
}
void ADC_Init()
{
PINSEL0 = 0x00030000; /* channel AD1.1 */
AD1CR = 0x01210402; /* Setup A/D: 10-bit AIN1 @ 3MHz */
}
void ADC_Convert(unsigned int ADC_Value)
{
unsigned int X,Y,Z; /* Intermidiate Variables */
FirstBit=0,SecondBit=0,ThrdBit=0,FourthBit=0
; X = ADC_Value/10;
FirstBit = ADC_Value%10;
FirstBit = 0x30|FirstBit; /* First Byte(LSB)
*/ Y = X/10;
SecondBit = X % 10;
SecondBit = 0x30|SecondBit; /* Second Byte
*/ Z = Y/10;
ThrdBit = Y % 10;
ThrdBit = 0x30|ThrdBit; /* Third Byte
*/ FourthBit = Z; /* Last Byte(MSB) */
FourthBit=0x30|FourthBit;
}
Delay(5000);
LCD_Cmd(0x01);
ADC_Init(); /* ADC Initialize*/
while(1)
{
AD1CR |= 0x01000000; /* start of ADC conversion */ do
{
ADC_Val = AD1DR1; /* 10 bit value */
21
}
while ((ADC_Val & 0x80000000) == 0); /* Wait ADC
Conversion Complete*/
AD1CR &= ~0x01000000; /* Again start ADC */ ADC_Val =
(ADC_Val >> 6) & 0x03FF;
ADC_Convert(ADC_Val); /* Convert ADC value into ASCII
for LCD Display */
LCD_Disp(0x83, "ADC Value");
LCD_Cmd(0xC5);
LCD_Data(FourthBit);
LCD_Cmd(0xC6);
LCD_Data(ThrdBit);
LCD_Cmd(0xC7);
LCD_Data(SecondBit);
LCD_Cmd(0xC8);
LCD_Data(FirstBit);
Delay(40000);
}
}
Program//DAC
#include<LPC214x.H>
void msdelay(unsigned long);
int main(void)
{
unsigned int DAC_Val;
IO1DIR = 0xFFFF0040;
IO0SET = 0x00000000;
VPBDIV = 0x01;
PINSEL0 = 0x00030000; //channel AD1.1
PINSEL1 = 0x00080000; //ENABLE DAC PIN
AD1CR = 0x01210402 ; /* Setup A/D: 10-bit AIN0 @ 3MHz */
22
DAC_Val = 0x00;
DACR =DAC_Val<<6;
msdelay(200);
}
}
Result
Thus the programs for Analog to Digital Conversion (On chip ADC), (On
chip DAC) were written and its output were verified using Nvis 5004 boar
23
EX.NO:
Blocking of LEDs and LCD
Aim:
To write a program for LED and LCD Interface and verify the output
using
Nvis 5004B board.
Equipment Needed:
1. Nvis 5004B board
2. Adapter 5volt/1Amp
3. USB Cable
24
13. Switch ‘On’ the supply, then press reset
switch.
14. Observe the LED glowing according to
program
25
Windows OS: Start menu/All programs/Flash Magic/Flashmagic.exe.)
and select the appropriate port settings (use baud rate 9600).
6. Program “LCD_Interface.hex” file from the folder you have
saved. 7. Switch ‘OFF’ the power supply and change the
position of Run/ISP switch placed in “PC Interface & ISP
Section” block on the RUN mode.
8. Put all the switches provided in the ‘LED Interface’ block in the
OFF position.
9. Put all the switches provided in the ‘LCD Interface’ block in the ON
position.
10. Put 6,7,8 switches provided in the ‘Motor Drive ’ block in the ON
position.
11. Switch ‘On’ the supply, then press reset switch.
12. Observe the LCD Display according to program.
int main(void)
{
IO1DIR = 0x00070000; /* Define Port1 pin P1.16 to P1.23 as output
*/
while (1)
{
IO1SET = 0x00070000; /* Glow All LEDs */
MSdelay (100); /* Delay */
IO1CLR = 0x00070000;
MSdelay (100); /* Delay */
26
Program for LCD
27
IO1SET = Data << 16; /* Write Command Value to LCD Data Pin */
LCD_Delay(20); /* LCD_Delay for enable Clock*/ EN_Clr; /* Enable Pin
Clear
*/
LCD_Delay(10);
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */ }
void LCD_Disp(unsigned char Loc, unsigned char *String)
{
LCD_Cmd(Loc); /* Send Command to LCd */ while(*String) /*
Wait untill Null char come */ {
LCD_Data(*String++); /* Write data to LCD */
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */
}
}
int main(void)
{
IO1DIR = 0x00FF0000; /* Set LCD_DATA pin as out put */
IO0DIR = 0x00FF0000; /* Set LCD_Control pin as out put
*/ LCD_Init(); /* Initialize LCD */ while(1)
{
LCD_Disp(0x80, " NVIS "); /* Display "NVIS" */
LCD_Disp(0xC0, " Technologies "); /* Display "Technologies" */
}
}
Result
Thus the programs for LED and 16x2 LCD Display Interface were
written and its output were verified using Nvis 5004 board.
28
EX.NO
Interfacing keyboard and StepperMotor
Aim:
To write a program for a 4x4 Hex Keypad Stepper Motor Interface and
verify the output using Nvis 5004B board.
Equipment Needed:
1. Nvis 5004B board
2. Adapter 5volt/1Amp
3. USB Cable
for(i=0;i<=Time;i++)
for(j=0;j<1275;j++);
}
void LCD_Init(void)
{
LCD_Cmd(0x38); /* Function Set 8bit : 2 Line 5x7 Dots
*/ LCD_Cmd(0x0C); /* Display On curser Off */
LCD_Cmd(0x01); /* Clear Display
*/ LCD_Cmd(0X06); /* Entry Mode
*/
}
IO1SET = Data << 16; /* Write Command Value to LCD Data Pin
*/ LCD_Delay(30); /* LCD_Delay for enable Clock*/ EN_Clr; /*
30
Enable Pin Clear */
LCD_Delay(10);
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */ }
void LCD_Disp(unsigned char Loc, unsigned char *String)
31
{
LCD_Cmd(Loc); /* Send Command to LCd */ while(*String) /*
Wait untill Null char come */ {
LCD_Data(*String++); /* Write data to LCD */
IO1CLR = 0x00FF0000; /* Clear All pins of LCD
*/
}
}
int main(void)
{
IO0DIR = 0x00E00000; /* defined as Outputs for LCD P0.21,22,23*/
IO1DIR = 0x0FFF0000; /* defined as Outputs for keypad P1.23 to P1.17
LCD_Init();
LCD_Disp(0x80, " Nvis "); /* Display "NVIS" */ LCD_Disp(0xC0,
" Technologies "); /* Display "Technologies" */; LCD_Delay(5000);
LCD_Cmd(0x01); /* Clear Display */ LCD_Disp(0x82," Key Pressed");
while(1)
{
IO1SET = 0x01000000; /* Set Row 1 */
Column4*/ { LCD_Disp(0xC8,"0");
IOCLR1 = 0x80000000;
32
}
LCD_Delay (100);
}
IO1CLR = 0x01000000; /* Clear Row 1 */ IO1SET = 0x02000000; /* Set
Row 1 */ if((IO1PIN & 0xF0000000)!= 0xF0000000)
{
if((IO1PIN & 0x10000000) == 0x10000000) /*Row1,
Column1*/ {
LCD_Disp(0xC8,"2"); /* Set Curser at '0xC6' */ IOCLR1 =
0x10000000; /* Clear pins */
}
else if((IO1PIN&0x20000000) == 0x20000000) /*Row1,
Column2*/
{ LCD_Disp(0xC8,"5");
IOCLR1 = 0x20000000;
}
else if((IO1PIN&0x40000000) == 0x40000000) /*Row1,
Column3*/ { LCD_Disp(0xC8,"8");
IOCLR1 = 0x40000000;
}
else if((IO1PIN&0x80000000) == 0x80000000) /*Row1,
{ LCD_Disp(0xC8,"A");
Column4*/ IOCLR1 = 0x80000000;
}
LCD_Delay (100);
}
IO1CLR = 0x02000000; /* Clear Row 1 */ IO1SET = 0x04000000; /* Set
Row 1 */ if((IO1PIN & 0xF0000000)!= 0xF0000000)
{
if((IO1PIN & 0x10000000) == 0x10000000) /*Row1,
Column1*/ {
LCD_Disp(0xC8,"3"); /* Set Curser at '0xC6' */ IOCLR1 =
0x10000000; /* Clear pins */
}
else if((IO1PIN&0x20000000) == 0x20000000)
/*Row1, Column2*/
{ LCD_Disp(0xC8,"6");
IOCLR1 = 0x20000000;
}
else if((IO1PIN&0x40000000) == 0x40000000) /*Row1,
33
Column3*/
{ LCD_Disp(0xC8,"9");
IOCLR1 = 0x40000000;
}
else if((IO1PIN&0x80000000) == 0x80000000)
/*Row1, Column4*/
{ LCD_Disp(0xC8,"B");
IOCLR1 = 0x80000000;
}
LCD_Delay (100);
}
IO1CLR = 0x04000000; /* Clear Row 1 */ IO1SET = 0x08000000; /* Set
Row 1 */ if((IO1PIN & 0xF0000000)!= 0xF0000000)
{
if((IO1PIN & 0x10000000) == 0x10000000) /*Row1,
Column1*/ {
LCD_Disp(0xC8,"F"); /* Set Curser at '0xC6' */ IOCLR1 =
0x10000000; /* Clear pins */
}
else if((IO1PIN&0x20000000) == 0x20000000) /*Row1,
Column2*/
{ LCD_Disp(0xC8,"E");
IOCLR1 = 0x20000000;
}
else if((IO1PIN&0x40000000) == 0x40000000) /*Row1,
Column3*/ { LCD_Disp(0xC8,"D");
IOCLR1 = 0x40000000;
}
else if((IO1PIN&0x80000000) == 0x80000000) /*Row1,
{ LCD_Disp(0xC8,"C");
Column4*/ IOCLR1 = 0x80000000;
}
LCD_Delay (100);
}
IO1CLR = 0x08000000; /* Clear Row 1 */ }
}
34
Procedure for Stepper Motor Interface:
Program
int main(void)
{
IO0DIR = 0x001F0000;
IO0SET = 0x00010000;
while (1)
{
IO0SET = 0x00020000;
MSdelay(150);
35
IO0CLR = 0x00020000;
IO0SET = 0x00040000;
MSdelay(150);
IO0CLR = 0x00040000;
IO0SET = 0x00080000;
MSdelay(150);
IO0CLR = 0x00080000;
IO0SET = 0x00100000;
MSdelay(150);
IO0CLR = 0x00100000;
}
}
Result
Thus the program for Keyboard and Stepper Motor Interface were
written and its output were verified using Nvis 5004 board.
36
30