Embedded
Embedded
Embedded
Experiment no.01
Code:
void delay(int t)
{
int i;
for(i=0; i<t; i++);
}
#include<reg51.h>
#include"delay.h"
#define SEG_DATA P2
#define SEG_CTRL P0
1
2020UEC1901
void main(void)
{
unsigned char a;
while(1)
{
for(a=0;a< 10;a++)
{
SEG_CTRL=0x01
SEG_DATA=sev_seg[a];
delay(3000);
}
}
}
#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);
}
}
}
}
}
}
}
Experiment no.02
3
2020UEC1901
Code:
void delay(int t)
{
int i;
for(i=0; i<t; i++);
}
#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 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);
}
}
}