Upload
tanuj-kumar
View
212
Download
0
Embed Size (px)
DESCRIPTION
8051_FILE
Citation preview
MICROPROCESSOR LAB FILE
AND PLC’s APPLICATIONS
Submitted By: Tanuj KumarRoll No.-12104025
Electrical-4th Year
Submitted To: PROF. Tilak ThakurElectrical Department
Analog to Digital Converter(ADC)
Connections:
LCD control --- PORT 2
LCD data ----- PORT 0
ADC control ---- PORT 3
ADC data ----- PORT 1
PROGRAM:
#include<reg51.h>
char arr4[12]="DIGITAL O/P ";
sbit ALE=P1^2;
sbit SOC=P1^1;
sbit OE=P1^0;
sbit EOC=P1^3;
sbit SET0=P1^5;
sbit SET1=P1^6;
sbit SET2=P1^7;
sbit CLOCK=P1^4;
sbit rs=P2^0; sbit
e=P2^1;
unsigned char adc_val;
unsigned char temp[5];
void instwrt(void);
void datawrt(void);
void int_lcd(void);
void clock(void);
void delay(int x);
void main(void)
{
int i;
char dummy;
int_lcd();
for(i=0;i<12;i++)
{
P0=arr4[i];
datawrt();
delay(2);
}
while(1)
{
SET0=1;
SET1=1; //for the select line// CHANNEL 7(RA7) IS USED
SET2=1;
ALE=1;
SOC=1;
clock();
ALE=0;
SOC=0;
clock();
while(!EOC);
OE=1;
adc_val=P3;
dummy=P3;
for(i=0;i<3;i++)
{
temp[i]=adc_val%10;
adc_val /=10;
}
P0=0x8C;
instwrt();
delay(2);
for(i=2;i>=0;i--)
{
P0=temp[i]+0x30;
datawrt();
delay(2);
}
}
}
void instwrt(void)
{
rs=0;
e=1;
e=0;
}
void datawrt(void)
{
rs=1;
e=1;
e=0;
}
void int_lcd(void)
{
P0=0x38;
instwrt();
delay(2);
P0=0x01;
instwrt();
delay(2);
P0=0x06;
instwrt();
delay(2);
P0=0x0c;
instwrt();
delay(2);
P0=0x80;
instwrt();
delay(2);
}
void delay(int x)
{
int i,j; for(j=0;j<x;j+
+) for(i=0;i<10000;i+
+);
}
void clock(void)
{
int a,b;
for(b=0;b<=1000;b++)
{
for(a=0;a<30;a++);
CLOCK=~CLOCK;
}
}
Digital to Analog Converter (DAC)PROGRAM:
#include<reg51.h>
void main()
{unsigned char waveval[12]={128,192,238,255,238,192,128,64,17,0,17,64};int i;while(1){for(i=0;i<=12;i++)P2=waveval[i];}}
DC MOTOR
#include<reg51.h>
sbit m1=P0^0;
sbit m2=P0^1;
void delay(int x)
{
int a;
for(a=0;a<x;a++);
}
void main()
{
m2=0;
m1=1;
delay(300);
m1=0;
delay(1000);
}
DIP SWITCH
#include<reg51.h>
sbit a=P0^0;
sbit b=P0^1;
sbit c=P0^2;
sbit d=P0^3;
sbit e=P0^4;
sbit f=P0^5;
sbit g=P0^6;
sbit h=P0^7;
sbit a1=P2^0;
sbit b1=P2^1;
sbit c1=P2^2;
sbit d1=P2^3;
sbit e1=P2^4;
sbit f1=P2^5;
sbit g1=P2^6;
sbit h1=P2^7;
void main()
{ P0=0x00;
P2=0x00;
while(1) {
if(a1==1)
{ a=1; }
else if(b1==1)
{b=1; }
else if(c1==1)
{c=1; }
else if(d1==1)
{d=1;}
else if(e1==1)
{e=1 ; }
else if(f1==1)
{f=1; }
else if(g1==1)
{g=1;}
else if(h1==1)
{ h=1; }
else
{a=b=c=d=e=f=g=h=0;}
} }
EEPROM
/* CONNECT P0---Lcd control///
/* P2-----LCd data/////
/* P1L--- Eprom sec.*/
#include<reg51.h>
#include<intrins.h>
typedef unsigned char uchar;
typedef unsigned long ulong;
typedef unsigned int uint;
#define TIMER_RELOAD (-921)
#define port_delay() _nop_(), _nop_(), _nop_(), _nop_()
#define AVG 10
sbit LRS = P0 ^ 0;
sbit LEN = P0 ^ 1;
sbit SCL = P1 ^ 0;
sbit SDA = P1 ^ 1;
uint count;
uchar rdata,edata;
void timer0(void)
interrupt 1 using 1
{
count++;
TH0 = (uchar)(TIMER_RELOAD>>8);
TL0 = (uchar)TIMER_RELOAD;
}
void delay(uint n)
{
n = count + n;
while (n != count);
}
void dispstr(uchar *str, uchar stcol, uchar encol)
{
uint q;
if(stcol <= 15)
P2 = 0x80 + stcol;
else
P2 = 0xB0 + stcol;
LRS = 0;
LEN =
1; LEN = 0;
delay(1);
LRS = 1;
q=0;
for(; stcol <= encol; stcol++)
{
if(stcol == 16)
{
P2 = 0xB0 + stcol;
LRS = 0;
LEN = 1;
LEN = 0;
delay(1);
LRS = 1;
}
P2 = str[q];
q++;
LEN = 1;
LEN = 0;
delay(1);
}
}
void dispnum(uint no, uchar stcol, uchar encol)
{
uchar temp[5];
uchar i,k;
for (i = 0; i < 5; i++)
{
temp[i] = no % 10;
no /= 10;
}
if(stcol <= 15)
P2 = 0x80 + stcol;
else
P2 = 0xB0 + stcol;
LRS = 0;
LEN =
1; LEN = 0;
delay(1);
LRS = 1;
i = k = 4;
for(; stcol <= encol; stcol++)
{
if( k == 1)
{
k = 200;
dispstr(".",stcol,stcol);
}
else
{
P2 = temp[i] + 0x30;
i--;
k--; LEN
= 1;
LEN = 0;
delay(1);
}
}
}
void clrlcd()
{
LRS = 0;
P2 = 0x01;
LEN = 1;
LEN = 0;
delay(6);
}
void start(void)
{
SDA = 1 ;
_nop_() , _nop_() ,
_nop_() ; SCL = 1;
_nop_() , _nop_() ,
_nop_() ; SDA = 0 ;
_nop_() , _nop_() ,
_nop_() ; SCL = 0 ;
_nop_() , _nop_() , _nop_() ;
}
void stop(void)
{
SDA = 0 ;
_nop_() , _nop_() ,
_nop_() ; SCL = 1;
_nop_() , _nop_() ,
_nop_() ; SDA = 1 ;
_nop_() , _nop_() ,
_nop_() ; SCL = 0 ;
_nop_() , _nop_() , _nop_() ;
}
void clock(void)
{
_nop_() ; _nop_() ;
_nop_() ; SCL = 1;
_nop_() ; _nop_() ;
_nop_() ; SCL = 0 ;
_nop_() ; _nop_() ; _nop_() ;
}
void nack(void)
{
SDA = 1 ;
clock() ;
}
void opdat(uchar dat)
{
uchar i ;
_nop_() , _nop_() , _nop_() ;
for ( i = 0 ; i < 8 ; i++ )
{
if ( ( dat >> ( 7 - i ) ) & 0x01 ) SDA = 1 ;
else SDA = 0 ;
clock() ;
}
}
void waitack(void)
{
SDA = 1 ;
SCL = 1;
_nop_() , _nop_() ,
_nop_() ; SCL = 0 ;
_nop_() , _nop_() , _nop_() ;
}
uchar getdat(void)
{
uchar i , dat;
SDA = 1;
_nop_() , _nop_() , _nop_();
for ( i = 0 ; i < 8 ; i++ )
{
SCL = 1;
dat = ( ( ( dat << 1 ) & 0xfe ) | SDA );
_nop_() , _nop_() , _nop_();
SCL = 0;
_nop_() , _nop_() , _nop_();
}
return dat;
}
uchar i2c_read(uchar addr)
{start(); //dummy write start
opdat(0xa0); //send dev addr
waitack();
opdat(addr);
waitack();
start(); //start read
opdat(0xa1); //give dev adddr or with for read
waitack(); //operation coz lsb gives r|w
rdata = getdat();
nack() ;
stop() ;
return(rdata);
}
void i2c_write(uchar dat, uchar addr)
{
start();
opdat(0xa0); //dummy write startwaitack(); //send dev addr
opdat(addr);
waitack();
opdat(dat); //write data
waitack();
stop();
}
void io_open(void)
{
LEN = 0;
TMOD = 0x21;
IE = 0x92; //1001 0010
SCON = 0x50; //0101 0000
REN = 1;
TL0 = (uchar)TIMER_RELOAD;
TH0 = (uchar)TIMER_RELOAD >>
8; TH1 = TL1 = 0xFA;
TR0 = 1;
TR1 = 1;
}
void initlcd(void)
{
LEN = 0;
LRS = 0;
delay(20);
P2 = 0x30;
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x30;
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x30;
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x38; //funtion set
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x0c8; //display off
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x01; //clear display;
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x06; //entry mode set
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x0c; //display on
LEN = 1;
delay(1);
LEN = 0;
delay(6);
}
void main(void)
{
uchar i;
io_open();
initlcd();
clrlcd ();dispstr(" ADVANCE ",0,15);
for(i = 0; i <200;i++)
{
i2c_write(i,i);
delay(50);
}
i = 0;
clrlcd();
while(1)
{
edata = i2c_read(i);
dispnum(edata,16,21);
i++;dispstr(" ADVANCE ",0,15);
delay(2000);
clrlcd();
}
}
HEX KEYPAD
#include<reg51.h>
//////////// PIN DEFINED ///////////////
#define KEYPAD_PORT P0
#define DATA P1
sbit RS=P2^0;
sbit E=P2^1;
#include"delay.h"
#include"lcd.h"
#include"keypad.h"
void main(void)
{
unsigned char key;
init_lcd(); //lcd init.
cmd_lcd(0x80); //Set curser position
string_lcd("Press key : "); //Display string
while(1)
{
cmd_lcd(0xc0);
key = keyscan(); //Scan keypad
data_lcd(key); //Display pressed key on lcd
}
}
LCD
// CONTROL PORT
2 //DATA PORT 0
#include<reg51.h>
sbit RS = P2 ^ 0;
sbit E = P2 ^ 1;
void instwrt(void)
{
RS=0;
E=1;
E=0;
}
void datawrt(void)
{
RS=1;
E=1;
E=0;
}
void delay(void)
{
unsigned int i;
for(i=0;i<=30000;i++)
{}
}
void main(void)
{
while(1)
{
P0=0x38;
instwrt();
delay();
P0=0x0E;
instwrt();
delay();
P0=0x01;
instwrt();
delay();
P0=0x06;
instwrt();
delay();
P0=0x83;
instwrt();
delay();
P0='A';
datawrt();
delay();
P0='D';
datawrt();
delay();
P0='V';
datawrt();
delay();
P0='A';
datawrt();
delay();
P0='N';
datawrt();
delay();
P0='C';
datawrt();
delay();
P0='E';
datawrt();
delay();
/*shift();
delay();*/
P0=0xC3;
instwrt();
delay();
P0='T';
datawrt();
delay();
P0='E';
datawrt();
delay();
P0='C';
datawrt();
delay();
P0='H';
datawrt();
delay();
P0='N';
datawrt();
delay();
P0='O';
datawrt();
delay();
P0='L';
datawrt();
delay();
P0='O';
datawrt();
delay();
P0='G';
datawrt();
delay();
P0='Y';
datawrt();
delay();
}
}
LCD 4 BIT
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at
TRISB3_bit; // End LCD module
connections
char txt1[] = "mikroElektronika";
char txt2[] = "EasyPIC6";
char txt3[] = "Lcd4bit";
char txt4[] = "example";
char i; // Loop variable
void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}
void main(){
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,6,txt3); // Write text in first row
Lcd_Out(2,6,txt4); // Write text in second row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,1,txt1); // Write text in first row
Lcd_Out(2,5,txt2); // Write text in second row
Delay_ms(2000);
// Moving text
for(i=0; i<4; i++) { // Move text to the right 4 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
while(1) { // Endless loop
for(i=0; i<8; i++) { // Move text to the left 7 times
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
}
for(i=0; i<8; i++) { // Move text to the right 7 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
}
}
LED ROTATE
////led------Port P0 ////
# include<reg51.h>
void delay();
void main()
{ while(1)
{
P1=0X01;
delay();
P1=0X02;
delay();
P1=0X04;
delay();
P1=0X08;
delay();
P1=0X10;
delay();
P1=0X20;
delay();
P1=0X40;
delay();
P1=0X80;
delay();}}
void delay(){int i;
for(i=0;i<=30000;i++);
}
RELAY BUZZER
////relay buzzer------Port P1//////
#include<reg51.h>
void delay()
{
int j;
for(j=0;j<20000;j++);
}
void main()
{ char k;
while(1)
{
P1=0x01;
delay();
for(k=0;k<3;k++)
{
P1=P1<<1;
delay();
}
}
}
RTC
/*******************RTC************************/
/****************connections ******************/
/********* LCD control --- PORT 0 **********/
/********* LCD DATA ----- PORT 2 **********/
/********* RTC SEC ---- PORT 1 **********/
#include<reg51.h>
#include<intrins.h>
typedef unsigned char uchar;
typedef unsigned long ulong;
typedef unsigned int uint;
#define TIMER_RELOAD (-921)
#define port_delay() _nop_(), _nop_(), _nop_(), _nop_()
#define AVG 10
sbit LRS = P0 ^ 0;
sbit LEN = P0 ^ 1;
sbit ICLK = P1 ^ 0;
sbit IDAT = P1 ^ 1;
uint count;
uchar rdata,edata;
uint time;
uchar second,minute,hour,day,date,month,year;
void timer0(void)
interrupt 1 using 1
{
count++;
TH0 = (uchar)(TIMER_RELOAD>>8);
TL0 = (uchar)TIMER_RELOAD;
}
void delay(uint n)
{
n = count + n;
while (n != count);
}
void dispstr(uchar *str, uchar stcol, uchar encol)
{
uint q;
if(stcol <= 15)
P2 = 0x80 + stcol;
else
P2 = 0xB0 + stcol;
LRS = 0;
LEN = 1;
LEN = 0;
delay(1);
LRS = 1;
q=0;
for(; stcol <= encol; stcol++)
{
if(stcol == 16)
{
P2 = 0xB0 + stcol;
LRS = 0;
LEN = 1;
LEN = 0;
delay(1);
LRS = 1;
}
P2 = str[q];
q++;
LEN = 1;
LEN = 0;
delay(1);
}
}
void dispnum(uint no, uchar stcol, uchar encol)
{
uchar temp[5];
uchar i;
for (i = 0; i < 2; i++)
{
temp[i] = no % 10;
no /= 10;
}
if(stcol <= 15)
P2 = 0x80 + stcol;
else
P2 = 0xB0 + stcol;
LRS = 0;
LEN =
1; LEN = 0;
delay(1);
LRS = 1;
i = 1;
for(; stcol <= encol; stcol++)
{
P2 = temp[i] + 0x30;
i--;
LEN = 1;
LEN = 0;
delay(1);
}
}
void clrlcd()
{
LRS = 0;
P2 = 0x01;
LEN = 1;
LEN = 0;
delay(6);
}
void str1307(void)
{
IDAT = 1 ;
_nop_() , _nop_() ,
_nop_() ; ICLK = 1 ;
_nop_() , _nop_() ,
_nop_() ; IDAT = 0 ;
_nop_() , _nop_() ,
_nop_() ; ICLK = 0 ;
_nop_() , _nop_() , _nop_() ;
}
void stp1307(void)
{
IDAT = 0 ;
_nop_() , _nop_() ,
_nop_() ; ICLK = 1 ;
_nop_() , _nop_() ,
_nop_() ; IDAT = 1 ;
_nop_() , _nop_() ,
_nop_() ; ICLK = 0 ;
_nop_() , _nop_() , _nop_() ;
}
void clock(void)
{
_nop_() ; _nop_() ;
_nop_() ; ICLK = 1 ;
_nop_() ; _nop_() ;
_nop_() ; ICLK = 0 ;
_nop_() ; _nop_() ; _nop_() ;
}
void ack1307(void)
{
IDAT = 0 ;
clock() ;
}
void nack1307(void)
{
IDAT = 1 ;
clock() ;
}
void opdat(char rtcdata)
{
char i ;
for ( i = 0 ; i < 8 ; i++ )
{
if ( ( rtcdata >> ( 7 - i ) ) & 0x01 ) IDAT = 1 ;else IDAT =
0 ;
clock() ;
}
}
void waitack(void)
{
// watch() ;
IDAT = 1 ;
_nop_() , _nop_() ,
_nop_() ; while ( IDAT ) ;
ICLK = 1 ;
_nop_() , _nop_() ,
_nop_() ; ICLK = 0 ;
}
char getdat(void)
{
char i , dat ;
// watch() ;
IDAT = 1 ;
_nop_() , _nop_() ,
_nop_() ; for ( i = 0 ; i < 8 ;
i++ )
{
ICLK = 1 ;
dat = ( ( ( dat << 1 ) & 0xfe ) |
IDAT ) ; _nop_() , _nop_() ,
_nop_() ;
ICLK = 0 ;
_nop_() , _nop_() , _nop_() ;
}
return dat ;
}
void getrtc(void)
{
char rdata ;
/ watch() ;
str1307() ;
opdat(0xd0)
; waitack() ;
opdat(0x00) ;
waitack() ;
stp1307() ;
_nop_() , _nop_() ,
_nop_() ; str1307() ;
opdat(0xd1) ;
waitack() ; rdata
= getdat() ;
ack1307() ;
second = ( rdata & 0x7f) ;
rdata = getdat() ;
ack1307() ;
minute = ( rdata &
0x7f) ; rdata = getdat() ;
ack1307() ;
hour = ( rdata &
0x3f) ; rdata = getdat() ;
ack1307() ;
/ watch() ;
day = ( rdata & 0x07) ;
rdata =
getdat() ;
ack1307() ;
date = ( rdata &
0x3f) ; rdata = getdat() ;
ack1307() ;
month = ( rdata & 0x1f) ;
rdata = getdat() ;
nack1307() ;
year =
rdata ; stp1307() ;
}
void setrtc(void)
{
char
rdata ; //
watch() ;
str1307() ;
opdat(0xd0)
; waitack() ;
opdat(0x00) ;
waitack() ;
rdata = ( second &
0x7f) ; opdat(rdata) ;
waitack() ;
rdata = ( minute &
0x7f) ; opdat(rdata) ;
waitack() ;
rdata = ( hour &
0x3f) ; opdat(rdata) ;
waitack() ;
rdata = ( day &
0x07) ; opdat(rdata);
waitack();
rdata = ( date &
0x3f); opdat(rdata) ;
waitack() ;
rdata = ( month &
0x1f); opdat(rdata);
waitack() ;
rdata = year ;
opdat(rdata)
; waitack() ;
stp1307() ;
}
unsigned char bcdtime(unsigned char x)
{
return ( ( ( x / 10 ) << 4 ) + ( x % 10 ) ) ;
}
unsigned char binarytime(unsigned char x)
{
return ( ( ( x >> 4 ) * 10 ) + ( x & 0xf ) ) ;
}
void getrtc1(void)
{
getrtc() ;
// watch() ;
year = binarytime( year );
month = binarytime( month );
date = binarytime( date ); hour
= binarytime( hour ); minute =
binarytime( minute ); second =
binarytime( second );
}
void setrtc1(void)
{
// watch() ;
year = bcdtime( year ) ;
month = bcdtime( month ) ;
date = bcdtime( date ) ;
hour = bcdtime( hour ) ;
minute =
bcdtime( minute ) ; second =
bcdtime( second ) ; setrtc() ;
}
void io_open(void)
{
LEN = 0;
TMOD = 0x21;
IE = 0x92; //1001 0010
SCON = 0x50; //0101 0000
REN = 1;
TL0 = (uchar)TIMER_RELOAD;
TH0 = (uchar)TIMER_RELOAD >>
8; TH1 = TL1 = 0xFA;
TR0 = 1;
TR1 = 1;
}
void initlcd(void)
{
LEN = 0;
LRS = 0;
delay(20);
P2 = 0x30;
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x30;
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x30;
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x38; //funtion set
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x0c8; //display off
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x01; //clear display;
LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x06; //entry mode
set LEN = 1;
delay(1);
LEN = 0;
delay(6);
P2 = 0x0c; //display on
LEN = 1;
delay(1);
LEN = 0;
delay(6);
}
void main(void){
io_open();
initlcd();
clrlcd ();
dispstr(" ADVANCE ",0,15);
delay(2000);
minute = 52;
hour = 3;
second = 1;
date = 18;
month = 5;
year = 4;
setrtc1();
/ getrtc1();
dispstr(":",18,18);
dispstr(":",21,21);
while(1)
{ getrtc1();
dispnum(hour,16,17);
dispnum(minute,19,20);
dispnum(second,22,23);
}
}
SERIAL COMM AS TRANSMITTER
#include<reg51.h>
void delay(int x)
{
int i;
for(i=0;i<x;i++);
}
void main()
{
SCON=0x50;
TMOD=0x20;
TH1=0xFD;
TR1=1;
while(1)
{
SBUF='a';
while(TI==0);
TI=0;
delay(4000);
}
}
SEVEN SEGMENT
/***************Seven Segments***************/
/***************Connections******************/
/********** SS data --- PORT 0 ******/
/********** SS control --- PORT 2 ******/
#include<reg51.h>
char arr[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
void delay(void);
void main(void)
{
int a;
while(1)
{ for(a=0;a<10;a++)
{ P2=0x0f;
P0=arr[a];
delay();
delay(); delay();
}}}
void delay(void)
{
int f;
for(f=0;f<30000;f++);
}
STEPPER MOTOR UNIVERSAL
#include<reg51.h>
delay()
{
int i;
for(i=0;i<=6000;i++);//1000 fast///3000 medium//6000 slow
}
void main()
{
while(1)
{
P0=0x01;
delay();
P0=0x08;
delay();
P0=0x02;
delay();
P0=0x04;
delay();
};
}
SWITCH DIP
#include<reg51.h>
sbit a=P2^0;
sbit b=P2^1;
sbit c=P2^2;
sbit d=P2^3;
sbit a1=P1^0;
sbit b1=P1^1;
sbit c1=P1^2;
sbit d1=P1^3;
void main()
{ P1=0x00;
P2=0x00;
while(1) {
if(a1==1) {
a=1; }
else if(b1==1)
{b=1; }
else if(c1==1)
{c=1; }
else
if(d1==1) {d=1; }
else
{a=b=c=d=0;}
} }