Anda di halaman 1dari 21

Sr No

1
2

Title
BLINKING LED
INTERFACING ANALOG-TO-DIGITAL
CONVERTERS

THE STEPPER MOTOR INTERFACE

INTERFACING LCDs

SERIAL DATA COMMUNICATION

TRAFFIC LIGHT SIMULATOR

ELEVATOR SIMULATOR

Date

Sign

INTERFACING ANALOG-TO-DIGITAL CONVERTERS


Analog-to-digital Converters accept analog inputs such as light, temperature etc. and convert them
to a digital form. The ADC0808/0809 used here uses successive approximation as a conversion
techniqueand has 8 input channels from where it can access 8 analog signals.
The timing Diagram shown below illustratesthe conversion sequence as follows:
1> Place analog input on any desired channel.
2> Place address of the selected input channel on address lines ADD A, ADD B &ADD C.
3> Latch the input address using ALE (Address Latch Enable) singal.
4> Apply START pulse, commanding the ADCto start conversion.
5> Wait for the EOC (End of Converstion) signal to become Low and then High informing that the
conversion from analog to digital is complete.
6> Enable the Output by making OE line High.

7> Read in the digital data from ADCs output lines.


In the circuit presented here, we are taking voltage as an analog input from a pot of 10K ohms.
Weare using port P1 for reading in the converted digital data and port P3 for control lines. We have
chosenIN2 as an input channel using statements (CLR ADD_A, SETB ADD_B and CLR ADD_C). A
preset isused to set the Vref+ to a desired value. If we set the Vref+ to 2.56 V then we get a
convinient step size of10 mV. We vary the analog input voltage to the ADC by rotating the pot.
Since the output of ADC isconnected to port P1, we can see the digital outptu on bi-color LEDs
connected to P1. The clock for ADCis derived by dividing frequency of XTAL2 pin of the crystal by IC
4040, the Binary Counter. We aretaking only one sample at a time so that observation can be made
easily. Hence after every sample, wechange the analog input voltage by rotating the pot, making
sure that the input voltage does not exceed2.56V; because this is an 8-bit ADC and the maximum
digital output can expect is 255. Use Multimeterto measure this voltage (There is an orange
coloured socket provided on the ADC interface for thispurpose). Then press RESET buttons so that
program reexecutes. The convereted digital output can thenbe observed on bi-color LEDs of port
P1. To convert the digital value observed on the LEDs, useWindows calculator in Scientific mode.
In calculator -> View ->Scientific. Select Bin, then feed 1s and 0s displayed on P1 starting
fromMSB. Then click Dec to convert the result to decimal. Compare the input voltage with the
digital outputvoltage. They should be almost equal. For example, if the input analog voltage is 1.9V
(=1900 mV), thenthe digital output will be approximately 190 (=1900/10). For next sample, vary
the pot and press RESETbutton.

INTERFACING PROGRAM FOR ANALOG-TO-DIGITAL CONVERTERS


#include <AT89x52.h>
#include <intrins.h>
#define IN_PORT P1 //
#define ON 1
#define OFF 0
sbit ADDR_A = P3^3; //
sbit ADDR_B = P3^1; //
sbit ADDR_C = P3^0; //
sbit ALE = P3^4;
sbit OE = P3^5;
sbit START = P3^6;
sbit EOC = P3^7;
unsigned char nop;
void main( void )
{
IN_PORT = 0xff; // make as input
EOC = 1;
ALE = 0;
START = 0;
OE = 0;
//
// while(1) // infinite loop
// {
ADDR_C = 0;
ADDR_B = 1;
ADDR_A = 0;
nop++; ALE = 1;
nop++; START = 1;
nop++; ALE = 0;
START = 0;
while(EOC) {_nop_();}
while(!EOC) {_nop_();}
OE = 1;
for (;;);
// } //end of while
} // end of main

THE STEPPER MOTOR INTERFACE


It is often desirable in an application to accurately position a load or device. Conventional DC orAC
motors are ill-suited in such cases because it is difficult to determine the exact position of the
load,motor speed, or how much total movement has been produced; unless external positioning
sensors,encoders and controlling devices are used. In such applications, using stepper motor is a
better option.Stepper motor is an electromechanical device which converts electrical pulses into
discrete mechanicalmovements.
Features of Stepper Motor:
1. Angle of rotation is proportional to the number of input pulses.
2. Speed is proportional to the frequency of input pulses.
3. Bi-directional Operation.
4. Open-loop system. No position feedback is required.
5. Non-cumulative positioning error.
6. Excellent low speed and high torque characteristics. No need for gear reduction.
7. Holding torque when energized.
8. Absence of brushes for longer trouble free life.
Disadvantages of Stepper Motor:
1. Resonance can occur if not systematically controlled.
2. Canonotbe used for applications demanding extremly high speed.
3. If torque is exceeded beyoun limit, all knowledge of position is lost.
4. Produces much less torque as compared to that produced by DC/AC motor of comparable size.
5. Expensive.

In the scheme presented here, only lower order 4 lines of port P1 are used in the interface. A
number00110011 is placed on port P1 and rotated right when motor is to be rotated in clockwise
directionand rotated left when motor is to rotated in anticlockwise direction. A delay is necessary
betweensteps.
If we use a stepper motor with step angle of 1.8 degrees, then 200 steps will cause a one
completerotation (1.8 X 200 = 360).

THE INTERFACING PROGRAM


#include <reg51.h>
sbit SW = P2^7;
voidMSDelay(unsigned int value);
void main()
// Start of main() function
{
P1 = 0x00;
SW = 1; // Initialize Port 1 as Output Port
while(1) // Infinite Loop
{
if (SW == 0)
{
P1 = 0X66;
MSDelay(50);
P1 = 0XCC;
MSDelay(50);
P1 = 0X99;
MSDelay(50);
P1 = 0X33;
MSDelay(50);
}
else
{
P1 = 0X66;
MSDelay(50);
P1 = 0X33;
MSDelay(50);
P1 = 0X99;
MSDelay(50);
P1 = 0XCC;
MSDelay(50);
}
}
}
voidMSDelay(unsigned int value)
{
unsignedint x, y;
for (x=0;x<1275;x++)
for(y=0;y<value;y++);
}

INTERFACING LCDs
An LCD communicated with the host (89S51 in our case) via the data bus (D0-D7) and 3
controllines viz. Enable (EN), Register Select (RS) and Read/Wirte (R/W). LCD contains two bytewideregisters.
1. Instruction Register (IR) or Command Register For sending commands. Accessedwhen RS
ispulled Low.
2. Data Register (DR) For sending characters to be displayed. Accesssed when RS is made High.
LCD can be programmed to display characters in various attributes such as character
resolutionwhether 5 x 7 dots/character or 5 x 10 dots/characterm type of cursor whether simple or
block, cursorblinking or no blink, cursor on or off etc. We can also program the LCD to display the
character in sameposition or next character at the next position etc. This is done by sending
various command bytes to theLCD. To send a particular command byte, we have to make RS line
low. However while sendingcharacters to be displayed on the LCD, we have to make this line high.
In our scheme we are using port P1 for data and 3 lines of port P3 for handshaking as follows:P3.3RS, P3.4-R/W, 93.5-EN. Before sending any command to the LCD, it should be checked whetherthe
LCD is busy or not. The routine to check this is named READY. When an LCD is busy the bit 7 ofthe
Command Register is High. As soon as an LCD is ready to accept commands it makes bit 7 low.

INTERFACING PROGRAM FOR LCDs


#include <AT89x52.h>
#include <intrins.h>
voidlcdcmd (unsigned char value);
voidlcddata (unsigned char value);
voidMSDelay(unsigned intitime);
voidlcdready();
//#define IN_PORT P1 //
//#define OUT_PORT P3
sfrldata = 0x90;
sbitrs = P3^3;
sbitrw = P3^4;
sbit en = P3^5;
sbit busy = P1^7;

void main()
{
lcdcmd (0x38);
lcdcmd (0x0E);
lcdcmd (0x01);
lcdcmd (0x06);
lcddata ('E');
lcddata ('D');
lcddata ('K');
lcddata ('I');
lcddata ('T');
for (;;);
}
voidlcdcmd (unsigned char value)
{
lcdready();
ldata = value;
rs = 0;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
return;
}

voidlcddata (unsigned char value)


{
lcdready();
ldata = value;
rs = 1;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
return;
}
voidlcdready()
{
busy = 1;
rs = 0;
rw = 1;
while(busy==1)
{
en = 0;
MSDelay(1);
en = 1;
}
return;
}
voidMSDelay(unsigned intitime)
{
unsignedint i, j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}

SERIAL DATA COMMUNICATION


The Edkits51 kit communicates with PC via the serial port using a crossed serial cable (2 3, 3 -2, 5 50. Timer 1 is used in mode 2 (auto-reload) to generate the desired baud rate. The
mode is set usingTMOD register. And the baud rate is set by loading appropriate value in TH
register. The serial datacommunication parameters such as baud rate, no. of data bits, parity etc.
are set using SCON register.SBUF register is used for transmitting or receiving a bte of data. The
bte of data to be transmitted in
placed in SBUF. Similarly, SBUF holds the byte of data when it is received. The bit nos 0 and 1 in
SCONregister are Receive and Transmit flags RI and TI. These flags are monitored in program using
a loop tocheck whether the byte is transmitted or received.
IC 232 is a RS-232 line driver/receiver which converts the voltage levels from TTL/CMOS to
RS-232 compatible level and vice versa. The voltage level for RS-232 are +3V to +15V for Hi and
-3V to -15V for Lo. Also the TxD and RxD lines use negative logic. i.e. the voltage at the connectors
is +3V to+15V when 0 is transmitted (or received) and -3V to -15V when 1 is transmitted (or
received). IC 232gates also invert these levels.
Write a program to transfer the message Welcome serially at 9600 baud, 8-bit data, 1
stop bit. Do this continuously. Program is written for crystal 11.0592 MHz.

10

INTERFACING PROGRAM FOR SERIAL DATA COMMUNICATION


ORG 0000h
MOV TMOD,#20h ;timer 1, mode 2
MOV TH1,#-3 ;9600 baud
MOV SCON,#50h ;8-bit, 1 stop bit, REN enabled
SETB TR1 ;start timer 1
AGAIN: MOV A,#'W' ;transfer 'W'
ACALL TRANS
MOV A,#'E' ;transfer 'E'
ACALL TRANS
MOV A,#'L' ;transfer 'L'
ACALL TRANS
MOV A,#'C' ;transfer 'C'

11

ACALL TRANS
MOV A,#'O' ;transfer 'O'
ACALL TRANS
MOV A,#'M' ;transfer 'M'
ACALL TRANS
MOV A,#'E' ;transfer 'E'
ACALL TRANS
MOV A,#' ' ;transfer ' '
ACALL TRANS
SJMP AGAIN ;keep doing it
;--Serial data transfer subroutine
TRANS: MOV SBUF,A ;load SBUF
HERE: JNB TI,HERE ;wait for last bit to transfer
CLR TI
RET
END

TRAFFIC LIGHT SIMULATOR

12

INTERFACING PROGRAM FOR TRAFFIC LIGHT SIMULATOR


#include<AT89x51.h>
voidms_delay(unsigned char);
void signal_1();
void signal_1_yellow();

13

void signal_2();
void signal_2_yellow();
void signal_3();
void signal_3_yellow();
void signal_4();
void signal_4_yellow();
sbit red_1 = P0^0;
sbit yellow_1 = P0^1;
sbit green_1 = P0^2;
sbit green_left_1 = P0^3;
sbit green_right_1 = P0^4;
sbit red_2 = P0^5;
sbit yellow_2 = P0^6;
sbit green_2 = P0^7;
sbit green_left_2 = P1^0;
sbit green_right_2 = P1^1;
sbit red_3 = P1^2;
sbit yellow_3 = P1^3;
sbit green_3 = P1^4;
sbit green_left_3 = P1^5;
sbit green_right_3 = P1^6;
sbit red_4 = P1^7;
sbit yellow_4 = P2^0;
sbit green_4 = P2^1;
sbit green_left_4 = P2^3;
sbit green_right_4 = P2^4;
void main()
{
red_1 = 0;
yellow_1 = 0;
green_1 = 0;
green_left_1 = 0;
green_right_1 = 0;
red_2 = 0;
yellow_2 = 0;
green_2 = 0;
green_left_2 = 0;
green_right_2 = 0;
red_3 = 0;
yellow_3 = 0;
green_3 = 0;
green_left_3 = 0;
green_right_3 = 0;
red_4 = 0;
yellow_4 = 0;
green_4 = 0;
green_left_4 = 0;
green_right_4 = 0;
while(1)
{
signal_1();
ms_delay(1000);
signal_1_yellow();
ms_delay(100);
signal_2();
ms_delay(1000);
signal_2_yellow();
ms_delay(100);
signal_3();
ms_delay(1000);
signal_3_yellow();
ms_delay(100);
signal_4();
ms_delay(1000);
signal_4_yellow();
ms_delay(100);

14

}
}
void signal_1()
{
red_1 = 0;
yellow_1 = 0;
green_1 = 1;
green_left_1 = 1;
green_right_1 = 1;
red_2 = 1;
yellow_2 = 0;
green_2 = 0;
green_left_2 = 1;
green_right_2 = 0;
red_3 = 1;
yellow_3 = 0;
green_3 = 0;
green_left_3 = 1;
green_right_3 = 0;
red_4 = 1;
yellow_4 = 0;
green_4 = 0;
green_left_4 = 1;
green_right_4 = 0;
return;
}
void signal_1_yellow()
{
red_1 = 0;
yellow_1 = 1;
green_1 = 1;
green_left_1 = 1;
green_right_1 = 1;
red_2 = 1;
yellow_2 = 0;
green_2 = 0;
green_left_2 = 1;
green_right_2 = 0;
red_3 = 1;
yellow_3 = 0;
green_3 = 0;
green_left_3 = 1;
green_right_3 = 0;
red_4 = 1;
yellow_4 = 0;
green_4 = 0;
green_left_4 = 1;
green_right_4 = 0;
return;
}
void signal_2()
{
red_1 = 1;
yellow_1 = 0;
green_1 = 0;
green_left_1 = 1;
green_right_1 = 0;
red_2 = 0;
yellow_2 = 0;
green_2 = 1;
green_left_2 = 1;
green_right_2 = 1;
red_3 = 1;
yellow_3 = 0;
green_3 = 0;
green_left_3 = 1;

15

green_right_3 = 0;
red_4 = 1;
yellow_4 = 0;
green_4 = 0;
green_left_4 = 1;
green_right_4 = 0;
return;
}
void signal_2_yellow()
{
red_1 = 1;
yellow_1 = 0;
green_1 = 0;
green_left_1 = 1;
green_right_1 = 0;
red_2 = 0;
yellow_2 = 1;
green_2 = 1;
green_left_2 = 1;
green_right_2 = 1;
red_3 = 1;
yellow_3 = 0;
green_3 = 0;
green_left_3 = 1;
green_right_3 = 0;
red_4 = 1;
yellow_4 = 0;
green_4 = 0;
green_left_4 = 1;
green_right_4 = 0;
return;
}
void signal_3()
{
red_1 = 1;
yellow_1 = 0;
green_1 = 0;
green_left_1 = 1;
green_right_1 = 0;
red_2 = 1;
yellow_2 = 0;
green_2 = 0;
green_left_2 = 1;
green_right_2 = 0;
red_3 = 0;
yellow_3 = 0;
green_3 = 1;
green_left_3 = 1;
green_right_3 = 1;
red_4 = 1;
yellow_4 = 0;
green_4 = 0;
green_left_4 = 1;
green_right_4 = 0;
return;
}
void signal_3_yellow()
{
red_1 = 1;
yellow_1 = 0;
green_1 = 0;
green_left_1 = 1;
green_right_1 = 0;
red_2 = 1;
yellow_2 = 0;
green_2 = 0;

16

green_left_2 = 1;
green_right_2 = 0;
red_3 = 0;
yellow_3 = 1;
green_3 = 1;
green_left_3 = 1;
green_right_3 = 1;
red_4 = 1;
yellow_4 = 0;
green_4 = 0;
green_left_4 = 1;
green_right_4 = 0;
return;
}
void signal_4()
{
red_1 = 1;
yellow_1 = 0;
green_1 = 0;
green_left_1 = 1;
green_right_1 = 0;
red_2 = 1;
yellow_2 = 0;
green_2 = 0;
green_left_2 = 1;
green_right_2 = 0;
red_3 = 1;
yellow_3 = 0;
green_3 = 0;
green_left_3 = 1;
green_right_3 = 0;
red_4 = 0;
yellow_4 = 0;
green_4 = 1;
green_left_4 = 1;
green_right_4 = 1;
return;
}
void signal_4_yellow()
{
red_1 = 1;
yellow_1 = 0;
green_1 = 0;
green_left_1 = 1;
green_right_1 = 0;
red_2 = 1;
yellow_2 = 0;
green_2 = 0;
green_left_2 = 1;
green_right_2 = 0;
red_3 = 1;
yellow_3 = 0;
green_3 = 0;
green_left_3 = 1;
green_right_3 = 0;
red_4 = 0;
yellow_4 = 1;
green_4 = 1;
green_left_4 = 1;
green_right_4 = 1;
return;
}
voidms_delay(unsigned char itime)
{
int k;
int i;

17

int j;
for(k=0;k<10;k++)
{
for(i=0;i<itime;i++)
{
for(j=0;j<1275;j++);
}
}
return;

ELEVATOR SIMULATOR

18

INTERFACING PROGRAM FOR ELEVATOR SIMULATOR


#include<at89x51.h>

19

unsigned char current_fl;


unsigned char requested_fl;
void delay(unsigned char);
void out(unsigned char);
sbit sw1 = P1^0;
sbit sw2 = P1^1;
sbit sw3 = P1^2;
sbit sw4 = P1^3;
sbit sw1_r = P0^4;
sbit sw2_r = P0^5;
sbit sw3_r = P0^6;
sbit sw4_r = P0^7;
sbit a_7442 = P0^0;
sbit b_7442 = P0^1;
sbit c_7442 = P0^2;
sbit d_7442 = P0^3;
sbit current_fl_0 = ACC^0;
sbit current_fl_1 = ACC^1;
sbit current_fl_2 = ACC^2;
sbit current_fl_3 = ACC^3;
void main()
{
sw1_r = 0;
sw2_r = 0;
sw3_r = 0;
sw4_r = 0;
sw1_r = 1;
sw2_r = 1;
sw3_r = 1;
sw4_r = 1;
current_fl = 0x00;
ACC = current_fl;
a_7442 = current_fl_0;
b_7442 = current_fl_1;
c_7442 = current_fl_2;
d_7442 = current_fl_3;
while(1)
{
if(sw1==1)
{
requested_fl = 0x00;
while(current_fl<=requested_fl)
{
out(current_fl);
current_fl++;
}
while(current_fl>requested_fl)
{
current_fl--;
out(current_fl);
}
sw1_r = 0;
delay(10);
sw1_r = 1;
}
if(sw2==1)
{
requested_fl = 0x03;
while(current_fl<=requested_fl)
{
out(current_fl);
current_fl++;
}
while(current_fl>requested_fl)
{
current_fl--;

20

out(current_fl);
}
sw2_r = 0;
delay(10);
sw2_r = 1;
}
if(sw3==1)
{
requested_fl = 0x06;
while(current_fl<=requested_fl)
{
out(current_fl);
current_fl++;
}
while(current_fl>requested_fl)
{
current_fl--;
out(current_fl);
}
sw3_r = 0;
delay(10);
sw3_r = 1;
}
if(sw4==1)
{
requested_fl = 0x09;
while(current_fl<=requested_fl)
{
out(current_fl);
current_fl++;
}
while(current_fl>requested_fl)
{
current_fl--;
out(current_fl);
}
sw4_r = 0;
delay(10);
sw4_r = 1;
}
}
}
void out(unsigned char current_fl_temp)
{
ACC = current_fl_temp;
a_7442 = current_fl_0;
b_7442 = current_fl_1;
c_7442 = current_fl_2;
d_7442 = current_fl_3;
delay(100);
return;
}
void delay(unsigned char itime)
{
inti,j;
for(i=0;i<=itime;i++)
for(j=0;j<=1275;j++);
return;

21

Anda mungkin juga menyukai