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/ 30
Interfacing LED to 8051
Assembly Program to control the LED
Let us assume that the cathode of LED is connected to P1.4 and Anode is connected to 5V, through a 330 Ohm current limiting register. LED is ‘on’ when logic level on P1.4 is 0 as it is forward biased. When logic level on P1.4 is 1(5V) the LED is ‘off’ as both cathode and anode are 5V. The interfacing program alternately sends logic 0 and 1 to Port pin P1.4 to toggle the LED(make it on and off) #include <reg51.h> Sbit x=P1^4; Main() { int i; while() { x=0; for(i=0; i<=5000; i++); x=1; for(i=0; i<=5000; i++); } } Interfacing seven segment display to 8051 Program • Common anode 7 segment display will be connected through buffer to port 1( In ckt diagram it is common cathode display) • So port 1(7 segment display) is used as output port ORG 0H again:MOV DPTR, #arr7seg; starting address of array put in dptr MOV R5,#10;counter for displaying 10 digits rep: MOV A,#0H MOVC A,@A+DPTR;bring 7 segment code from array in A MOV P1,A;7 segment code sent out to 7segment display ACALL delay INC DPTR DJNZ R5, rep SJMP again Program continued ORG 100H Arr7seg DB: , , , , 99H,92H, , ,80H, , END To get the seven segment code use the following logic In common anode displays , a logic ‘0’ glows a segment and a logic ‘1’ put it off. So to see ‘5‘ segment b and e should not glow(logic 1) and rest of the segments should glow(logic 0) . Segment ‘h’ which indicates decimal point should be off BCD i/P from hgfedc ba Hex code Thumbwheel 7 segments 5(0101) 10010010 92H 8(1000) 10000000 80H 4(0100) 10011001 99H The first element of the array should be 7 segment code for 0, then for 1,then 2 and so on…. Don’t change the order ADC and DAC interfacing • Need. In computer process control the controller understands only digital information and communicates with digital signal. The sensors and control devices are analog devices and understand analog signals. So there is a need to convert the signals from analog to digital on the input side and digital to analog on the output side. For this purpose ADC and DAC are required. DAC types: R-2R ladder and binary weighted Ladder network. Most of the available DAC are R-2R type. ADC types: Flash ADC, single and dual slope ADC, counter type Adc and successive approximation ADC Parameters of ADC and DAC • Accuracy • Resolution • Full scale output • Linearity • Conversion time • Settling time • monotonocity ADC interfacing to 8051 P1 accepts the converted digital o/p. Vin represents Anlog input. WR indicates start conversion. INTR tells the status whether conversion is completed. RD signal Enables the output buffers in 0804 so that digital data is put on 8051 to read. P2.5 and P2.6 are output pins and P2.7 is the input pin conversion time of ADC 0804 is 110uS. So R and C are chosen accordingly. The formula for frequency is F= 1/1.1RC. We get a frequency of 606KHz. T=1/F gives about 110uS. It is a 8 bit parallel ADC from National semiconductor For writing a program the following steps are to be implemented Activate CS. Configure P1 and P2.7 as input. Send a rising edge (0->1) on WR pin to start conversion. Check INTR(P2.7) signal continuously. If it goes low, then send a falling edge(1->0) on RD pin. This allows 8 bit digital data on port 1 DAC interfacing to 8051 • P1 is the output port on which 8051 sends out digital data. This is converted to analog current output by DAC. Using an OPAMP based current to voltage convertor at out (I0), voltage output is produced. • The current output is given by Iout = I ref * (I7/2 +I6/4 + I5/8 + I4/16 + I3/32 +I2/64 + I1/128 + I0/256) Here Iref = 2mA • One can produce Square , Sine , Ramp and Saw tooth waves with DAC by writing appropriate C program. • For square wave send 00 and FF continuously to port P1 after some time delay. This delay decides the frequency of square wave.(00,time delay, FF, time delay) • For Ramp wave send data from 00,01,02… to FF on port P1. After FF(255) the same process is repeated. • For triangular wave use two loops. First sends 00,01,02…to FF(255) to port P1. second loop sends 254(FE),253,252,… to 01.These two loops are contunuously repeated LCD(Liquid Crystal display)interfacing to 8051 LCD interfacing • R/W is read write control. 0 for write ,1 for read • EN enables the Latch in the driver. It is a high to low pulse It should be low for atleast 450nS. • Programming requires two loops. In first loop control register is selected by making RS=0 and WR is made 0. The control or command words are sent one by one. After each word is put on the port EN is made 1 and then 0.This loop does the initializing of the LCD driver. In second loop RS=1 to select data register and WR is made 0. Then the character to be actually displayed is sent one by one. After each character is put on the port EN is made 1 and then 0.This loop does the display of message on the screen. Both the loop are continuously repeated to keep LCD working till we switch it off LCD command words S.No Command word Function
1 38H 2 line display each line 16 character (16x2)
2 80H to 8FH First line 0th character to first line 15th character 3 C0H to CFH Second line 0th character to second line 15th character 4 01H Clear display 5 05H Shift display right 6 07H Shift display left 7 0EH Display on cursor on not blinking 8 1BH /1CH Shift entire display left/right 9 0CH Display on cursor off Stepper motors • Motors two types: AC and DC motor • DC motor two types: continuous rotating and rotating in steps • Stepper motor Application :Movement of read write head in disk drives, line feed motors in printers, robotics(movement of arms) basically for position control • There are two magnets used Rotor is an permanent magnet while stator is an electromagnet. By continuously altering the magnetic field in the stator coils it is possible to move the rotor from one equilibrium position to the other. Every equilibrium position is a stable condition. Thus one rotation is achieved in a number of steps. • Step angle is the angular displacement of rotor from one equilibrium position(step) to the next consecutive step. • Step angle = 360/n where ‘n’ is the number of steps for one rotation Stepper motor interfacing Programming the stepper motor • 9,5,6 and A (1001, 0101, 0110 and 1010) :These conditions ensure that the current direction in the two stator coils are changed alternately resulting in changing of North and south poles of the electromagnets of the stator. This will cause the rotor to step in clock wise direction . • Reversing the conditions as 9,A,6,5 9…will cause the rotor to rotate in anticlockwise direction. • In the program ,A key input can be read in or a user input can be read in. If it is one send data 9,5,6,A continuously after some time delay to rotate the stator clockwise. If the input is 0 then send the reverse order ie 9,A,6,5 to continuously rotate the stator anticlockwise. The whole program is run infinitely. The time delay controls the switching of the magnetic poles of the electromagnets and hence shifting of rotor from one equilibrium position to next.