8051 Programme
8051 Programme
Hardware:- total 32 LEDs are connected one with each i/o line. Anodes of all 32 LEDs
are tied to Vcc and cathode is connected with port pin. Here is the program to
generate different chasing effects one after another continuously.
#include<reg51.h>
void delay(void);
void delay()
{
int a,b;
for(a=0;a<100;a++)
for(b=0;b<1000;b++);
}
void main()
{
int i, j, k, l;
for(i=0;i<50;i++) // ON-OFF effect
{
P0=0x00;
P1=0x00;
P2=0x00;
P3=0x00
Delay();
P0=0xFF;
P1=0xFF;
P2=0xFF;
P3=0xFF;
Delay();
}
for(j=0;j<50;j++) // alternate blinking effect
{
P0=0x55;
P1=0x55;
P2=0x55;
P3=0x55
Delay();
P0=0xAA;
P1=0xAA;
P2=0xAA;
P3=0xAA;
Delay();
}
for(k=0;k<50;k++) // ON-OFF effect for port lower and upper
nibble
{
P0=0xF0;
Delay();
P0=0x0F;
Delay();
P0=0xFF
P1=0xF0;
Delay();
P1=0x0F;
Delay();
P1=0xFF
P2=0xF0;
Delay();
P2=0x0F;
Delay();
P2=0xFF
P3=0xF0;
Delay();
P3=0x0F;
Delay();
P3=0xFF;
}
for(l=0;l<50;l++) // alternate switching of ports one by one
{
P0=0x00
Delay();
P0=0xFF;
P1=0x00;
Delay();
P1=0xFF;
P2=0x00
Delay();
P2=0xFF;
P3=0x00;
Delay();
P3=0xFF;
}
#include<reg51.h>
void main(void)
{
loop:P2=0xFF; // send all 1's to P1
while(P21==0xFF); // remain within loop till key is not pressed
switch(P1) // when key pressed detect is
{
case 0xFE:
P0=0xF9; // and display digit from 1 to 8
break;
case 0xFD:
P0=0xA4;
break;
case 0xFB:
P0=0xB0;
break;
case 0xF7:
P0=0x99;
break;
case 0xEF:
P0=0x92;
break;
case 0xDF:
P0=0x82;
break;
case 0xBF:
P0=0xF8;
break;
case 0x7F:
P0=0x80;
break;
}
goto loop;
}
LCD interfacing:
Hardware:- normally all types of text LCDs have 8 data pins and 3 control signals.
here data pins are connected with P0 and three control pins RS, R/W and EN are
connected with P2.7, P2.6 & P2.5 respectively. Its a 16X2 LCD.
#include <reg51.h>
#include <string.h>
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
}
ADC interfacing:
Hardware:- here I have interfaced 8 bit ADC 0804 with 8051 and given program
displays digital equivalent value (HEX) of any analog input on 2-digit multiplex seven
segment. Usually ADC has four control signals. CS (chip select-active low), WR (SOC-
start of conversion-active low), RD(OE-o/p enable-active low)and INT. from these four
only INT is o/p form ADC all other are inputs. The CS is connected with ground. WR,
RD and INT signals are connected with P3.0, P3.1 and P3.2 respectively. 8 data pins
are connected with P1. Multiplex 7-segment has 8 data pins and 2 display select pins.
data pins are connected with P0 and display select pins are connected to P2.7 and
P2.6 respectively.
#include <reg51.h>
#include <string.h>
Hardware:-a 8 bit DAC is connected to P2. Its two control signals WR and CS are tied
to ground. Here I am writing a program to generate three different types of
waveforms square, triangular and staircase type. To select desire waveform three
push buttons are connected at P3.0 to P3.2.
#include<reg51.h>