Microcontroller › 8051 › interfacing › check
October 5, 2011 at 5:41 pm
#6679
Ashish Angural
Participant
check this…
#include<reg51.h>
#include<intrins.h>
#define data P1
sbit S1=P3^0;
sbit S2=P3^1;
sbit S3=P3^2;
sbit motor=P3^3;
sbit S4=P3^4;
sbit RS=P2^0;
sbit RW=P2^1;
sbit E=P2^2;
sbit A1=P0^0;
sbit B1=P0^1;
sbit C1=P0^2;
sbit D1=P0^3;
void ms_delay(unsigned int a)
{
unsigned int i,j;
for(i=0;i<a;i++)
{
for(j=0;j<70;j++)
{
_nop_();
}
}
}
void sec_delay(unsigned int a)
{
unsigned int i,j;
for(i=0;i<a;i++)
{
for(j=0;j<1000;j++)
{
ms_delay(1);
}
}
}
void ibit_left()
{
unsigned char i,a;
while(1);
{
if(S1==0)
{
a=0xfe;
for(i=0;i<8;i++)
{
P1=a;
a=a<<1;
a=a+0x01;
ms_delay(500);
}
}
}
}
void right_shift()
{
unsigned char i,a;
while(1);
{
if(S2==0)
{
a=0xfe;
for(i=0;i<8;i++)
{
P1=a;
a=a>>1;
ms_delay(500);
}
}
}
}
void ibit_right()
{
unsigned char i,a;
while(1);
{
if(S3==0)
{
a=0xfe;
for(i=0;i<8;i++)
{
P1=a;
a=a>>1;
a=a+0x80;
ms_delay(500);
}
}
}
}
void even_segments()
{
unsigned char i,a[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x98};
while(1);
{
if(S1==0)
{
for(i=0;i<=9;i++)
{
if(i%2==0)
P2=a;
ms_delay(500);
}
}
}
}
void odd_segments()
{
unsigned char i,a[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x98};
while(1);
{
if(S2==0)
{
for(i=0;i<=9;i++)
{
if(i%2==1)
P2=a;
ms_delay(500);
}
}
}
}
void numbers()
{
unsigned char i,a[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x98};
while(1);
{
if(S3==0)
{
for(i=0;i<=9;i++)
{
P2=a;
ms_delay(500);
}
}
}
}
void lcd_cmd()
{
data=ACC;
RS=0;
RW=0;
E=1;
ms_delay(10);
E=0;
}
void lcd_data()
{
data=ACC;
RS=1;
RW=0;
E=1;
ms_delay(10);
E=0;
}
void lcd_initialize()
{
ACC=0x38;
lcd_cmd();
ACC=0x38;
lcd_cmd();
ACC=0x38;
lcd_cmd();
ACC=0x06;
lcd_cmd();
ACC=0x0C;
lcd_cmd();
}
void lcd_puts(unsigned char *a)
{
while(*a!=’