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 / hey try

hey try

|

Microcontroller › 8051 › Interfacing 16×2 LCD Character Problem › hey try

October 26, 2011 at 5:37 pm #6751
Ashish Angural
Participant

hey try this

 

#include<reg51.h>

#include<intrins.h>

#define data P1
 

sbitS1=P1^0;

sbitS2=P1^2;

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 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 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(“MOTOR CLOCKWISE”);
    clkwise();
   }
   else if(S2==0)
   {
       ACC=0x01;
    lcd_cmd();
    ACC=0x80;
    lcd_cmd();
    lcd_puts(“MOTOR ANTICLOCKWISE”);
    anticlkwise();
   }
  }
 }

 

this code is for stepper motor and lcd intefacing take it as an example

 

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