You are on page 1of 6

2020UEC1901

Experiment no.01

Aim: To write C or Assembly program to interface 7 segments with


8051/ARM to display 0-9 and 0000-9999 on universal embedded
system board.

Equipments: Universal Embedded system board with 2FRC cable


and power supply, serial adapter.

Code:

#Code for delay

//saved in current directory as delay.h file.

void delay(int t)
{
int i;
for(i=0; i<t; i++);
}

#Code for displaying 0-9 digits on 7 segments display

#include<reg51.h>
#include"delay.h"

#define SEG_DATA P2
#define SEG_CTRL P0

1
2020UEC1901

unsigned char sev_seg[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};

void main(void)
{
unsigned char a;
while(1)
{
for(a=0;a< 10;a++)
{
SEG_CTRL=0x01
SEG_DATA=sev_seg[a];
delay(3000);
}
}
}

#Code for displaying 0000-9999 digits on 7 segments display

#include<reg51.h>
#include"delay.h"

#define SEG_DATA P0
#define SEG_CTRL P2

unsigned char sev_seg[10] = {0xbf, 0x86, 0xdb, 0xcf, 0xe6, 0xed, 0xfd, 0x87, 0xff, 0xef};

void main(void)
{
unsigned char a,b,c,d,e;
while(1)
{
for(d=0;d<10;d++)
{
for(c=0;c< 10;c++)
{
for(b=0;b< 10;b++)
{
for(a=0;a< 10;a++)

2
2020UEC1901

{
for(e=0;e<50;e++) // for delay or hold the hole value for few sec
{
SEG_CTRL = 0x01;
SEG_DATA = sev_seg[a];
delay(200);

SEG_CTRL = 0x02;
SEG_DATA = sev_seg[b];
delay(200);

SEG_CTRL = 0x04;
SEG_DATA = sev_seg[c];
delay(200);

SEG_CTRL = 0x08;
SEG_DATA = sev_seg[d];
delay(200);
}
}
}
}
}
}
}

Conclusion: Thus we have written a code to interface 7 segments


with 8051/ARM to display 0-9 and 0000-9999 on universal
embedded system board.

Experiment no.02
3
2020UEC1901

Aim: To write C or Assembly program to interface 16*2 char


Module with 8051/ARM on universal embedded system board.

Equipments: Universal Embedded system board with 2FRC cable


and power supply, serial adapter.

Code:

#Code for delay

//saved in current directory as delay.h file.

void delay(int t)
{
int i;
for(i=0; i<t; i++);
}

#Code for displaying 16*2 char on LCD display

#include<reg51.h>
#define DATA P0

sbit RS=P2^0;
sbit E=P2^1;

#include"delay.h"

void cmd_lcd (unsigned char dat) // function to write command at lcd port
{

4
2020UEC1901

DATA=dat;
RS=0; //clear RS (ie. RS=0) to write command
E=1; // send H-L pulse at E pin
delay(100);
E=0;
delay(100);
}

void data_lcd (unsigned char dat) // function to write data at lcd port
{
DATA=dat;
RS=1; // set RS=1 to write DATA
E=1; // send H-L pulse at E pin
delay(100);
E=0;
delay(100);
}

void init_lcd() // function to initialize the LCD at power on time


{
cmd_lcd(0x38); // 2x16 display select
delay(50000);
cmd_lcd(0x0c); // display on cursor off command
delay(1000);
cmd_lcd(0x06); // automatic cursor movement to right
delay(1000);
cmd_lcd(0x01); // lcd clear command
delay(5000);
}

void string_lcd(unsigned char *str) // function to display string to lcd


{
while(*str!='\0') // '\0' is null char as last char of pointer
is null
{
data_lcd(*str);
str++;
}
}

void main()
{
char i;
init_lcd();
while(1)
{
cmd_lcd(0x80);

5
2020UEC1901

string_lcd("LCD DISPLAY");
cmd_lcd(0xc0);
string_lcd("** 8051 ** ");

for(i=0;i<5;i++)
{
cmd_lcd(0x1C);
delay(30000);
}
for(i=0;i<5;i++)
{
cmd_lcd(0x18);
delay(30000);
}
}
}

Conclusion: Thus we have written a code to interface 16*2 char


LCD module with 8051/ARM on universal embedded system board.

You might also like