Interfacing First Week
Interfacing First Week
Interfacing First Week
// Follow indentation in every C program when practicing, writing programs in the record
and also on the data sheet.
#include<reg51.h> // to access ports, timer registers etc.,
#include <reg51.h>
void main()
{
//void delay(unsigned int);
unsigned char x1[] = {0x06,0x0C,0x09,0x03};
void Delay(unsigned int);
unsigned char i,j;
P2 = 0x00; // configuring P2 as out
while(1)
{
for (j=0;j<=7;j++)
{
for(i=0;i<4;i++)
{
P2 = x1[i];
Delay(8000);
}
}
// forever wait until restart or reset
}
}
#include <reg51.h>
unsigned char x1[] = {0x03,0x09,0x0C,0x06},temp;
//unsigned char x2[] = {0x03,0x01,0x09,0x08,0x0C,0x04,0x06, 0x02};
// x2 array for alternate phase excitation
void main()
{
void clk_wise();
void cclk_wise();
void delay(unsigned int);
P2 = 0x00; // configuring P2 as out
while(1)
{
temp = P1 & 0x80;
//delay(100);
if(temp!= 0)
clk_wise();
else
cclk_wise();
}
//while(1);
P2 = x1[i];
delay(5000);
}
}
void cclk_wise(void)
{
unsigned int i;
for(i=0;i<4;i++)
{
P2 = x1[3-i];
delay(5000);
}
}