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 Recent Posts

  • LED circuit for 1/6 scale diorama May 15, 2025
  • stud mount Schottky diodes May 15, 2025
  • Hi Guys May 15, 2025
  • using a RTC in SF basic May 14, 2025
  • Can I use this charger in every country? May 14, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media 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 WTWH Media
Privacy Policy | Advertising | About Us

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