MC Interfacing
MC Interfacing
MC Interfacing
h>
yoid driveStepperMotorClockwise90Degrees() {
{
PO = 0xBB; /* Initialize Port 0/
P1 =OxDD;
P2 = OxDD;
P3 =0xDD;
delay(15);
PO =0xEE; / Step 2/
P1= OxEE;
p2 =0xEE;
P3 = 0xEE;
delay(15);
PO = 0x77; /* Step 3*/
P1 = 0x77;
P2 = Ox77;
P3=0x77;
delay(15);
while(1)
P1 = 0x00;
P2 =0x00;
P3 = 0x00;
int main(void) {
driveStepperMotorClockwise90Degrees):/ Rotate stepper motor clockwise for 90 degrees */
#define on time = 20
THO = 0xF8;
while(1 )
TH0 - 0xF8:
TRO 1; I|Turn ON timer-0
for(i-0;i<off_time;itt)
THO = 0xF8:
}
27
#include <at89c51xd2.h>
#define OFF_TIME 20
#define ON_TIME 20
void main()
(Timer 0, Mode 1)
TMOD = Ox01; // Set TimerO in 16-bit mode
to Ox00
LO-Ox00: //!ritialize the low byte of Timer O
Timer 0 to OxF8
THO = OxF8: // initialize the high byte of
while(1)
TLO = 0x00; // Reset the low byte of Timer 0 to start counting from 0
THO = 0xF8; // Reset the high byte of Timer 0 to the initial value
for(i=0;ictime;i++)
for(j=0;j<1275,j++):
void main()
int loop=0,loop2;
while(1)
for(loop=0;loop<100;loop++)
loop2=loop %10;
PO=0x10;
Pl=numslloop2);
msdelay(30):
loop2=loop / 10;
PO=0x00;
P1=numslloop2):
msdelay(10);
I|SSD- 00-99
|/CN1 ’ CN7,CN2 ’ CN8
#include<at89c51xd2.h>
for(j=0;j<1275;j++);
void main()
int loop=0,loop2;
while(1)
for(loop=0;loop<100;loop++)
loop2=loop %10;
PO=0x10;
P1=numslloop2);
msdelay(30);
loop2=loop /10;
PO=0x00;
Pl=nums[loop2]:
msdelay(10);
"Up-Counter 00---99 using Timer-0 for delay
Connection CNI To CN7 :# CN2 To CN8I
tincludecat89c51xd2.h>
void delay(int);
bit tmr0_flg=0,one_sec_flg-0;
void timer0_init(void);
void display(void);
void main(void)
AUXR=0x10;
timer0_init():
EA=1;
while(1)
while(tmro_flg=-0)
tmr0_flg-0;
dig_count+=1;
if(dig_count=-0x06)
dig count-0x00;
if(one_sec_flg==1)
{
one_sec_flg-0;
dig1+=1;
if(digl==0xOA)
digl=0;
dig2+=1;
if(dig2==0x0A)
dig2-0;
dig3+=1;
display():
void timer0_init(void)
TMOD=0x01;
TLO=0x00;
THO=0X00;
TCON=0x00;
ETO=1;
TRO=1;
void timer0_isr(void)interrupt 1
{
TLO=0x00;
THO=0x00;
TFO=0;
tmro_flg=1;
if(twenty_count==11)
one_sec_flg=1;
twenty count=0x00;
}
void display(void)
PO=0xFO;
for(i-0;i<6;i++);
if(dig_count--0x00)
temp3=digl;
PO=0x50;
else if(dig_count==0x01)
temp3=dig2;
PO=0x40;
temp3 &-0x0F;
temp2=array_dec[temp3];
P1=temp2;
for(i=0;i<4;i++);
* Pogram to demonstrate led operation displays a message on LCD sereen
lines used: P2.5 RW P2.6 RS p2.7 EN data lines : P2.0 - P2.3 */
/ Connection CN3 to CN6 */
void lcd_init(void);
void lcd comm(void);
void lcd data(void);
void wr cn(void);
void wr dn(void):
void delay(int);
unsigned char templ=0x00:
int i:
for(i=0;i<l6;i++)
for(i-0;i<20000;i++);
of first line
templ = OxCO; II Display the data from first position
I| Command Writing
lcd comm();
for(i=0:i<l6;i++)
temp2 = arr2|i];
I/ Data Writing
lcd data():
while( 1):
lend of main()
templ = Ox30:
wr cn();
delay( 500):
templ = Ox30;
WT_cn);
delay(500);
templ = 0x30:
Wr cn);
delay(500);
templ = 0x20;
wr_cn):
delay(500);
templ = Ox28;
lcd comm);
delay( 500):
lcd comm():
delay( 500):
lcd comm():
delay( 500);:
templ = Ox80: l/clear display with cursor on first position
lcd comm();
delay(500);
templ = Ox01:
lcd_comm();
delay( 500);
var = templ;
WT Cn():
delay(60):
W
Functionnto pass data to LCD
var = temp2;
temp2 = temp2 &Oxf0; I/ convert the byte
into nibble
temp2 =temp2 >> 4;
wr_dn();
temp2 = var & Ox0f:
wr_dn():
delay(60);
W
Function to write to command reg of LCD
void wr_ cn(void)
RS(P2^7)0
templ = templ & Ox7f; //
P2 = templ:
EN(P3^6F0,
temp] = templ & Oxbf; I/
P2 = templ:
UFunction to write to data reg of LCD
P2 = temp2;
int i;
for(i-0;i<count;i++);
I/sepper Motor Clock wise Intertace on flach Boart
/Connections CNI(port 0) TO CN12 CN18 TO CHAlport 3)
Mincdudeat89eS1vd2 h
vod delay).
void maintvoid)
int a-0,
UP PO-Ox0BB;
P1-0x0BB;
P2-0x0B8,
P3=Ox0BB;
delayl):
PO-0x0DD;
P1=0x0DD;
P2=0x0DD;
P3-0x0DD;
delay():
PO=0x0EE;
Pl=0x0EE;
P2=0x0EE:;
P3-0x0EE,
delayl).
PO-0x77,
P1=0x77;
P2=0x77;
P3=0x77;
delay():
a=a+1;
goto UP;
void delay()
int x=10000,y;
forly=O;y<=x;y++)
ytt;
I/Stepper Motor Clock wisse Interface on
Flash Board
WConnections CN1(port-0) TO CN12 :: CN18 TO CN4((port-3)
#include<at89c51xd2.h>
void delay):
void main(void)
int a=0;
UP: PO=0x0BB;
P1=0x0BB;
P2=0x0BB;
P3=0x0BB;
delay();
PO=0x0DD;
P1=0x0DD;
P2=0x0DD;
P3=0x0DD;
delay();
PO=0x0EE;
P1=0x0EE;
P2=0x0EE;
P3=0x0EE;
delay();
PO=0x77;
P1-0x77;
P2=0x77;
P3-0x77;
delayl):
a-a+1;
goto UP;
voId delay()
Int x 10000,y;
forly-0;y<=x;y++)
y+,
Board
Flash
on
Interface
wise
AntiClock
#include<at89c51xd2.h>
PO=0x77; P3=0x77; PO=0x0EE;
P2=0x77;
P1=0x77; P2=0x0EE;
P1=0x0EE; P1=0x0DD;
P3=0x0EE; PO=0x0DD; P2=0x0DD;
P3=0x0DD; PO=0x0BB; P2=0x0
P1=0x0BB;
Motor, void
main(void) a=0;
int delay(): delay(): delay():
delay();
void
I/Stepper
i
JP: