EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / check

check

|

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!=’’)
 {
  ACC=*a;
  lcd_data();
  a++;
 }
}
 
void PWM(unsigned char Ton)
{
 motor=0;
 ms_delay(Ton);
 motor=1;
 ms_delay(100-Ton);
}
 
void clkwise()
{
 unsigned char i;
 for(i=0;i<=5;i++)
 {
  A1=0;
  B1=C1=D1=1;
  ms_delay(250);
 
  B1=0;
  A1=C1=D1=1;
  ms_delay(250);
 
  C1=0;
  A1=B1=D1=1;
  ms_delay(250);
 
  D1=0;
  A1=B1=C1=1;
  ms_delay(250);
  }
}
 
void anticlkwise()
{
 unsigned char i;
 for(i=0;i<=5;i++)
 {
  D1=0;
  A1=B1=C1=1;
  ms_delay(250);
 
  C1=0;
  A1=B1=D1=1;
  ms_delay(250);
 
  B1=0;
  A1=C1=D1=1;
  ms_delay(250);
 
  A1=0;
  B1=C1=D1=1;
  ms_delay(250);
 }
}
 
void main()
{
 lcd_initialize();
 while(1);
 {
  if(S1==0)
  {
   ACC=0x80;
   lcd_cmd();
   lcd_puts(“1BIT LEFTSHIFT”);
   ibit_left();
  }
  else if(S2==0)
  {
   ACC=0x01;
   lcd_cmd();
   ACC=0x80;
   lcd_cmd();
   lcd_puts(“RIGHT SHIFT”);
   right_shift();
  }
  else if(S3==0)
  {
   ACC=0x01;
   lcd_cmd();
   ACC=0x80;
   lcd_cmd();
   lcd_puts(“1BIT RIGHTSHIFT”);
   ibit_right();
  }
  while(1);
  {
   if(S1==0)
  {
   ACC=0x80;
   lcd_cmd();
   lcd_puts(“EVEN NUMBERS”);
   even_segments();
  }
  else if(S2==0)
  {
   ACC=0x01;
   lcd_cmd();
   ACC=0x80;
   lcd_cmd();
   lcd_puts(“ODD NUMBERS”);
   odd_segments();
  }
  else if(S3==0)
  {
   ACC=0x01;
   lcd_cmd();
   ACC=0x80;
   lcd_cmd();
   lcd_puts(“DECIMALS”);
   numbers();
  }
  }
  while(1);
  {
   motor=0;
   sec_delay(10);
   motor=1;
   sec_delay(5);
   PWM(30);
  }
  while(1)
  {
   if(S1==0)
   {
   ACC=0x80;
lcd_cmd();
lcd_puts(“MOTOR CLOCKWISE”);
clkwise();
   }
   else if(S2==0)
   {
   ACC=0x01;
lcd_cmd();
ACC=0x80;
lcd_cmd();
lcd_puts(“MOTOR ANTICLOCKWISE”);
anticlkwise();
   }
  }
 }
}
 
 
 

RSS feed: Recent Posts Recent Posts

  • Portable charger for my mate's new leg October 16, 2026
  • solderless sma screw mounting RF causaliy problem October 15, 2026
  • Almost Very New in PCB / KICAD DESIGN October 15, 2026
  • Delco alternator (12SI) AC-tap - what is the mate to this connector called and where to find it? October 15, 2026
  • Semi-automatic battery handler October 15, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 Arrowfly LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of Arrowfly
Privacy Policy | Advertising

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise