Vous êtes sur la page 1sur 21

1.

TOGGLE SWITCH

Aim: To write a program in embedded to toggle all the bits of portB parts continuously with a

250ms delay.

Hardware Required: Personal Computer

Software Required: Keil compiler and Flash magic

Procedure:

1. Write the assembly language for this task in the keil complier and save it with “.C”

extension.

2. Complier it and build target as per the procedure given above

3. Start the debug session by selecting the option from debug menu.

4. Use the flash magic software for program dumping process.

5. Connect the port p1. 1 to light sensor

6. Connect the port p1.7 to the buzzer

7. Seeing the output reset the set the port1.1 and see the output

Program

#include<reg51.h>

void delay(void);
void main(void)

while(1)

P1=0x55;

delay();

P1=0xAA;

delay();

void delay(void)

int i,j;

for(i=0;i<10;i++)

for(j=0;j<1000;j++)

Output:

Result: The program to toggle LED was successfully performed using keil software.
2.Flashing a light by a software delay

Aim: To write a program in embedded to perform blinking LED’S using keil software

Hardware Required: Personal Computer

Software Required: Keil compiler and Flash magic

Procedure:

1. Write the assembly language for this task in the keil complier and save it with “.C”

extension.

2. Complier it and build target as per the procedure given above

3. Start the debug session by selecting the option from debug menu.

4. Use the flash magic software for program dumping process.

5. Connect the port p1. 1 to LED input (CN4) using 8 pin connector

6. Connect the port p2.0 to switch of CN9 using flying leads.

7. Before seeing the output reset the device to communicate the peripherals

8. Connect p1. 0 to CN4

9. Reset the device to communicate with 8 pin connector to blink LED’s as per program.

10. Seeing the output reset the set the port1.1 and see the output

Program
#include<reg51.h>

sbit led=P1^0;

void delay(void);

void main(void)

while(1)

led=0;

delay();

led=1;

delay();

void delay(void)

int i,j;

for(i=0;i<10;i++)

for(j=0;j<1000;j++)

}
}

Output:

Result:

The flashing LED’s program was successfully performed using keil software.

4.Displaying Characters on LCD.

Aim: To write a program in embedded to write in LCD IN 8051 development kit using keil

software

Hardware Required: Personal Computer

8051 development board

Software Required: Keil compiler and Flash magic

Procedure:

1. Write the assembly language for this task in the keil complier and save it with “.C”

extension.

2. Complier it and build target as per the procedure given above

3. Start the debug session by selecting the option from debug menu.

4. Use the flash magic software for program dumping process.

5. Connect the port p0 to data pin in LCD module


6. Connect the pin p2.0, p2.1, p2.2 to the enable read/write and reset respectively in the

LCD module.

7. Before seeing the output reset the device to communicate with other peripheral.

Program

#include <reg51.h>

#include <string.h>

sbit rs = P2^7; // declare P2.7 as rs pin

sbit en = P2^5; // declare p2.5 as enable pin

sbit rw = P2^6; // declare p2.6 as read/write pin

sbit b = P0^7; // busy flag

void writecmd(unsigned char a); // function to send command to LCD

void writedat(unsigned char b); // function to send data to LCD

void busy(); // function to check LCD is busy or not

void writestr(unsigned char *s); // function to write string on LCD

void writecmd(unsigned char a)

busy(); // check for LCD is busy or not

rs = 0; // clear rs pin for command

rw = 0; // clear rw pin to write

P0 = a; // send command character

en = 1; // strob LCD

en = 0;
}

void writedat(unsigned char b)

busy(); // check for LCD is busy or not

rs = 1; // set rs pin for data

rw = 0; // clear rw pin to write

P0 = b; // send data character

en = 1; // strob LCD

en = 0;

void busy()

en = 0; // disable display

P0 = 0xFF; // configur P0 as input

rs = 0; // clear rs pin for command

rw = 1; // set rw pin to read

while(b==1)

en=0; // strob LCD till P0.7 is 1

en=1;

en=0;

}
void writestr(unsigned char *s)

unsigned char l,i;

l = strlen(s); // get the length of string

for(i=1;i<l;i++)

writedat(*s); // write every char one by one

s++;

main()

P0=0x00; // P0 and P0 as output ports

P2=0x00;

writecmd(0x3C); // initialize LCD

writecmd(0x0E);

writecmd(0x01); // clear memory and home cursor

writestr("Wel-Come to LCD"); // write message in first line

writecmd(0xC4); // move cursor to second line 4th pos

writestr("Program");

while(1); // continuous loop

Output:
Result: The message is displayed in the LCD was successfully performed using Keil µ vision

and implemented to 8051 development board.

4. Serial Communication using UART.

4.SERIAL TRANSMISSION

Aim: To write a program for the 8051 to transfer the letter ‘A’ serially with a baud rate of 9600

continuously use 8 bit data and 1 step bit.

Hardware Required: Personal Computer

8051 development board

Software Required: Keil compiler

Procedure:

1. Write the assembly language for this task in the keil complier and save it with “.C”

extension.

2. Complier it and build target as per the procedure given above

3. Start the debug session by selecting the option from debug menu.

4. Use the flash magic software for program dumping process.

5. Set the device 89V51RD2 using COM1 port with baud rate of 9600.

6. Select erase all option to erase previous program

7. Browse the program hex file location and select the program to dump to µc.
8. If the option comes like “Reset the device into ISP mode” press the reset button in 8051

development board.

9. Then the program will be dumped into the µc.

10. Go to the hyper terminal, name the connection COM1 port with baud rate of 9600 with

default options and press OK.

11. Now press RESET on the device so as to communicate with PC.

12. After pressing RESET key the device receives the character to hyper terminal using serial

port RS232.

PROGRAM

#include<reg51.h>

void sertx(unsigned char);

void main(void)

TMOD=0x20; //use timer 1, 8-bit data

TH1=0xFD; //9600 baud rate

SCON=0x50;

TR1=1;

while(1)

sertx(‘Y’);

sertx(‘E’);

sertx(‘S’);
}

void sertx(unsigned char x)

SBUF=x;

while(TI==0);

TI=0;

Output:

Result: Therefore, Sending a character serially was successfully performed using Keil µvision

and implemented to 8051 development board.

SERIAL RECEPTION

Aim: To write a C language program to perform serial reception in development board using keil

µvision

Hardware Required: Personal Computer

8051 development board

Software Required: Keil compiler


Procedure:

1. Write the assembly language for this task in the keil complier and save it with “.C”

extension.

2. Complier it and build target as per the procedure given above

3. Start the debug session by selecting the option from debug menu.

4. Use the flash magic software for program dumping process.

5. Set the device 89V51RD2 using COM1 port with baud rate of 9600.

6. Select erase all option to erase previous program

7. Browse the program hex file location and select the program to dump to µc.

8. If the option comes like “Reset the device into ISP mode” press the reset button in 8051

development board.

9. Then the program will be dumped into the µc.

10. Go to the hyper terminal, name the connection COM1 port with baud rate of 9600 with

default options and press OK.

11. Now press RESET on the device so as to communicate with PC.

12. After pressing RESET key the device receives the character to hyper terminal using serial

port RS232.

SERIAL RECEPTION

PROGRAM

#include<reg51.h>

unsigned char a,f=0;


sfr lcddata=0x90;

sbit rs=P3^4;

sbit rw=P3^3;

sbit en=P3^2;

sbit s=P2^1;

unsigned int cnt=-1,cnt1=0;

void delay(unsigned char a)

unsigned char i,j;

for(i=0;i<=a;i++)

for(j=0;j<=125;j++)

{}

void command(unsigned char dost)

lcddata=dost;

rs=0;

rw=0;

en=1;

delay(5);

en=0;

void lcddisplay(unsigned char word)


{

lcddata=word;

rs=1;

rw=0;

en=1;

delay(5);

en=0;

void delete1()

command(0xc0+cnt1);

command(0x10);

lcddisplay(0x20);

cnt1--;

command(0x10);

void delete()

command(0x80+cnt);

command(0x10);

lcddisplay (0x20);

cnt--;

command(0x10);
}

void main()

unsigned char m,f=0;

command(0x38);

command(0x0e);

command(0x80);

while(1)

TMOD=0x20;

TH1=0xfd;

SCON=0x50;

TR1=1;

while(RI==0);

m=SBUF;

RI=0;

if(m==0x80)

if(cnt>0)

if(cnt!=0)

delete1();
}

else

f=0;

delete();

else

if(m==0x0d)

command(0xc0);

cnt++;

f=1;

else

if(cnt==-1)

command(0x80);

cnt++;

if(cnt==16&&f==0)
{

command(0xc0);

f=1;

command(0x60);

lcddisplay(m);

if(f==0)

cnt++;

else

cnt1++;

Output:
Result: Thus, the serial reception was performed successfully by using keil µvision and

hyperterminal.

5.TIMER 0

Aim: Write a program to use the TIMER 0 as a counter.

Apparatus required:

 8051 Microcontroller kit

 CRO (cathode ray oscilloscope)

Procedure:

1. Set timer in mode1 position

2. Set B as P1.6 in B Register

3. Clear TR0 and TF0

4. Move the data for counting and giving the time to that data.

5. Back instruction is used at two steps of the program

6. Finally the result is stored that is displayed on the Cathode Ray Oscilloscope.

Program:
MOV TMOD,#01H

NEXT: SETB P1.6 (96)

CLR TR0(8C)

CLR TF0

MOV TH0,#0FFH

MOVTL0,#1AH

SETB TR0

BACK1:MOV C,TF0

JNC BACK1

CLR P1.6

CLR TR0

CLRTF0

MOV TH0,#0FDH

MOV TL0,#04DH

SETB TR0

BACK2:MOV C,TF0

JNC BACK2
SJMP NEXT

(SQUARE WAVE)

MOV TMOD,#03H

BACK1:CLR TR1

CLR TF1

MOV TH0,#04AH

SETB TR1

BACK2:MOV C,TF1

JNC BACK2

MOV C,P1.5

CPL C

MOV P1.5,C

SJMP BACK1

Output

Rectangular wave:

Amplitude=

Time period=

T=

Frequency=
Square wave:

Amplitude=

Time period=

T=

Frequency=

Output:

Result:

Thus, the program to use Timer `0` as counter has been verified successfully

Vous aimerez peut-être aussi