0% found this document useful (0 votes)
59 views6 pages

Modified 8051 Programs

This document contains code for controlling a stepper motor. The code defines pins for controlling the motor direction and speed. It uses interrupts to call the rotation function which changes the motor phase after a delay. When start is pressed it sets the direction and enables the motor. Buttons can increase or decrease the speed. Stop disables the motor.

Uploaded by

atharvaraskar44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views6 pages

Modified 8051 Programs

This document contains code for controlling a stepper motor. The code defines pins for controlling the motor direction and speed. It uses interrupts to call the rotation function which changes the motor phase after a delay. When start is pressed it sets the direction and enables the motor. Buttons can increase or decrease the speed. Stop disables the motor.

Uploaded by

atharvaraskar44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Original SSD Modified SSD

#include <reg51.h> #include <reg51.h>

void display(unsigned char byte); void display(unsigned char byte);


void delay(unsigned int time); void delay(unsigned int time);

void main(void) void main(void)


{ {
P0 = 0x00; P0 = 0x00;
P1 = 0xff; P1 = 0xff;
while(1) while(1)
{ {
display(0xC0); // Display 0 display(0xC0); // Display 0
display(0xF9); // Display 1
display(0xA4); // Display 2 }
display(0xB0); // Display 3 }
display(0x99); // Display 4 void display(unsigned char byte)
display(0x92); // Display 5 {
display(0x82); // Display 6 P0 = byte;
display(0xF8); // Display 7 delay(200);
display(0x80); // Display 8 }
display(0x90); // Display 9 void delay(unsigned int time)
display(0x88); // Display A {
display(0x83); // Display B int i,j;
display(0xC6); // Display C for(i=0;i<time;i++)
display(0xA1); // Display D for(j=0;j<1000;j++);
display(0x86); // Display E }
display(0x8E); // Display F

} Write anyone sentence to display the digit


}
void display(unsigned char byte)
{
P0 = byte;
delay(200);
}
void delay(unsigned int time)
{
int i,j;
for(i=0;i<time;i++)
for(j=0;j<1000;j++);
}
Original LCD Modified LCD
#include <reg51.h> #include <reg51.h>
#include "lcd.h" #include "lcd.h"

sbit rs=P1^0; sbit rs=P1^0;


sbit rw=P1^1; sbit rw=P1^1;
sbit en=P1^2; sbit en=P1^2;

void main(void) void main(void)


{ {
P0=0x00; P0=0x00;
P1=0x00; P1=0x00;
lcd_init(); lcd_init();
lcd_dis(1," LOGSUN SYSTEMS"); lcd_dis(const a);
lcd_dis(2," 8 Bit LCD");
while(1); }
} void lcd_init(void)
void lcd_init(void) {
{ lcd_cmd(0x38);
lcd_cmd(0x38); delayms(10);
delayms(10); lcd_cmd(0x0C);
lcd_cmd(0x0C); delayms(10);
delayms(10); lcd_cmd(0x06);
lcd_cmd(0x06); delayms(10);
delayms(10); lcd_cmd(0x01);
lcd_cmd(0x01); delayms(10);
delayms(10); lcd_cmd(0x80);
lcd_cmd(0x80); }
}
void lcd_cmd(unsigned char byte)
void lcd_cmd(unsigned char byte) {
{ P0=byte;
P0=byte; rw=0;
rw=0; rs=0;
rs=0; enable();
enable(); }
} void lcd_dat(const a)
void lcd_dat(unsigned char byte) {
{ P0=byte;
P0=byte; rw=0;
rw=0; rs=1;
rs=1; enable();
enable(); }
}
void lcd_dis( const a)
void lcd_dis( unsigned int row, const unsigned char *string) {
{
unsigned int ptr=0; lcd_dat(12600);
if(row==1){lcd_cmd(0x80);} }
else {lcd_cmd(0xC0);}
void enable(void)
while(*string) {
{ en=1;
lcd_dat(*string++); delayms(5);
ptr++; en=0;
} }
while(ptr<16)
{
lcd_dat(' ');
ptr++ ;
}
}

void enable(void)
{
en=1;
delayms(5);
en=0;
}

void delayms(unsigned int time)


{
int s,t;
for(s=0;s<time;s++)
for(t=0;t<45;t++);
}
Original Stepper Modified Stepper
#include <reg51.h> #include <reg51.h>

sbit start=P2^0; sbit start=P2^0;


sbit inc =P2^2; sbit inc =P2^2;
sbit dec =P2^3; sbit dec =P2^3;
sbit rev =P2^1; sbit rev =P2^1;
sbit stop =P2^4; sbit stop =P2^4;

sbit IN1 =P1^4; sbit IN1 =P1^4;


sbit IN2 =P1^5; sbit IN2 =P1^5;
sbit IN3 =P1^6; sbit IN3 =P1^6;
sbit IN4 =P1^7; sbit IN4 =P1^7;
sbit EN1 =P1^0; sbit EN1 =P1^0;
sbit EN2 =P1^1; sbit EN2 =P1^1;

unsigned int count=25,run=0,DIR; unsigned int count=25,run=0,DIR;

void delay(unsigned int t); void delay(unsigned int t);


void rotation(void); void rotation(void);

int main() int main()


{ {
P1=0x00; P1=0x00;
P2=0xFF; P2=0xFF;
EN1=0; EN1=0;
EN2=0; EN2=0;
while(1) while(1)
{ {
if(start==0) if(start==0)
{ {
DIR=0; DIR=0;
EN1=1; EN1=1;
EN2=1; EN2=1;
count = 25; count = 25;
run=1; run=1;
} }

else if(rev==0) else if(rev==0)


{ {
DIR=1; DIR=1;
} }
else if(inc==0 & count>2) else if(inc==0 & count>2)
{ {
count = count-1; count = count-1;
delay(20); delay(20);
} }
else if(dec==0 & count<50) else if(dec==0 & count<50)
{ {
count = count+1; count = count+1;
delay(20); delay(20);
} }
else if(stop==0) else if(stop==0)
{ {
EN1=0; EN1=0;
EN2=0; EN2=0;
IN1=0;IN2=0;IN3=0;IN4=0; IN1=0;IN2=0;IN3=0;IN4=0;
run=0; run=0;
} }
if(run==1) if(run==1)
rotation(); rotation();
} }
} }

void rotation(void) void rotation(void)


{ {
if(DIR==0) if(DIR==0)
{ {
IN1=0;IN2=0;IN3=1;IN4=1; IN1=0;IN2=0;IN3=1;IN4=1;
delay(count); delay(count);
IN1=0;IN2=1;IN3=1;IN4=0; IN1=0;IN2=1;IN3=1;IN4=0;
delay(count); delay(count);
IN1=1;IN2=1;IN3=0;IN4=0; IN1=1;IN2=1;IN3=0;IN4=0;
delay(count); delay(count);
IN1=1;IN2=0;IN3=0;IN4=1; IN1=1;IN2=0;IN3=0;IN4=1;
delay(count); delay(count);
} }

if(DIR==1) if(DIR==1)
{ {
IN1=1;IN2=0;IN3=0;IN4=1; IN1=1;IN2=0;IN3=0;IN4=1;
delay(count); delay(count);
IN1=1;IN2=1;IN3=0;IN4=0; IN1=1;IN2=1;IN3=0;IN4=0;
delay(count); delay(count);
IN1=0;IN2=1;IN3=1;IN4=0; IN1=0;IN2=1;IN3=1;IN4=0;
delay(count); delay(count);
IN1=0;IN2=0;IN3=1;IN4=1; IN1=0;IN2=0;IN3=1;IN4=1;
delay(count); delay(count);
} }
} }

void delay(unsigned int t) void delay(unsigned int t)


{ {
unsigned int i,j; unsigned int i,j;
for(i=0;i<t;i++) for(i=0;i<t;i++)
for(j=0;j<95;j++); for(j=0;j<95;j++);
} }

You might also like