Interfacing of LEDS
Total Page:16
File Type:pdf, Size:1020Kb
Dept. of Electronics & Telecommunication engg. Microcontrollers M Interfacing of LEDS: Fig. shows Interfacing of 8 LEDs with 8051 microcontroller. Anodes of the LEDs are Connected to the port pins and cathodes are connected to common ground connection. To turn on particular LED we will need to make value of that pin “High” i.e “1”. After making a particular pin high or low a small delay is executed to make that LED light visdible. ASM Program: ORG 0000H START: MOV P0, #00000000B CALL DELAY MOV P0, #00000001B CALL DELAY MOV P0, #00000010B CALL DELAY MOV P0, #00000011B CALL DELAY MOV P0, #00000100B CALL DELAY SNJB’s Late Sau K. B. Jain College of engineering, Chandwad Dept. of Electronics & Telecommunication engg. Microcontrollers M MOV P0, #00000101B CALL DELAY MOV P0, #00000110B CALL DELAY MOV P0, #00000111B CALL DELAY MOV P0, #00001000B CALL DELAY MOV P0, #00001001B CALL DELAY CALL START DELAY: MOV R0, #0FH L3:MOV R2, #0FFH L1:MOV R1,#0FFH L2: DJNZ R1, L2 DJNZ R2, L1 DJNZ R0, L3 RET END Interfacing of 7-Segment Display: Figure shows interfacing diagram of 8051 microcontroller and Seven segment display. It also shows structure of Seven segment display. There are two types of LED 7-segment displays: common cathode (CC) and common anode (CA). The difference between the two displays is the common cathode has all the cathodes of the 7- segments connected directly together and the common anode has all the anodes of the 7-segments connected together. In this diagram common anode seven segment display is used. So when we want to make any segment glow on, we will just make respective I/O pin low i.e. 0. There are total 4 seven segment displays are used. Transistors T1, T2, T3, T4 are used to trigger particular seven segment display ON and OFF. With the help of seven segment display we can display alphabetical characters such as A,B,C,D,E,F and numerical characters such as 0,1,2,3,4,5,6,7,8,9. SNJB’s Late Sau K. B. Jain College of engineering, Chandwad Dept. of Electronics & Telecommunication engg. Microcontrollers M Assembly Language Program to display all the hexadecimal characters is given below. Program: ORG 0000H MOV P1, #00001111B CALL DELAY MOV P0, #11111111B START: MOV P0, #11000000B ; DISPLAY 0 CALL DELAY MOV P0, #11111001B ; DISPLAY 1 CALL DELAY MOV P0, #10100100B ; DISPLAY 2 CALL DELAY MOV P0, #10110000B ; DISPLAY 3 CALL DELAY MOV P0, #10011001B ; DISPLAY 4 CALL DELAY MOV P0, #10010010B ; DISPLAY 5 CALL DELAY MOV P0, #10000010B ; DISPLAY 6 CALL DELAY MOV P0, #11111000B ; DISPLAY 7 CALL DELAY MOV P0, #10000000B ; DISPLAY 8 SNJB’s Late Sau K. B. Jain College of engineering, Chandwad Dept. of Electronics & Telecommunication engg. Microcontrollers M CALL DELAY MOV P0, #10010000B ; DISPLAY 9 CALL DELAY CALL START DELAY: MOV R0, #0FH L3:MOV R2, #0FFH L1:MOV R1,#0FFH L2: DJNZ R1, L2 DJNZ R2, L1 DJNZ R0, L3 RET END Interfacing of 16x2 LCD: Liquid Crystal Display (LCD) is very commonly used electronic display module and having a wide range of applications such as calculators, laptops, mobile phones etc. 16×2 character lcd display is very basic module which is commonly used in electronics devices and projects. It can display 2 lines of 16 characters. Each character is displayed using 5×7 or 5×10 pixel matrix. LCD can be interfaced with microcontroller in 4 Bit or 8 Bit mode. These differs in how data is send to LCD. In 8 bit mode to write a character, 8 bit ASCII data is send through the data lines D0 – D7 and data strobe is given through E of the LCD. LCD commands which are also 8 bit are written to LCD in similar way. The LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines. The number on data lines depends on the mode of operation. If operated in 8-bit mode then 8 data lines + 3 control lines i.e. total 11 lines are required. And if operated in 4-bit mode then 4 data lines + 3 control lines i.e. 7 lines are required. Pin Symbol Function 1 Vss Ground 2 Vdd Supply Voltage 3 Vo Contrast Setting 4 RS Register Select 5 R/W Read/Write Select 6 En Chip Enable Signal 7-14 DB0-DB7 Data Lines 15 A/Vee Gnd for the backlight 16 K Vcc for backlight SNJB’s Late Sau K. B. Jain College of engineering, Chandwad Dept. of Electronics & Telecommunication engg. Microcontrollers M Program: ORG 0000H MOV A,#38H ACALL CMD MOV A,#0EH ACALL CMD MOV A,#01H ACALL CMD MOV A,#06H ACALL CMD MOV A,#80H ACALL CMD MOV A,#'S' ACALL DISP MOV A,#'N' ACALL DISP MOV A,#'J' ACALL DISP MOV A,#'B‘ ACALL DISP SNJB’s Late Sau K. B. Jain College of engineering, Chandwad Dept. of Electronics & Telecommunication engg. Microcontrollers M L1: SJMP L1 CMD: ACALL INIT MOV P1,A CLR P3.5 CLR P3.4 SETB P3.3 CALL DELAY CLR P3.3 RET DISP: ACALL INIT MOV P1,A SETB P3.5 CLR P3.4 SETB P3.3 ACALL DELAY CLR P3.3 RET INIT: CLR P3.3 CLR P3.5 MOV P1, #0FFH SETB P3.4 L1: SETB P3.3 JB P1.7, L1 CLR P3.3 DELAY: MOV R3, #10 L1: MOV R4, #250 L2: DJNZ R4, L2 DJNZ R3, L1 RET END Interfacing of ADC0809 with 8051: Normally analogue-to-digital converter (ADC) needs interfacing through a microprocessor to convert analogue data into digital format. This requires hardware and necessary software, resulting in increased complexity and hence the total cost. The circuit of A-to-D converter shown here is configured around ADC 0809, avoiding the use of a microprocessor. The ADC 0809 is an 8-bit A-to-D converter, having data lines D0-D7. It works on the principle of successive approximation. It has a total of eight analogue input channels, out of which any one can be selected using address lines A, B and C. Here, in this case, input channel IN0 is selected by grounding A, B and C address lines. Usually the control signals EOC (end of conversion), SC (start conversion), ALE (address latch enable) and OE (output enable) are interfaced by means of a SNJB’s Late Sau K. B. Jain College of engineering, Chandwad Dept. of Electronics & Telecommunication engg. Microcontrollers M microprocessor. However, the circuit shown here is built to operate in its continuous mode without using any microprocessor. Therefore the input control signals ALE and OE, being active-high, are tied to Vcc (+5 volts). The input control signal SC, being active-low, initiates start of conversion at falling edge of the pulse, whereas the output signal EOC becomes high after completion of digitization. This EOC output is coupled to SC input, where falling edge of EOC output acts as SC input to direct the ADC to start the conversion. As the conversion starts, EOC signal goes high. At next clock pulse EOC output again goes low, and hence SC is enabled to start the next conversion. Thus, it provides continuous 8-bit digital output corresponding to instantaneous value of analogue input. The maximum level of analogue input voltage should be appropriately scaled down below positive reference (+5V) level. The ADC 0808 IC requires clock signal of typically 550 kHz, which can be easily derived from an Astable multi-vibrator constructed using 7404 inverter gates. In order to visualize the digital output, the row of eight LEDs (LED1 through LED8) have been used, where in each LED is connected to respective data lines D0 through D7. Since ADC works in the continuous mode, it displays digital output as soon as analogue input is applied. The decimal equivalent digital output value D for a given analogue input voltage Vin can be calculated from the relationship. Program: ALE EQU P3.4 OE EQU P3.7 SNJB’s Late Sau K. B. Jain College of engineering, Chandwad Dept. of Electronics & Telecommunication engg. Microcontrollers M START EQU P3.5 EOC EQU P3.6 SEL_A EQU P3.1 SEL_B EQU P3.2 SEL_C EQU P3.3 ADC_DATA EQU P1 ORG 0000H MOV ADC_DATA, #0FFH ;DATA PORT AS A INPUT SETB EOC ;EOC AS A INPUT CLR ALE ;REST AS A OUTPUT CLR OE CLR START SIGNALS MAIN: SETB SEL_A ;SELECT ANALOG CHANNEL 1 CLR SEL_B CLR SEL_C SETB ALE ;LATCH CHANNEL SELECT SETB START ;START CONVERSION CLR ALE CLR START HERE: JB EOC, HERE ; WAIT FOR END OF CONVERSION HERE1:JNB EOC, HERE1 SETB OE ;ASSERT READ SIGNAL MOV A, ADC_DATA ;READ DATA CLR OE ;START OVER FOR NEXT CONVERSION SJMP MAIN END Interfacing of 4x4 Keypad with 8051: Hex key pad is essentially a collection of 16 keys arranged in the form of a 4×4 matrix. Hex key pad usually have keys representing numerics 0 to 9 and characters A to F. The simplified diagram of a typical hex key pad is shown in the figure below. SNJB’s Late Sau K. B. Jain College of engineering, Chandwad Dept. of Electronics & Telecommunication engg. Microcontrollers M The hex keypad has 8 communication lines namely R1, R2, R3, R4, C1, C2, C3 and C4. R1 to R4 represents the four rows and C1 to C4 represents the four columns. When a particular key is pressed the corresponding row and column to which the terminals of the key are connected gets shorted. For example if key 1 is pressed row R1 and column C1 gets shorted and so on.