Sei sulla pagina 1di 236

AMC- 51 ADVANCED 8051 MICRCONTROLLER TRAINER EXPERIMENTAL MANUAL

AMC-51 Advanced 8051 Microcontroller Trainer

Welcome
Introduction The AMC-51 trainer is designed to study the advanced microcontroller architecture, advanced programming, and interfacing of external devices to the microcontroller.

Companys Motto Light years ahead refers to leadership.

We strive to be the best in what we do and maintain high standards in the areas of Design Quality Value Delivery Support We are indeed light years ahead of the competition in this field. We guarantee our valued customers great satisfaction.

Important Information As you will move through this manual you will quickly discover that we have complete, truly innovative & superior training products. We are so committed to quality that we back our products with a complete and comprehensive warranty.

FALCON ELECTRO-TEK PVT.LTD.


FALCON HOUSE, PLOT-A-194, TTC Industrial Area MIDC, Kopar Khairane, NAVI MUMBAI-400705 MAHARASHTRA, INDIA. TEL.: +91-22-27788551 / 27788552 / 27788553 / 27788554 FAX: 91-22-27788555

Email: falcon@falconindia .biz Website: www.falconindia.biz

Microprocessors & Microcontrollers

AMC-51 Advanced 8051 Microcontroller Trainer

Safety Guidelines

Read carefully and follow the instructions mentioned in this manual. This user manual includes all the important points about the installation, use and the maintenance of the product. Keep this manual always with you, for quick reference. After unpacking the product, arrange all the accessories in proper order, so that their integrity is checked with the packing list. Also, ensure that the accessories have no visible damage. Before connecting the power supply to the kit, be sure that the jumpers and the connecting chords are connected correctly, as per the experiment. This kit must be employed only for the use for which it has been conceived, i.e. as educational kit and must be used under the direct survey of expert personnel. Any other use is inadvisable and dangerous too. The manufacturer cannot be considered responsible for eventual damages due to improper, wrong or unreasonable uses. In case of any fault or malfunctioning in the trainer kit, turn off the power supply. Please do not tamper the kit. If you require our service, kindly contact the service centre for technical assistance. The kits are liable to malfunction/ underperforms if it is not operated under following conditions: Ambient temperature: Between 0 to 45 C Relative humidity: Between 20 to 80 %

Avoid any immediate/significant change of temperature and humidity.

Microprocessors & Microcontrollers

AMC-51 Advanced Microcontroller 8051 Trainer

Warranty

This kit is warranted against defects in workmanship and materials. Any failure due to defect in either workmanship or material should occur under normal use within a year from the original date of purchase, such failure will be corrected free of charge to the purchaser by repair or replacement of defective part or parts. When the failure is result of users neglect, natural disaster or accident, we would charge for repairs, regardless of the warranty period. The warranty does not cover include perishable items like connecting chords, crystals, etc. and other imported items. Conditions and Limitations The warranty is void and inapplicable if the defective product is not brought or sent to our authorized service center or sales outlet within the warranty period. Defective product will be Falcon Electro Tek. Pvt. Ltds sole judgment. The defective product will be replaced with a new one or repaired, without charge or with charge. In the warranty period if the service is needed, the purchaser should get in touch with the service center or the sales outlet. The purchaser should return the product to the service center or the sales outlet at his or her sole expense. The loss and damage in transit will be outside the preview of this warranty. A returned product must be accompanied by a written description of the defects. Type and Model No. of the kit has to be mentioned specifically. We return the product to the purchaser at our expense. In case the warranty does not cover the product on Falcon Electro- Tek Pvt. Ltd.s judgment, we would repair the product after obtaining prior permission from purchaser who would receive an estimate statement about the repairing charges. In such cases, Falcon Electro-Tek Pvt. Ltd. bares the transporting expenses required to send back all the repaired products for the moment, and then repairs and transporting expenses will be charged against the purchaser by the statement of accounts. When the authorized sales agents sell our products, they must notify the purchaser of the warranty contents, but they have no rights to stretch the meaning of original warranty contents or to offer an additional warranty. Falcon Electro-Tek Pvt. Ltd. does not provide any other promise or suggestive warranty and hold no liability for the damage caused by negligence, abnormal use or natural disaster. Falcon Electro-Tek Pvt. Ltd. is not responsible for the damages even if it is notified of above dangers in advance as well. For more special service or overall repairs, maintenance and up gradation of products, be sure to contact our service center or the sales outlet.

Microprocessors & Microcontrollers

AMC-51 Advanced Microprocessor 8051 Trainer

FALCON ELECTRO TEK PVT. LTD Title: Test Report Of Product

PRD / F03 / 0 1- 9 - 04

Test Report
Customer Name Distributor Name : Model Serial No. Sr. No. 1. 2. 3. 4. 5. 6. 7. 8. : AMC- 51 Advanced Microcontroller 8051 Trainer : Types Of Tests Visual Inspection Electrical Check Functional Settings Functional Test Burning Test Final Check Accessories Check As Per List Packing Report :

Checked By Signature Installed By Signature

: _____________________________ : ______________________________ : ______________________________ : ______________________________

Date: ________

Date: ________

Microprocessors & Microcontrollers

AMC-51 Advanced Microcontroller 8051 Trainer

FALCON ELECTRO TEK PVT. LTD Title: Test Report Of Product

PRD / F03 / 0 1- 9 - 04

Test Report
Customer Name Distributor Name : Model Serial No. Sr. No. 1. 2. 3. 4. 5. 6. 7. 8. Checked By Signature Installed By Signature : AMC- 51 Advanced Microcontroller 8051 Trainer : Types Of Tests Visual Inspection Electrical Check Functional Settings Functional Test Burning Test Final Check Accessories Check As Per List Packing : ______________________________ : ______________________________ : ______________________________ : ______________________________ Date: ________ Date: ________ Report :

Microprocessors & Microcontrollers

AMC-51 Advanced Microcontroller 8051 Trainer

Table of Content
1. Introduction 2. Specification 3. AMC-51 TRAINER ACCESSORIES LIST 4. 5. 6. 7 Software Installation PANAL DISCRIPTION AMC-51 COMMUNICATION SETTING SERIAL DEBUGGER 14 16 21 07 08 10 11

Software experiments
3. Experiment 1: RESET PROGRAM .. 4. Experiment 2: SEPARATION OF 2 DIGIT NUMBER 5. Experiment 3: GET 2 DIGIT NUMBER FROM 2 SINGLE DIGIT NUMBER . 6. Experiment 4: DATA AREA SEND DELIVER SUBROUTINE . 7. Experiment 5: SORTING DATA . 8. Experiment 6: FIND SAME NUMBER .. 30 9. Experiment7: R APID MULTIPLICATION OF UNSIGNEDBYTE SUBROUTINE INPUT 32 10 Experiment8: MULTIBRANCH PROGRAM 11 Experiment 9: COMPUTER CLOCK .. 12 Experiment 10 IMPULSE COUNT: Hardware experiments: 13 Experiment 1: 14 Experiment 2: 15 Experiment 3: 16 Experiment 4: 17 Experiment 5: 18 Experiment 6: 19 Experiment 7: 20 Experiment 8: LIGHT P1 PORT EXPERIMENT P1 PORT TURN LIGHT EXPERIMENT p3.3 PORT INPUT, PI PORT OUTPUT . INDUSTRY SEQUENCE CONTROL 8255 A,B,C PORT OUTPUT SQUARE WAVE 8255PAPORT CONTROL PB PORT 8255 CONTROL TRAFFIC LIGHT SIMPLE I/O EXPANSION EXPERIMENT
4

22 23 . 24 26 28

34

36
44

48 51 54 57 60 62 64 68

AMC-51 Advanced Microcontroller 8051 Trainer

21 Experiment 9: 23 Experiment 11: 24 Experiment 12:

ANALOG TO DIGITAL CONVERSION 8279 KEYBOARD DISPLAYING DISPLAYING EXPERIMENT.. COMMON USED PRINTER

71 77

22 Experiment 10 DIGITAL TO ANALOG CONVERSION.

82 88 91 95 97 105 109 116 127 135 142 153 160 166 170 176 188 190 201 217 220 223 226

25 Experiment13:MICRO PRINTER PRINTCHARACTER/CURVED SHAPE 26 Experiment 14: RELAY CONTROL 27 Experiment 15: STEPPER MOTOR CONTROL 28 Experiment 16: 8253 SQUARE WAVE . 29 Experiment 17: CONTROLLING SMALL DC MOTOR . 30 Experiment 18: LED 16 x 16 LATTICE DISPLAY 31 Experiment 19: 12864 LCD EXPERIMENT 32 Experiment 20: 8250 Serial Interface Experiment . 33 Experiment 21: 8251 PROGRAMMABLE SERIAL INTERFACE & PC COMMUNICATION 34 Experiment 22: DS 18B20 TEMPERATURE MEASUREMENT. 35 Experiment 23: INFRARED COMMUNICATION 36 Experiment 24: TL 549 SERIAL A/D CONVERSION 37 Experiment 25: TL 5615SERIAL D/A CONVERSION 38 Experiment 26: PCF 8563 REAL TIME CLOCK/CALENDAR 39 Experiment 27: MAX 8131 WATCH DOG REPLACEMENT 40 Experiment 28: VOLTAGE/FREQUENCY CONTROLLER 41 Experiment 29: SERIAL MEMORY CHIP93C46 R/W 42 Experiment 30: AT 24C02 IC BUS MEMORY R/W 43 Experiment 31: PWM IMPULSE WIDTH MODULATION 44 Experiment 32: 74LS164 SERIAL INPUT & PARALLEL OUTPUT 45 Experiment 33: 165 PARALLEL /SERIAL CONVERT 46 Experiment 34: PLAYING ELECTRONIC MUSIC

AMC-51 Advanced Microcontroller 8051 Trainer

AMC-51 Advanced Microcontroller 8051 Trainer

INTRODUCTION
The AMC-51 trainer is designed to study the microcontroller architecture, basic programming, advantages of the micro-controller over microprocessor and interfacing of external devices to the microcontroller like ADC, DAC, DC motor, Stepper motor etc.It also allows the study of interfacing devices like programmable keyboard / display, timer and I/O devices etc.. The trainer provides different application sections along with microcontroller. Only we have to connect required device to the microcontroller using patch cord provided with Kit. All application resources are available on AMC-51 trainer board. Trainer supports +5V and 12V fixed power supply. A descriptive experimental manual helps students to gain more insight in to the subject.

AMC-51 Advanced Microcontroller 8051 Trainer

SPECIFICATIONS
1) In built power source: - Inbuilt +5V, +12V and -12V dc power source are provided. 2) Microcontroller unit (Atmel 89s52):- This section includes ZIF socket for microcontroller IC, reset switch, Slide switch to select normal mode and program mode. All IC pins are accessible for connection and testing purpose. 3) Mono-pulse and clock unit: - different frequencies are provided as a clock source such as 8MHz, 4MHz, 2MHz, 1MHz, 500 KHz, 250 KHz, 125 KHz, 62.5 KHz and 31.25 KHz. 4) RS232 section: - for external RS232 serial communication use only. 5) Reset switch section: - provide reset signal to all required circuit. 6) 8251 unit: - Interface the programmable communication interface IC to microcontroller. 7) 8155 unit: - This is RAM and I/O chips to be used in MPU system. 8) 8253 unit: - Interface the programmable interval timer to microcontroller. 9) 8255 unit: - Interface the programmable peripheral I/O to microcontroller. 10) 8279 unit: - Interface the programmable Keyboard and display to microcontroller. 11) 8250 unit: - Interface the serial communication 8250 UART to microcontroller. 12) ADC0809 unit: - Interface the Analog to Digital converter to microcontroller. 13) DAC0832 unit: - Interface the Digital to Analog converter to microcontroller. 14) 8 Switch input unit: - used as user inputs.
15) 6x4 matrix key board: - keyboard used for alpha numeric input and some program

related instructions like transfer program EEPROM to RAM, memory write, memory read , execute and etc. (see appendix for more detail.) 16) 6 dynamic Led 7-seg display: - Used for alpha numeric display. 17) 16 LED output units: - LED display section for indication and checking purpose. 18) 16X16 dot matrix display: - Used for alpha numeric and graphic display. 19) LCD unit: - used for large amount data display. 20) ROM 64k: - used for program code storage.
21) RAM 32K: - for data storage memory.

AMC-51 Advanced Microcontroller 8051 Trainer

22) Expansion module (CAN /USB):- programmer can be used to connect external

CAN or USB module to micro-controller.


23) I/O expansion unit: - used to expand I/O functionality of the micro-controller.

24) Adjustable voltage unit: - used as a variable voltage source. 25) IR receiver and digital temp sensor unit: - interface the external world to microcontroller. 26) RTC and calendar unit: - used for real time clock interface to micro-controller.
27) Watch dog unit: - to monitor power-supply and battery functions in C systems.

28) Serial in parallel out unit: - used to convert serial data into parallel 8-bit data. 29) Serial digital to analog unit: - serial digital data is converted into serial analog form.
30) Buzzer: - to alert the system.

31) Relay unit: - used for relay interface to switch output (on/off). 32) RS485 unit: - used for serial RS485 communication. 33) Logic pen unit: - it shows the either high or low logic level at IN point . 34) Serial analog to digital unit: - serial analog data is converted into serial digital form. 35) V/F unit: - this used to convert voltage into frequency form. 36) PWM unit: - used to provide different width depending upon micro-controller unit. 37) Parallel in serial out: - used to convert parallel 8-bit data into serial data. 38) Dc motor: - used to study the interface of dc motor with micro-controller. 39) Stepper motor: - used to study the interface of stepper motor with micro-controller. 40) Voice recorder unit: - which based on SPI protocol. Pins are provided for connection purpose. This unit provides recording, play, erase, forward, volume, reset and FT switches for select particular function of this unit. 41) Audio amplifier: - to amplify the audio signal. 42) IC card: - to read and write the data on card. 43) Printer interface section: - to interface the external printer device to microcontroller. 44) I2c EEPROM unit: - used for data storage through I2C serial protocol. 45) Serial EEPROM unit: - used for data storage in serial form.

AMC-51 Advanced Microcontroller 8051 Trainer

AMC-51 TRAINER ACCESSORIES LIST

Sr.no. 1 2 3 4 5 6 7 8

Description Mcs-51 trainer kit Power cord 8 pin ribbon cable Remote Small patch cord Yellow- 7,Black-6,Red-4,Blue-8 Serial cable Parallel cable CD contained software, sample program etc. Experiment manual

Quantity 01 01 05 01 25 01 01 01

Check mark

01

10

Emulator

01

10

AMC-51 Advanced Microcontroller 8051 Trainer

SOFTWARE INSTALLATION
1.

Explore the AMC-51 software CD content and access AMC-51trainer / software / 8051setup.exe .Double click on the following icon.

2) Click on Next->

3) click on Next ->

11

AMC-51 Advanced Microcontroller 8051 Trainer

4) click on Install ->

5) click on Finish.

(Note: - Use AMC-51 Communication setting manual for hardware and software setting before start programming and downloading the program.)

12

AMC-51 Advanced Microcontroller 8051 Trainer

SOFTWARE UNINSTALLATION
1) Follow the steps like start->program->8051 simulation system -> uninstall 8051 simulation system-> then click on uninstall 8051 simulation system then following window will appear.

2) Click on Yes. Automatically software starts uninstalling all the required component of software 8051 simulation system. Following window shows the progress of software uninstalling process.

3) Finally following window is appearing on the screen. It shows uninstall successfully completed then Press OK to complete the uninstall process of 8051 Simulation system.

13

AMC-51 Advanced Microcontroller 8051 Trainer

PANAL DISCRIPTION:

38

39

40

41

42

43

37 1 36 35 34 33 32 31 30 29 28 7 3 4 6 5

27 26 25 3 13 12 14 15 24 23 22 21 20 19 18 16 17

10 00 00 00 10 1100

8 9

14

AMC-51 Advanced Microcontroller 8051 Trainer

S.R. NO.
1. 2 3 4 5 6 7 8 19 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

DISCRIPTION
MICROCONTROLLER UNIT EXPANSION MODULE FOR CAN &USB 8251 UNIT 8253 UNIT RS232 UNIT MATRIX KEYBOARD UNIT DECODING LATCH UNIT 8279 UNIT 8155 UNIT 8255 UNIT SWITCH INPUT UNIT LED OUTPUT UNIT I/O EXPANSION UNIT ADJUSTABLE UNIT I2C EEPROM PWM UNIT DIGITAL TEMPRATURE SENSOR SERIAL D/A DEVICE LOGIC PEN RS485 UNIT SERIAL A/D DEVICE STEPPER MOTOR DC MOTOR VOICE RECORDER AD0809 UNIT RELAY BUZZER REAL TIME CLOCK/CALENDAR SERIAL EEPROM PARALLEL IN SERIAL OUT V/F UNIT WATCHDOG UNIT IN-BUILT POWER ADC 0809 UNIT SERIAL IN PARALLEL OUT LCD UNIT AUDIO AMPLIFIER IC CARD MONOPLUS & CLOCK UNIT 16*16 DOT MATRIX 8250 UNIT DECODR SECTION

15

AMC-51 Advanced Microcontroller 8051 Trainer

AMC-51 COMMUNICATION SETTING (HARDWARE AND SOFTWARE)


1) AMC-51 Trainer kit hardware setting: Refer following picture no.1 for doing hardware setting. a) KB1 Switch: Must be sliding KB1 Switch to NORMAL PATTERN location. b) KB2 Switch: short circuit block must be insert AMC-51 location. c) SW1 Switch: short circuit block must be inserting UP location.

2) Emulator: Emulator is powered by the AMC-51 kit only need not required external supply. For Emulator connection with computer and AMC-51 trainer kit refer following picture no.2. a) Connect one end of Emulator which is having 34 pin FRC female connector to AMC -51 trainer kits box type 34 pin male connector (JF_1) using FRC cable provided with kit.
b) Other end of Emulator which is having 9 pin D-type female connector to

computer COM1 male connector using communication cable provided with kit.

standard

RS232

serial

16

AMC-51 Advanced Microcontroller 8051 Trainer

3) AMC-51 Trainer kit software setting (8051 Simulation Software): a) Check your Computer serial communication port is where COM1 or COM2.

b) Install the 8051 Simulation software software provided with the trainer Kit. Use Installation guide provided with kit. c) Connect computer serial communication port (like COM1) to AMC-51 trainer kit through emulator to JF_1 using serial cable provided with Kit and switch-ON the power of AMC-51 trainer kit. d) Open 8051 Simulation software software using Start->program->8051 simulation software and then 8051 simulation software. Following will appear on the screen. Here user have to select the communication port default is COM 1. User need not enter any Instrumentation code. Then click OK.

17

AMC-51 Advanced Microcontroller 8051 Trainer

e) Immediately following window will appear on the screen. Here 100% connectivity means Computer, Emulator and AMC-51 trainer kit is connected properly.

f) Simulation Model setting of 8051 simulation system:CPU: 8031/8032 RAM: User RAM ROM: System ROM

18

AMC-51 Advanced Microcontroller 8051 Trainer

g) Very Important Notice:Directory and file names not more than eight characters in English are allowed, otherwise the program being compiled are wrong.

Program will display following error window:-

h) When do not get 100% connectivity window then there is a problem in either AMC-51 trainer kit setting or computer communication port setting. Resolve this problem then again follow the same steps as given above. i) Now user can write a program in either Assembly or C language, compile it
19

AMC-51 Advanced Microcontroller 8051 Trainer

properly to generate .hex file and other supported file. Use 8051 simulation system to download the .hex file into microcontroller and check the functionality of program. To compile the software use tab, to run or execute the program use tab and to stop the execution use tab. j) Use the experimental manual provided with kit to do the experiments.

20

AMC-51 Advanced Microcontroller 8051 Trainer

SERIAL DEBUGGER ASSISTANCE HELP


Using this software user can communicate from AMC-51 trainer kit to computer over serial communication. 1) There is no need to install the software. We have to just open the SSCOM32.exe icon which is stored in AMC-51trainer ->software->Serial Debugging Assistance>software folder in CD. Double click on the following icon.

2) Immediately following window shows on the screen. Set the red mark setting in the software as shown in below. a) Com Num = COM1. b) Hex Data = check mark. c) Baud Rate = 9600, Data Bit = 8, Stop Bit = 1, Verify = None, Flow control = none. d) Send Hex = check mark.

3) Connect one end of serial communication RS232 D-type 9 pin cable to computer COM-1and other end is CZ11 PCB mounted D-type 9 pin connector on AMC-51 trainer kit. Finally this software is ready to communicate with AMC-51 trainer kit.

21

AMC-51 Advanced Microcontroller 8051 Trainer

Software Experiments
EXPERIMENT NO-1 RESET PROGRAM
OBJECTIVE: Fill the content between 2000H to 20FFH is other than 00H data THEORY: To reset data stored in memory location 2000h to 20FFh.Firstly we have to clear accumulator & R0 register. R0 is used here as a counter, its counting memory location 00 to FF. where as accumulator holds 00 data to store in memory location. 2000h address is loaded in DPTR. By using move instruction load 00 data in memory & INC instruction to increment both memory location & counter till R0 content becomes 00. PROGRAM: ORG 0000H LJMP SE01 ORG 0080H SE01: MOV R0,#00H MOV DPTR,#2000H LOO1: MOV A,#00H MOVX @DPTR,A INC DPTR INC R0 CJNE R0,#00H,LOO1 LOOP: SJMP LOOP END

; clear content of r0 ; 2000H address send DPTR ; clear accumulator data ; move accumulator data in memory location pointed by DPTR ; DPTR+1 ; Add 1 bytes

PROCEDURE: 1) Switch ON power supply. 2) Open respective program SW01.asm in 8051simulation system software.
3) Press compile and load tab

in the software. We can see the process window in the software at the left bottom corner. 4) Now go to Debug (D) in 8051simulation system software and press Step Over F6 command for single step execution.
5) Press F6 for further single step execution in you can see the stored data on 6)

respective memory location. For memory location please refer program Before check the content , you must stop the running program or Refresh the Data Store memory.

OUTPUT: content between 2000H to 20FFH is 00 H in Data Store Memory.(by right click on status reg.1-progam memory. Table)
22

AMC-51 Advanced Microcontroller 8051 Trainer

EXPERIMENT NO:2 SEPARATION OF 2 DIGIT NUMBER


OBJECTIVE: To separate digits of 2 digit number & store in different memory location. THEORY: Store 12 in 2000h memory location. By anding with 0FH ,get first digit .Store it in 2001 memory location. Then get another digit by using SWAP & ANL instruction .Store in 2002 the second digit. PROGRAM: ORG 0000H LJMP MAIN ORG 0080H MAIN: MOV DPTR,#2000H MOV A,#12H MOVX @DPTR,A MOV B,A SWAP A ANL A,#0FH INC DPTR MOVX @DPTR,A INC DPTR MOV A,B ANL A,#0FH MOVX @DPTR,A END PROCEDURE: 1) Switch ON power supply. 2) Open respective program SW02.asm in 8051simulation system Software. 3) Press compile and load tab in the software. We can see the process window in the software at the left bottom corner. 4) Now go to Debug (D) in 8051simulation system software and press Step Over F6 command for single step execution. 5) Press F6 for further single step execution in you can see the stored data on respective memory location. For memory location please refer program 6) Before check the content, you must stop the running program or Refresh the Data Store memory. OUTPUT: The 2000H to 2002H Data memory location shows 12,01,02 respectively.
23

; load 2000h address to DPTR ; load 12h data to accumulator ; move data stored in accumulator to memory location pointed by DPTR ; move data from accumulator to b reg. ; exchange content of accumulator ; anding 0fh data with data stored in accumulator ; increment address stored in DPTR ; move data from accumulator to memory location pointed by DPTR ; increment address stored in DPTR ; move data from b reg. to accumulator ; anding 0fh data with data stored in accumulator ; move data from accumulator to Memory location pointed by DPTR LOOP: SJMP LOOP

AMC-51 Advanced Microcontroller 8051 Trainer

EXPERIMENT NO:3 GET 2 DIGIT NUMBER FROM TWO SINGLE DIGIT NUMBERS

OBJECTIVE: To send the data of 2000H as lower and 2001H as higher byte in memory location 2002H THEORY: Take 1 & 2 as single digit number .Save 1 in 2000h & 2 in 2001h memory location. By using ANL instruction & SWAP instruction get 1 as MSB .Then by using ANL & ORL instruction get two digit required output .Store it in 2002h memory location. PROGRAM: ORG 0000H LJMP MAIN ORG 0080H MAIN: MOV DPTR,#2000H CLR A MOVX @DPTR,A MOV A,#01H MOVX @DPTR,A INC DPTR MOV A,#02H MOVX @DPTR,A MOV DPTR,#2000H MOVX A,@DPTR ANL A,#0FH SWAP A MOV B,A INC DPTR MOVX A,@DPTR ANL A,#0FH ORL A,B INC DPTR MOVX @DPTR,A END

;load DPTR by memory location address 2000H ; move data 01h to accumulator ; load accumulator data in memory location whose address pointed by DPTR ; increment address pointed by DPTR ; move data 02h to accumulator ; move accumulator data to memory location whose address pointed by DPTR ; load data of memory location 2000h to accumulator ; ANDing content of accumulator with data 0Fh ; exchange content of accumulator ; move accumulator content to b reg. ; Increment address stored in DPTR ; data stored in memory location pointed by DPTR load to accumulator ; ANDing 0fh data with content of accumulator ; oring data content in b reg. & accumulator ; increment address stored in DPTR ; move data of accumulator to memory location pointed by DPTR ; end of program

PROCEDURE: 1) Switch ON power supply. 2) Open respective program SW03.asm in 8051simulation system Software.
24

AMC-51 Advanced Microcontroller 8051 Trainer

3) Press compile and load tab in the software. We can see the process window in the software at the left bottom corner. 4) Now go to Debug (D) in 8051simulation system software and press Step Over F6 command for single step execution. 5) Press F6 for further single step execution and see the parallel effect on Data store memory window. In code memory you can see the stored on respective memory location. For memory location please refer program. 6) Before check the content , must stop the running program or Refresh the Data Store memory. OUTPUT: The 2000H to 2002H Data memory location shows 01,02,12 respectively.

25

AMC-51 Advanced Microcontroller 8051 Trainer

EXPERIMENT NO :4 Data area send Deliver Subroutine OBJECTIVE:


Data stored in memory location (0000h to 0fffh) copy to memory location 2000 to 2fffh THEORY: Store initial address 0000h in R2 & R3 register and 2000h in R4 & R5 respectively. Use R6 & R7 for counting memory location, hence load 1FFF in it. Start data storing from 1. & increase it continuously as memory location increases of source & destination, decrease content of R6 & R7. PROGRAM: ORG 0000H LJMP MAIN ORG 0080H MAIN: MOV A,#01H MOV R2,#00H ;Source address MOV R3,#00H MOV R4,#20H ;Destination address MOV R5,#00H MOV R6,#1FH ;Transmit bytes MOV R7,#0FFH SE22: MOV DPL,R3 MOV DPH,R2 ;build source program address MOVX @DPTR,A ;get number MOV DPL,R5 MOV DPH,R4 ;build Destination program address MOVX @DPTR,A ;transmit data CJNE R3,#0FFH,LO42 INC R2 INC A LO42: INC R3 ;source address add 1 CJNE R5,#0FFH,LO43 INC R4 LO43: INC R5 ;destination address add 1 CJNE R7,#00H,LO44 CJNE R6,#00H,LO45 ;byte number subtract 1 LOOP: SJMP LOOP NOP LO44: DEC R7 SJMP SE22 LO45: DEC R7 DEC R6 SJMP SE22 END PROCEDURE: 1) Switch ON power supply. 2) Open respective program SW04.asm in 8051simulation system
26

AMC-51 Advanced Microcontroller 8051 Trainer

Software. 3) Press compile and load tab in the software. We can see the process window in the software at the left bottom corner. 4) Now go to Debug (D) in 8051simulation system software and press Step Over F6 command for single step execution. 5) Press F6 for further single step execution and see the parallel effect on Data store memory window. In code memory you can see the stored data on respective memory location. For memory location please refer program to press this tab for direct execution . 6) Before check the content ,you must stop the running program or Refresh . the Data Store memory. OUTPUT: Input the source address in R2,R3,(eg:0000H), input destination address in R4,R5, (eg:2000H),input the byte number in R6,R7, (eg:1FFFH), then run the program to check whether the contend in 0000H to 1FFFH and 2000H to 3FFFH are the same. The 2000H to 2002H Data memory location shows 12,01,02 respectively.

EXPERIMENT NO :5

27

AMC-51 Advanced Microcontroller 8051 Trainer

SORTING DATA EXPERIMENT.


OBJECTIVE: Sorting data stored in memory location 50 to 5A in ascending order. THEORY: Load data in memory location 50 to 5A in any order. Use R7 as a counter .First store memory location address in R0.load data of first memory location in R2 & data from next memory to 22h memory location . compare both data, if not equal check carry flag. If flag is set ,keep data as it is . if carry is not set , exchange data & go to next memory location. Till R7 content becomes zero. PROGRAM: ORG 0000H LJMP QUE ORG 0080H QUE: MOV 50H,#08H ;load data 08h to memory location 50h MOV 51H,#01H ;load data 01h to memory location 51h MOV 52H,#07H ;load data 07h to memory location 52h MOV 53H,#02H ;load data 02h to memory location 53h MOV 54H,#06H ;load data 06h to memory location 54h MOV 55H,#09H ;load data 09h to memory location 55h MOV 56H,#02H ;load data 02h to memory location 56h MOV 57H,#04H ;load data 04h to memory location 57h MOV 58H,#08H ;load data 08h to memory location 58h MOV 59H,#03H ;load data 03h to memory location 59h MOV 5AH,#05H ;load data 05h to memory location 5Ah MOV R3,#50H ;load data 50h to reg. r3 QUE1: MOV A,R3 ;load data from r3 to accumulator MOV R0,A ;Pointer send to R0 MOV R7,#0AH ;length send to R7 CLR 00H ;Clear flag MOV A,@R0 ;data saved in memory location whose address stored in r0 moved to accumulator QL2: INC R0 ;increment stored address in r0 MOV R2,A ; move data from accumulator to r2 CLR C ; clear c reg. MOV 22H,@R0 ;move data pointed by r0 to 22h memory location CJNE A,22H,QL3 ; compare & jump if accumulator data is not equal to 22h to ql3 loop SETB C ;set bit c QL3: MOV A,R2 ;move data from r2 to accumulator JC QL1 ;jump if carry to QL1 loop SETB 00H ;set bit 00h XCH A,@R0 ;exchange accumulator data with data in r0 DEC R0 ;decrement r0 XCH A,@R0 ;exchange accumulator data with data pointed by r0 INC R0 ;increment r0 QL1: MOV A,@R0 ;move data pointed by r0 to accumulator DJNZ R7,QL2 ;decrement & jump if not zero to Ql2
28

AMC-51 Advanced Microcontroller 8051 Trainer

JB 00H,QUE1 LOOP: SJMP LOOP END

;jump if bit t0 00h to que1 ;short jump to loop ; end of program

PROCEDURE: 1) Switch ON power supply. 2) Open respective program SW05.asm in 8051simulation system Software. 3) Press compile and load tab in the software. We can see the process window in the software at the left bottom corner. 4) Now go to Debug (D) in 8051simulation system software and press Step Over F6 command for single step execution. 5) Press F6 for further single step execution and see the parallel effect on Internal store memory window. In code memory you can see the stored data on respective memory location . For memory location please refer program . For memory location please refer program or to press this tab for direct execution. 6) Before check the content , you must stop the running program or Refresh the Data Store memory. OUTPUT: The 50H to 5AH is shows the output in the In internal store memory 01,02,02,03,04,05,06,07,08,08,09 respectively.

EXPERIMENT NO-6

29

AMC-51 Advanced Microcontroller 8051 Trainer

FIND THE SAME NUMBER EXPRIMENT


OBJECTIVE: Fill zero in some units between 2000H to 200FH in the data store memory. THEORY: Load 00 in some of the memory location from 2000h to 200F. Use R0 as a counter. Clear R1 data to store number of zero count. Use CJNE instruction to compare it with 00. If it equal then increment R1 and go to next memory location, else keep R1 data as it is. PROGRAM: ORG 0000H LJMP MAIN ORG 0080H MAIN: MOV DPTR,#2000H ; load DPTR by address 2000h MOV A,#00H ; clear accumulator MOV R2,#08H ; Fill in the number of 0 LOOP: MOVX @DPTR,A ; store data from accumulator to memory location pointed by DPTR ; increment address stored in DPTR ; decrement & jump if number stored in r2 is not zero to loop L5800: MOV R0,#10H ; for increasing address location from 2000h to 200f MOV R1,#00H ; for counting number of zeroes MOV DPTR,#2000H ; starts counting L5811: MOVX A,@DPTR ; load data from DPTR memory location to accumulator CJNE A,#00H,L5816 ; Is the result equal with 00 INC R1 ; increment count of zeroes L5816: INC DPTR ; increment to next address DJNZ R0,L5811 ; decrement & jump if not zero data of R0 MOV DPTR,#2100H ; stored number of zeroes in 2100 memory location MOV A,R1 ; move r1 data in accumulator MOVX @DPTR,A ; the same number send to 2100H L581E: SJMP L581E END PROCEDURE: 1) Switch ON power supply. 2) Open respective program SW06.asm in 8051simulation system Software. 3) Press compile and load tab in the software. We can see the process window in the software at the left bottom corner. 4) Now go to Debug (D) in 8051simulation system software and press Step Over F6 command for single step execution. 5) Press F6 for further single step execution and see the parallel effect on Data store memory window. In code memory you can see the stored data on respective memory location. For memory location please refer program or to
30

INC DPTR DJNZ R2,LOOP

AMC-51 Advanced Microcontroller 8051 Trainer

press this tab direct execution. 6) Before check the content ,you must stop the running program or Refresh the Data Store memory. OUTPUT: The number of zeros which is present in the data memory 2000H to 200FH is (count) shown in 2100H data memory.

EXPERIMENT NO-7
31

AMC-51 Advanced Microcontroller 8051 Trainer

RAPID MULTIPLICATION OF UNSIGNED BYTE SUBROUTINE INPUT:


OBJECTIVE: The program doing multiplication operation with the following formula by single-byte multiplication instruction.

THEORY: Store 02 data in R2R3 & 04 data in R6 R7 register respectively. First multiply all 4 registers data with each other .Then add result of all multiplication & add carry of all multiplication. Store result in R6 R7 & store carry result in R4 R5.

PROGRAM: ORG 0000H LJMP QKUL ORG 0080H QKUL: MOV R2,#00 ; store data 0 in r2 MOV R3,#02 ; store 02 data in r3 MOV R6,#00 ; store 0 data in r6 MOV R7,#04 ; store 4 data in r7 MOV A,R3 ; move data from r3 to accumulator MOV B,R7 ; move data from r7 to b reg. MUL AB ; R3*R7 XCH A,R7 ; move multiplication result in r7 &data of r7 in accumulator MOV R5,B ; move content of b reg. in r5 MOV B,R2 ; move data from r2 to b reg. MUL AB ; R2*R7 ADD A,R5 ; result of multiplication add with data stored in accumulator MOV R4,A ; move added result in r4 CLR A ; clear accumulator ADDC A,B ; add content of accumulator & b reg. with carry MOV R5,A ; result of addition store in r5 MOV A,R6 ; move data stored in r6 t0 accumulator MOV B,R3 ; move data from r3 to b reg. MUL AB ; R3*R6 ADD A,R4 ; addition of data content in accumulator & r4 reg. XCH A,R6 ; exchange data content in r6 & accumulator XCH A,B ; exchange content of accumulator & b reg. ADDC A,R5 ; addition of data content in r5 with accumulator MOV R5,A ; move accumulator data in r5 reg. MOV PSW.5,C ; save CY MOV A,R2 ; move content of r2 reg. in accumulator MUL AB ; R2*R6 ADD A,R5 ; addition of accumulator data with r5 reg. data MOV R5,A ; move accumulator data in r5 reg. CLR A ; clear accumulator
32

AMC-51 Advanced Microcontroller 8051 Trainer

MOV ACC.0,C MOV C,PSW.5 ADDC A,B ; addition of accumulator data with b reg. data with carry MOV R4,A ; move accumulator data in r4 reg. LOOP: SJMP LOOP END PROCEDURE: 1) Switch ON power supply. 2) Open respective program SW07.asm in 8051simulation system Software. 3) Press compile and load tab in the software. We can see the process window in the software at the left bottom corner. 4) Now go to Debug (D) in 8051simulation system software and press Step Over F6 command for single step execution. 5) Press F6 for further single step execution and see the parallel effect on Data store memory window. In code memory you can see the stored data on respective memory location. For memory location please refer program or to press this tab direct execution. 6) Before check the content ,you must stop the running program or Refresh the Data Store memory. OUTPUT: Observe result of multiplication 00000008 in R4R5R6R7.

EXPERIMENT NO-8 Multi-branch Program


OBJECTIVE: Write 00,01,02,03 in 20H grade, then run the program to observe the cycle in digital tube
33

AMC-51 Advanced Microcontroller 8051 Trainer

THEORY: To display data from 0 to 3 on display in scrolling mode, store one of data in 20h memory location. RLA instruction used to scroll same number on display. For 0 to 3 number , C0,F9,A4& B0are hex code used in program to display 0,1,2,3 respectively. CPLA used to blank display..

PROGRAM: ORG 0000H LJMP MEMORYS ORG 0080H MEMORYS: MOV P2,#0FFH ;initialize port 2 MOV A,#43H ;move 43 data in accumulator MOV DPTR,#0FF20H ;move ff20 address in DPTR pointer MOVX @DPTR,A ;move accumulator data in memory location pointed by DPTR MOV 20H,#01H ;you can change input 0 or 1 or 2 or 3 MOV A,20H ;move memory location 20h to accumulator MOV DPTR,#KKKK ;branch address RL A ;(20)*2 JMP @A+DPTR ;jump to address of accumulator content + DPTR KKKK: AJMP MEMORYSP0 AJMP MEMORYSP1 AJMP MEMORYSP2 SJMP MEMORYSP3 MEMORYSP0: MOV 20H,#0C0H ;move data c0h to memory location 20h LJMP SOX0 ;to display 0 MEMORYSP1: MOV 20H,#0F9H ;move data f9h to memory location 20h LJMP SOX0 ;to display 1 MEMORYSP2: MOV 20H,#0A4H ;move data a4h to memory location 20h LJMP SOX0 ;to display2 MEMORYSP3: MOV 20H,#0B0H ;move data 0bh to memory location 20h LJMP SOX0 ;to display 3 SOX0: MOV A,20H ;MOV R0,#22H ;MOV R1,#21H MOV DPTR,#0FF22H MOVX @DPTR,A ;MOVX @R0,A MOV A,#01H SOX1: CPL A MOV DPTR,#0FF21H MOVX @DPTR,A ;MOVX @R1,A CPL A MOV R2,#20H LCALL DELY RL A SJMP SOX1 ;Display routines

34

AMC-51 Advanced Microcontroller 8051 Trainer

DELY: DEL2: DEL3: DEL4:

PUSH 02H PUSH 02H PUSH 02H DJNZ R2,DEL4 POP 02H DJNZ R2,DEL3 POP 02H DJNZ R2,DEL2 POP 02H DJNZ R2,DELY RET END

PROCEDURE: 1) Switch ON power supply. 2) Open respective program SW07.asm in 8051simulation system Software. 3) Press compile and load tab in the software. We can see the process window in the software at the left bottom corner. 4) Now go to Debug (D) in 8051simulation system software and press Step Over F6 command for single step execution. 5) Press F6 for further single step execution and see the parallel effect on Data store memory window. In code memory you can see the stored data on respective memory location. For memory location please refer program or to press this tab direct execution. 6) Before check the content, you must stop the running program or Refresh the Data Store memory.

OUTPUT: Observe scrolling data on 7 segment display from 0 to 3 which is available in 20h memory location.

EXPERIMENT NO-9 Computer Clock (Timer, Interrupt Experiment)


OBJECTIVE: To study RTC & see time on seven segment display. THEORY: input current value of hour, minute, second from the keyboard. The timer 0 is selected to give time interval. The hex code loaded in timer is DBE6 to give 10ms
35

AMC-51 Advanced Microcontroller 8051 Trainer

time interval. Formula to calculate time interval is required time= (FFFF-XXYY+1) x cycle time where XXYY is hex code loaded in timer. Program ORG 0000H LJMP CHK0 ORG 000BH LJMP CLOCK ORG 0080H CHK0: MOV SP,#60H ;store 60h data in stack pointer MOV P2,#0FFH ;initialize port2 MOV 7EH,#11H ;move 11h data in 7eh MOV 7DH,#10H ;move 10h data in 7dh MOV 7CH,#10H ;move 10h data in 7ch MOV 7BH,#10H ;move 10h data in 7bh MOV 7AH,#10H ;move 10h data in 7ah MOV 79H,#10H ;move 10h data in 79h MOV A,#43H ;move 43h data in accumulator MOV DPTR,#0FF20H ;store ff20 address in DPTR MOVX @DPTR,A ;move data from accumulator to memory location pointed by DPTR ;MOV r0,#59h ;move 59h to r0 reg. MOV a,#7eh ;move 7eh data to accumulator MOVX @r0,a ;move data from accumulator to memory location MOV DPTR,#2059H ;store address 2059 in DPTR MOVX @DPTR,A ;move data from accumulator to memory location pointed by DPTR LCALL LCK0 LCALL PTDS0 MOV TMOD,#01H ;select timer ORL IE,#82H ;move 82h in i.e. reg. MOV TL0,#0E6H ;set timer time MOV TH0,#0DBH MOV 23H,#00H ;clear 23h memory location SETB TR0 ; set timer LOO5: LCALL SSEE LCALL PTDS0 SJMP LOO5 PTDS0:MOV R0,#79H ;move 79h data in r0 MOV A,22H ;move 22h in accumulator ACALL PTDS MOV A,21H ;move 21h to accumulator ACALL PTDS MOV A,20H ;move 20h to accumulator ACALL PTDS RET PTDS: MOV R1,A ;move accumulator to r1 reg. ACALL PTDS1 MOV A,R1 ;move r1 data to accumulator SWAP A ; exchange higher & lower bit saved in accumulator
36

AMC-51 Advanced Microcontroller 8051 Trainer

PTDS1:ANL A,#0FH MOV @R0,A

INC R0 RET CLOCK:MOV TL0,#0E6H ;set timer time MOV TH0,#0DBH PUSH PSW PUSH ACC SETB 0D3H INC 23H MOV A,23H ;move data stored in memory location CJNE A,#64H,DONE ;compare 64 with content of accumulator & jump if not equal to done loop MOV 23H,#00H MOV A,22H INC A DA A ; decimal adjustment of data stored in accumulator MOV 22H,A CJNE A,#60H,DONE MOV 22H,#00H MOV A,21H INC A DA A MOV 21H,A CJNE A,#60H,DONE MOV 21H,#00H MOV A,20H INC A DA A MOV 20H,A CJNE A,#24H,DONE MOV 20H,#00H DONE: POP ACC POP PSW RETI ORG 0D50H SSEE: SETB RS1 MOV R5,#05H SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H SSE1: ;MOV R1,#21H MOV A,30H CPL A ;MOVX @R1,A MOV DPTR,#0FF21H MOVX @DPTR,A MOV R0,31H MOV A,@R0 MOV DPTR,#DDFF
37

; anding 0fh data with content of accumulator ;move accumulator data in memory location pointed by r0 reg. ;increment data in r0

AMC-51 Advanced Microcontroller 8051 Trainer

MOVC A,@A+DPTR MOV R1,#22H ;MOVX @R1,A MOV DPTR,#0FF22H MOVX @DPTR,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH ;MOVX @R1,A MOV DPTR,#0FF22H MOVX @DPTR,A DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0CH,89H,0DEH ORG 1D00H X3: MOV R4,A ;MOV R0,#59H ;MOVX A,@R0 MOV DPTR,#2059H MOVX A,@DPTR MOV R1,A MOV A,R4 MOV @R1,A CLR A POP DPH POP DPL MOVC A,@A+DPTR INC DPTR CJNE A,01H,X30 CLR A MOVC A,@A+DPTR X31: ;MOVX @R0,A INC DPTR PUSH DPL PUSH DPH MOV DPTR,#2059H MOVX @DPTR,A RET X30: DEC R1 MOV A,R1 SJMP X31 X2: MOV R6,#50H X0: ACALL XLE JNB ACC.5,XX0 DJNZ R6,X0 MOV R6,#20H ;MOV R0,#59H
38

AMC-51 Advanced Microcontroller 8051 Trainer

;MOVX A,@R0 MOV DPTR,#2059H MOVX A,@DPTR MOV R0,A MOV A,@R0 MOV R7,A MOV A,#10H MOV @R0,A X1: ACALL XLE JNB ACC.5,XX1 DJNZ R6,X1 MOV A,R7 MOV @R0,A SJMP X2 XX1: MOV R6,A MOV A,R7 MOV @R0,A MOV A,R6 XX0: RET XLE: ACALL DIS ACALL KEY MOV R4,A ;MOV R1,#48H ;MOVX A,@R1 MOV DPTR,#2048H MOVX A,@DPTR MOV R2,A ;INC R1 ;MOVX A,@R1 MOV DPTR,#2049H MOVX A,@DPTR MOV R3,A MOV A,R4 XRL A,R3 MOV R3,04H MOV R4,02H JZ X10 MOV R2,#88H MOV R4,#88H X10: DEC R4 MOV A,R4 XRL A,#82H JZ X11 MOV A,R4 XRL A,#0EH JZ X11 MOV A,R4 ORL A,R4 JZ X12 MOV R4,#20H DEC R2 SJMP X13
39

AMC-51 Advanced Microcontroller 8051 Trainer

X12: x11:

MOV R4,#0FH MOV R2,04H MOV R4,03H X13: ;MOV R1,#48H MOV A,R2 ;MOVX @R1,A MOV DPTR,#2048H MOVX @DPTR,A ;INC R1 MOV A,R3 ;MOVX @R1,A MOV DPTR,#2049H MOVX @DPTR,A MOV A,R4 RET LS3: DB 07H,04H,08H,05H,09H,06H,0AH DB 0BH,01H,00H,02H,0FH,03H,0EH DB 0CH,0DH DIS: PUSH DPH PUSH DPL SETB RS1 MOV R0,#7EH MOV R2,#20H MOV R3,#00H ;MOV DPTR,#LS0 LS2: MOV DPTR,#LS0 MOV A,@R0 MOVC A,@A+DPTR ;MOV R1,#22H ;MOVX @R1,A MOV DPTR,#0FF22H MOVX @DPTR,A MOV A,R2 CPL A ;DEC R1 ;MOVX @R1,A MOV DPTR,#0FF21H MOVX @DPTR,A CPL A DEC R0 LS1: DJNZ R3,LS1 CLR C RRC A MOV R2,A JNZ LS2 ;INC R1 MOV A,#0FFH ;MOVX @R1,A MOV DPTR,#0FF22H MOVX @DPTR,A CLR RS1 POP DPL
40

AMC-51 Advanced Microcontroller 8051 Trainer

POP DPH RET LS0: DB 0C0H,0F9H,0A4H,0B0H,99H,92H DB 82H,0F8H,80H,90H,88H,83H,0C6H DB 0A1H,86H,8EH,0FFH,0CH,89H,7FH,0BFH KEY: SETB RS1 MOV R2,#0FEH MOV R3,#08H MOV R0,#00H LP1: MOV A,R2 ;MOV R1,#21H ;MOVX @R1,A MOV DPTR,#0FF21H MOVX @DPTR,A RL A MOV R2,A ;MOV R1,#23H ;MOVX A,@R1 MOV DPTR,#0FF23H MOVX A,@DPTR CPL A ANL A,#0FH JNZ LP0 INC R0 DJNZ R3,LP1 ;MOVX A,@R1 MOV DPTR,#0FF23H MOVX A,@DPTR JB ACC.4,XP33 MOV A,#19H SJMP XP3 XP33: MOV A,#20H XP3: CLR RS1 RET LP0: CPL A JB ACC.0,XP0 MOV A,#00H SJMP LPP XP0: JB ACC.1,XP1 MOV A,#08H SJMP LPP XP1: JB ACC.2,XP2 MOV A,#10H SJMP LPP XP2: JB ACC.3,XP33 MOV A,#18H LPP: ADD A,R0 CLR RS1 CJNE A,#10H,LX0 LX0: JNC XP35 MOV DPTR,#LS3 MOVC A,@A+DPTR
41

AMC-51 Advanced Microcontroller 8051 Trainer

XP35: RET LCK0: LCALL X2 JNC LCK1 LCALL X3 MOV R1,#7EH SJMP LCK0 LCK1: CJNE A,#16H,LCK0 MOV A,7AH SWAP A ORL A,79H MOV 22H,A location CJNE A,#60H,LCK2 LCK2: JNC EXIT MOV A,7CH SWAP A ORL A,7BH MOV 21H,A CJNE A,#60H,CLK3 CLK3: JNC EXIT MOV A,7EH SWAP A ORL A,7DH MOV 20H,A CJNE A,#24H,CLK4 CLK4: JNC EXIT RET EXIT: AJMP LCK0 END ; move data from 7ch memory location to accumulator ; exchange higher & lower bit data store in accumulator ; oring with data stored in 7bh & accumulator ; move data from accumulator to 21h memory location ;move data from 7eh memory location to accumulator ; exchange higher & lower bit data store in accumulator ; oring with data stored in 7dh & accumulator ; move data from accumulator to 20h memory location ; if hours are not equal to 24 then jump to clk4 loop

; move data from 7ah memory location to accumulator ; exchange higher & lower bit data store in accumulator ; ORing with data stored in 79h & accumulator ; move data from accumulator to 22h memory

PROCEDURE: 1) Switch ON power supply. 2) Open respective program SW07.asm in 8051simulation system Software. 3) write current value of hour , minute & second in program 3) Press compile and load tab in the software. We can see the process window in the software at the left bottom corner. 4) Now go to Debug (D) in 8051simulation system software and press Step Over F6 command for single step execution. 5) Press F6 for further single step execution and see the parallel effect on Data store memory window. In code memory you can see the stored data on respective memory location. For memory location please refer program or to
42

AMC-51 Advanced Microcontroller 8051 Trainer

press this tab direct execution. 6) Before check the content , you must stop the running program or Refresh the Data Store memory. OUTPUT: 7 segment display shows hour, minute & second .

EXPERIMENT NO-10 Impulse Count(Timing/Counter Experiment)


43

AMC-51 Advanced Microcontroller 8051 Trainer

OBJECTIVE: Count the impulse outside the timing 0 ,then send to display.

Experiment Steps Connect 8MHZ and T jack , connect T0 to T7 or single-impulse output hole one by one, run the program, to observe the number and speed of counter impulse in digital tube

OUTPUT: As a assignment for student. Program

ORG 0000H LJMP SE15 ORG 080H SE15: MOV SP,#53H MOV P2,#0FFH MOV A,#43H MOV DPTR,#0FF20H MOVX @DPTR,A pointed by DPTR MOV TMOD,#05H MOV TH0,#00H MOV TL0,#00H SETB TR0 LO29: MOV R2,TH0 MOV R3,TL0 LCALL ZOY0 MOV R0,#79H MOV A,R6 LCALL PTDS MOV A,R5 LCALL PTDS MOV A,R4 LCALL PTDS LCALL SSEE SJMP LO29 ZOY0: CLR A MOV R4,A MOV R5,A MOV R6,A MOV R7,#10H LO30: CLR C MOV A,R3

; ; ; ; ;

store 53h data in stack pointer initialize port2 move 43h data in accumulator move address ff20 in DPTR store data from accumulator to memory location

; select counter 0 ; initialize counter ; set counter ; move timer time data in r2 & r3 ; move 79 data in r0 reg. ; move data from r6 reg. to accumulator

; clear all accumulator ,r4,r5 & r6

44

AMC-51 Advanced Microcontroller 8051 Trainer

RLC A MOV R3,A MOV A,R2 RLC A MOV R2,A MOV A,R6 ADDC A,R6 DA A MOV R6,A MOV A,R5 ADDC A,R5 DA A MOV R5,A MOV A,R4 ADDC A,R4 DA A MOV R4,A DJNZ R7,LO30 RET PTDS: MOV R1,A CALL PTDS1 MOV A,R1 SWAP A PTDS1:ANL A,#0FH MOV @R0,A INC R0 RET SSEE: SETB RS1 MOV R5,#05H SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H SSE1: ;MOV R1,#21H MOV A,30H CPL A ;MOVX @R1,A MOV DPTR,#0FF21H MOVX @DPTR,A MOV R0,31H MOV A,@R0 MOV DPTR,#DDFF MOVC A,@A+DPTR ;MOV R1,#22H ;MOVX @R1,A MOV DPTR,#0FF22H MOVX @DPTR,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH ;MOVX @R1,A MOV DPTR,#0FF22H MOVX @DPTR,A

; rotate left with carry content data of accumulator

45

AMC-51 Advanced Microcontroller 8051 Trainer

DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0CH,89H,0DEH END

46

AMC-51 Advanced Microcontroller 8051 Trainer

Hardware Experiments

47

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 1 Light P1 Port Experiment


OBJECTIVE: To define port1 as output port using LED indication. CIRCUIT DISCRIPTION: P1 port is a bidirectional port. When 1s are written to port1 pins, the pins can be used as input pins. When 0s are written to port1 pins,port1act as output port. LEDs are connected to each pin of port1 in common anode configuration. LEDs are connected to port 1 pins through buffer IC 74LS245 transreceiver. As shown in circuit diagram 74LS245 consist of A0 to A7 as input port, B0 to B7 as output ports. By using pin, the input pins can be enable or disable. Dir pin used to select direction of data flow. Here Connect DIR pin to +5V to select A0 to A7 as input & B0 to B7 as output pins & connected to gnd to enable input pins. CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect LED OUTPUT UNIT L1~L8( 8-pin connector) to DECODER SECTION 8-pin JP1 using 8 pin ribbon cable b) Switch ON power supply. 2) Run program:a) Open respective program LED.ASM in 8051 simulation system software. Press compile and load button in the software. Watch the save message window is displayed. Conform the path where the program supported file was stored and press the YES button.
b)
48

AMC-51 Advanced Microcontroller 8051 Trainer

c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can press GO button execution. PROGRAM: //program to glow led in rotating pattern// ORG 0000H LJMP SE18 ORG 0790H SE18: MOV P1,#0FFH LO34: MOV A,#0FEH LO33: MOV P1,A LCALL SE19 RL A SJMP LO33 ORG 07A0H SE19: MOV R6,#0A0H LO36: MOV R7,#0FFH LO35: DJNZ R7,LO35 DJNZ R6,LO36 RET END Output: Press GO button to L8. and observe LEDs (L1 to L8) glows in specified manner from L1 ; for delay ; subroutine call for delay ; rotating left data stored in accumulator ; for continuous looping ; initialize port1 ; move data 0fe to the p1 for program execution. Use Stop button to stop the

Assignment:
49

AMC-51 Advanced Microcontroller 8051 Trainer

1.Try the same program by changing delay time. 2. do some changes in program to change rotating direction of led glowing .

50

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 2 P1 Port Turn Light Experiment


OBJECTIVE: T0 define port 1 as input port & output port CIRCUIT DISCRIPTION: P1.0 & P1.1 Pins of port1 configured as input pins & P1.4,P1.5, P1.6 & P1.7 pins are configured as output port. The input pins are connected to either GND or VCC through switches. The output pins are connected to LEDs through a buffer IC 74LS245. All LEDs are Connected in common anode configuration .When output pin is high , corresponding Led glows. CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect SWITCH INPUT UNITK1 jack to DECODER SECTION-P1.1jack using patch cord. b) Connect SWITCH INPUT UNITK2 jack to DECODER SECTION-P1.0 jack using patch cord. c) Connect LED OUTPUT UNITL1 jack to DECODER SECTION-P1.4 jack using patch cord. d) Connect LED OUTPUT UNITL2 jack to DECODER SECTION-P1.5 jack using patch cord. e) Connect LED OUTPUT UNITL3 jack to DECODER SECTION-P1.6 jack using patch cord. f) Connect LED OUTPUT UNITL4 jack to DECODER SECTION-P1.7 jack using patch cord. g) Switch ON power supply.
51

AMC-51 Advanced Microcontroller 8051 Trainer

2) Run program:a) Open respective program 2switch.ASM in 8051 simulation system software. Press compile and load button in the software. We can see the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can
b)

press GO button execution. PROGRAM:

for program execution. Use Stop button

to stop the

//program for p1 port to turn light// ORG 0000H LJMP PX00 ORG 0C30H PX00: MOV P1,#0FFH ; make port 1 high PX03: MOV A,P1 ; load data FFH to accumulator MOV B,A ; move data to b reg. ANL A,#03H ; define P1.0 & p1.1 as input & others as output CJNE A,#01H,PX01 ; when p1.0 is high , port 1.6 & p1.7 set ,or jump to Px01 JB 00H,PX04 ; jump if set bit 00h to pxo4 loop CLR P1.4 ; clear pi.4 bit CLR P1.5 ; clear p1.5 SETB P1.6 ; set bit p1.6 SETB P1.7 ; set bit p1.7 MOV R2,#20H ; move data 20h to r2 reg. LCALL DELY SETB 00H ; set bit 00h LJMP PX03 PX04: SETB P1.4 ; set bit of p1.4,p1.5,p1.6,p1.7 SETB P1.5 SETB P1.6 SETB P1.7 MOV R2,#20H LCALL DELY CLR 00H ; clear bit 00h AJMP PX03 PX01: CJNE A,#02H,PX02 ; if P1.1 is high,p1.4 &p1.5 are set or jump to px02 JB 01H,PX05 ; jump if 01h set to px05 loop SETB P1.4 ; set bit p1.4 SETB P1.5 ; set bit p1.5 CLR P1.6 ; clear bit p1.6 CLR P1.7 ; clear bit p1.7 MOV R2,#20H LCALL DELY SETB 01H LJMP PX03
52

AMC-51 Advanced Microcontroller 8051 Trainer

PX05: SETB P1.4 SETB P1.5 SETB P1.6 SETB P1.7 MOV R2,#20H LCALL DELY CLR 01H LJMP PX03 PX02: SETB P1.4 SETB P1.5 SETB P1.6 SETB P1.7 LJMP PX03 DELY: PUSH 02H DEL2: PUSH 02H DEL3: PUSH 02H DEL4: DJNZ R2,DEL4 POP 02H DJNZ R2,DEL3 POP 02H DJNZ R2,DEL2 POP 02H DJNZ R2,DELY RET END Output: -

; set bit p1.4,p1.5,p1.6,p1.7

; clear bit

; decrement data of r2 reg. jump if not zero to del3 loop

Press GO button and observe LED L1 and L2 glows when switch K1 is at high state. LED 3 and LED4 glows when switch K2 is at high state. All LEDs are OFF when both switch K1 and K2 are either at Low or at High. Assignment: write program by increasing output pins P1.2 & P1.3.

53

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 3 P3.3 Port Input, P1 Port Output


OBJECTIVE: By using one switch ,we can glow led in 16 condition of hex code manner(i.e.00000000 to 11111111). CIRCUIT DISCRIPTION: P3.3 pin of port 3 configured as input pin. This pin connected to VCC or GND through a switch. All pins of port1 configured as output ports. LEDs are connected to output port in a common mode configuration through buffer. CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect SWITCH INPUT UNITK1 jack to DECODER SECTION-P3.3 jack using patch cord. b) Connect LED OUTPUT UNIT L1~L8( 8-pin connector) to DECODER SECTION 8-pin JP1 using 8 pin ribbon cable. Switch ON power supply. 2) Run program:a) Open respective program hex_out.ASM in 8051 simulation system software. Press compile and load button in the software. We can see the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can
b)
54

AMC-51 Advanced Microcontroller 8051 Trainer

press GO button execution. PROGRAM:

for program execution. Use Stop button

to stop the

//program for using p3.3 as input port & p1 as output port // ORG 0000H LJMP J100 ORG 0100H J100: MOV A,#00H ; clear content of accumulator J101: JB P3.3,J101 ; jump if p3.3 is set MOV R2,#10H ; move data 10h to r2 reg. LCALL DELY JB P3.3,J101 J102: JNB P3.3,J102 ; jump if p3.3 is no bit MOV R2,#10H LCALL DELY JNB P3.3,J102 INC A ; data in accumulator incremented by 1 PUSH ACC CPL A ; complement data of accumulator MOV P1,A ; move data stored in accumulator in port 1 POP ACC AJMP J101 DELY: PUSH 02H ; for creating delay DEL2: PUSH 02H DEL3: PUSH 02H DEL4: DJNZ R2,DEL4 ; decrement & jump if not zero to DEL4 loop POP 02H DJNZ R2,DEL3 POP 02H DJNZ R2,DEL2 POP 02H DJNZ R2,DELY RET END

Output: Press GO button and observe all LEDs are at OFF position. When you toggle K1 (make K1switch low to high) then LED (L1 to L8) will Glows in 15 condition of hex code manner(i.e.00000000 to 11111111). ASSIGNMENT: 1.Modify program, to glow LED in a complement of hex code manner.

Experiment 4
55

AMC-51 Advanced Microcontroller 8051 Trainer

Industry Sequence Control


OBJECTIVE: To define the industry sequence control using interrupt CIRCUIT DISCRIPTION: Port1 configured as output port and port 3 configured as input port.P3.3 & P3.4 connected to VCC or GND through switch. LEDs are connected to port1 through buffer IC 74ls245. All LEDs are common anode configured. Buzzer connected to p1.7 pin through LM386. IC LM386 is a low voltage audio power amplifier. CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect SWITCH INPUT UNITK1 jack to DECODER SECTION-P3.3 jack using patch cord. b) Connect SWITCH INPUT UNITK2 jack to DECODER SECTION-P3.4 jack using patch cord. c) Connect LED OUTPUT UNITL1 jack to DECODER SECTION-P1.0 jack using patch cord. d) Connect LED OUTPUT UNITL2 jack to DECODER SECTION-P1.1 jack using patch cord. e) Connect LED OUTPUT UNITL3 jack to DECODER SECTION-P1.2 jack using patch cord. f) Connect LED OUTPUT UNITL4 jack to DECODER SECTION-P1.3 jack using patch cord.

56

AMC-51 Advanced Microcontroller 8051 Trainer

Connect LED OUTPUT UNITL5 jack to DECODER SECTION-P1.4 jack using patch cord. h) Connect LED OUTPUT UNITL6 jack to DECODER SECTION-P1.5 jack using patch cord. i) Connect LED OUTPUT UNITL7 jack to DECODER SECTION-P1.6 jack using patch cord. j) Connect AUDIO AMPLIFIER UNITVIN jack to DECODER SECTION-P1.7 jack using patch cord. k) AUDIO AMPLIFIER UNIT Short 5V to ON position using shorting jumper link. l) Switch ON power supply.
g)

2)
a) b)

Run program:Open respective program control.ASM in 8051 simulation system software.

Press compile and load button in the software. We can see the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can press GO button execution. for program execution. Use Stop button to stop the

c) When K1 toggle (external interrupt = high to low) then LED starts glowing from where they stopped. PROGRAM: //program for industry sequence control// ORG 0000H LJMP PO10 ORG 0013H LJMP PO16 ORG 0190H PO10: MOV P1,#7FH ; port 1 as output port ORL P3,#00H ; initialize port 3 PO11: JNB P3.4,PO11 ; jump if p3.4 not set bit ORL IE,#84H ; set EA & ET1 ORL IP,#04H ; set IP with data 04h MOV PSW,#00H ; clear PSW MOV SP,#53H ; store data 53h in stack PO12: MOV P1,#7EH ; move data 7eh to p1 ACALL PO1B MOV P1,#7DH ; load data 7dh to p1 ACALL PO1B MOV P1,#7BH ; load data 7bh to p1 ACALL PO1B MOV P1,#77H ; load data 77h to p1 ACALL PO1B MOV P1,#6FH ; load data 6fh to p1 ACALL PO1B
57

AMC-51 Advanced Microcontroller 8051 Trainer

MOV P1,#5FH ; load data 5fh to p1 ACALL PO1B MOV P1,#0FH ; load data 0fh to p1 ACALL PO1B SJMP PO12 PO16: MOV B,R2 ; move data stored in r2 to b erg PO17: MOV P1,#7FH ; load data 7fh to p1 MOV 20H,#0A0H ; move data 0A0h to memory loc. 20h PO18: SETB P1.7 ; set bit p1.7 ACALL PO1A CLR P1.7 ; clear p1.7 ACALL PO1A DJNZ 20H,PO18 ; decrement data of memory loc. 20h ,jump if not zero to p018 CLR P1.7 ; clear p1.7 ACALL PO1A JNB P3.3,PO17 ; jump if p3.3 not bit to p017 loop MOV R2,B ; move content of b reg. to r2 reg. RETI PO19: MOV R2,#10H ; move data 10h to r2 reg. ACALL DELY RET PO1A: MOV R2,#06H ; move data 06h to r2 reg. ACALL DELY RET PO1B: MOV R2,#30H ; move data 30h to r2 reg. ACALL DELY RET DELY: PUSH 02H DEL2: PUSH 02H DEL3: PUSH 02H DEL4: DJNZ R2,DEL4 POP 02H DJNZ R2,DEL3 POP 02H DJNZ R2,DEL2 POP 02H DJNZ R2,DELY RET END OUTPUT: a) Press GO button & observe all LEDs are at OFF position. When you toggle K2 (make K2switch low to high) then all LEDs (L1 to L7) will start glowing in specified manner. b) When K1 toggle (external interrupt = low to high) then LED stops glowing and system alerts using beep sound. ; to create delay time

58

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 5 8255A.B.C Port Output Square Wave

OBJECTIVE: To define use of 8255 programmable I/O interface chip. CIRCUIT DISCRIPTION: The 8255 is a widely used , programmable , parallel I/O device. 8255 has 24 I/O pins that can be grouped primarily in two 8 bit s of port C. The 8 bits of port c can be used as individual bits or be grouped in two 4 bit ports as C-upper & C-lower. The function of these ports are defined by writing a control word in control register. The control pins are /RD(read) /WR(write) RESET /CS,A0 & A1 : : : : to read data from selected I/O ports of 8255A Processor writes into selected I/O port or control register. It clears control register & sets all ports in input mode these are device select signals. /CS is connected to a decoded address & A0 & A1 are generally connected to MPU address line, address line.A0 & A1 respectively

CONTROL WORD :The content of control register ,called control word. Specify an I/O function for each port. This register can be accessed to write control word when A0 & A1 at logic 1.The register is not accessible for read operation. CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Internal connections are done. So no connections are required. b) Switch ON power supply.

59

AMC-51 Advanced Microcontroller 8051 Trainer

2)

Run program:a) Open respective program 8255_sq.ASM in 8051 simulation system software. Press compile and load button in the software. We can see the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can
b)

press GO button execution.

for program execution. Use Stop button

to stop the

PROGRAM: ORG 0000H LJMP SE09 ORG 0580H SE09: MOV DPTR,#0FF2BH ; SELECT CONTROL REGISTER ADDRESS MOV A,#80H ; ALL PORTS AS OUTPUT MOVX @DPTR,A ; LOAD VALUE TO CONTROL REGISTER MOV A,#55H ; STORE 55H DATA TO ACCUMULATOR LO15: MOV DPTR,#0FF28H ; SELECT PORTA ADDRESS MOVX @DPTR,A ; LOAD DATA FROM ACCUMULATOR TO PORT A INC DPTR ; SELECT PORTB ADDRESS MOVX @DPTR,A ; LOAD SAME DATA ON PORTB INC DPTR ; SELECT PORTC ADDRESS MOVX @DPTR,A ; LOAD SAME DATA ON PORTC MOV R2,#10H ; LOAD COUNT FOR CREATING DELAY LCALL DELY CPL A ; COMPLEMENT CONTENT OF ACCUMULATOR DATA SJMP LO15 ; J UMP TO LOOP ORG 05A0H DELY: PUSH 02H DEL2: PUSH 02H DEL3: PUSH 02H DEL4: DJNZ R2,DEL4 POP 02H DJNZ R2,DEL3 POP 02H DJNZ R2,DEL2 POP 02H DJNZ R2,DELY RET END OUTPUT: Press GO button & observe the Square wave at any port pin of 8255 UNIT on
60

; LOOP FOR DELAY

AMC-51 Advanced Microcontroller 8051 Trainer

the CRO..

Experiment 6 8255 PA Port Control PB Port


OBJECTIVE: To define port A of 8255 as input port & port B as output port CIRCUIT DISCRIPTION: The 8255 is a widely used , programmable , parallel I/O device8255 has 24 I/O pins that can be grouped primarily in two 8 bit s of port C. The 8 bits of port c can be used as individual bits or be grouped in two 4 bit ports as C-upper & C-lower. The function of these ports are defined by writing a control word in control register .The control pins are /RD(read) : to read data from selected I/O ports of 8255A /WR(write) ;microcontroller writes into selected I/O port or control register. RESET :It clears control register & sets all ports in input mode /CS,A0 & A1 :these are device select signals. /CS to a decoded is connected address & A0 & A1 are generally connected to MCU respectively. CONTROL WORD :The content of control register ,called control word . Specify an I/O function for each port .This register can be access data .Write control word when A0 & A1 at logic 1.The register is not accessible for read operation. In 8255 port A is input port connected to VCC or GND through switch .LEDs connected to output port B through buffer. All LEDs are common anode configured . For interfacing of 8255 hardware configuration is as shown in fig below. chip select pin used to select chip. CIRCUIT DIAGRAM::

PROCEDURE: 1) Connections: a) Connect LED OUTPUT UNIT-L1~L8 (8-pin connector) to 8255 UNIT 8-pin JX15 (port B) using 8 pin ribbon cable. (Note: - Make sure LSB or PX.0 of source connector should connect to LSB or 0th bit of destination Connector, where PX = any port). b) Connect SWITCH INPUT UNIT-K1~K8 (8-pin connector) to 8255 UNIT 8-pin JX9 (port A) using 8 pin ribbon cable. (Note: - Make sure LSB or PX.0 of source
61

AMC-51 Advanced Microcontroller 8051 Trainer

connector should connect to LSB or 0th bit of destination Connector, where PX = any port). c) Switch ON power supply. 2)
a) b)

Run program: Open respective program IO.ASM in 8051 simulation system software.

Press compile and load button in the software. We can see the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can press GO button execution. for program execution. Use Stop button to stop the

PROGRAM: org 0000h LJMP SE17 ORG 0770H SE17: MOV DPTR,#0FF2BH ; SELECT CONTROL REG ADDRESS MOV A,#90H ; port A AS INPUT & PORT b AS OUTPUT MOVX @DPTR,A ; MOV DATA TO CONTROL REG. LO32: MOV DPTR,#0FF28H ; SELECT ADDRESS OF PORT A MOVX A,@DPTR ; MOV DATA FROM PORT A TO ACCUMULATOR INC DPTR ; SELECT PORT B MOVX @DPTR,A ; LOAD DATA FROM ACCUMULATOR TO PORT B SJMP LO32 END OUTPUT: Press GO button & observe as you toggle K1 to K8 switches the respective LEDs L1 to L8 are make either ON or OFF. When switch is high then respective LED is OFF and when switch is low then respective LED is ON.

62

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 7 8255 Control Traffic Light


OBJECTIVE: To define port1 to control of traffic light CIRCUIT DISCRIPTION: Traffic light controller interface module is designed to simulate the function of two way traffic light controller. Combinations of red, amber and green LEDs are provided to indicate Halt, Wait and Go signals for vehicles. Combination of red and green LEDs are provided for pedestrian crossing. 3 LEDs group are arranged in to control the traffic of East & West. LED L3& L7 (Red) are for the stop signal for the vehicles on the road W & E respectively. L1& L5 (Amber) indicates wait state for vehicles on the road W & E respectively. L2 & L6 (Green) are for left and right turn for the vehicles on road S. 2 red & 2 Green at both side are provided for pedestrian crossing. L2 &L6 (Green) when on allows pedestrians to cross and L7, L3 (Red) . 8255 is interfaced with 8051 in I/O mapped I/O and all ports are output ports. The basic operation of the interface is explained with the help of the enclosed program. At the beginning of the program all red LEDs are switch ON, and all other LEDs are switched OFF. Amber LED is switched ON before switching over to proceed state from Halt state. The sequence of traffic followed in the program is given below. . CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect LED OUTPUT UNITL1 jack to 8255 UNIT-PA2 jack using patch cord. b) Connect LED OUTPUT UNITL2 jack to 8255 UNIT-PA1 jack using patch cord. c) Connect LED OUTPUT UNITL3 jack to 8255 UNIT-PA0 jack using patch cord. d) Connect LED OUTPUT UNITL5 jack to 8255 UNIT-PA5 jack using patch cord. e) Connect LED OUTPUT UNITL6 jack to 8255 UNIT-PA4 jack using patch cord. f) Connect LED OUTPUT UNITL7 jack to 8255 UNIT-PA3 jack using patch cord. g) Switch ON power supply.
63

AMC-51 Advanced Microcontroller 8051 Trainer

2)
a) b)

Run program:Open respective program traffic.ASM in 8051 simulation system software.

Press compile and load button in the software. We can see the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can press GO button execution. PROGRAM: ORG 0000H LJMP JOD0 ORG 0BB0H JOD0: MOV SP,#60H MOV DPTR,#0FF2BH MOV A,#88H MOVX @DPTR,A MOV DPTR,#0FF28H MOV A,#0B6H MOVX @DPTR,A for program execution. Use Stop button to stop the

INC DPTR MOV A,#0DH MOVX @DPTR,A MOV R2,#25H ; STORE COUNT NO IN R2 TO CREAT DELAY LCALL DELY JOD3: MOV DPTR,#0FF28H ; SELECT PORTA ADDRESS MOV A,#75H ; LOAD 75H DATA TO PORT A MOVX @DPTR,A INC DPTR ; SELECT PORTB MOV A,#0DH ; LOAD 0DH DATA TO PORT B MOVX @DPTR,A MOV R2,#55H ; LOAD 55 TO R2 TO CREAT ANOTHER DELAY LCALL DELY ; CALL DELY MOV R7,#05H ; MOV 05H DATA TO R7 JOD1: MOV DPTR,#0FF28H ; LOAD F3H DATA ON PORT A MOV A,#0F3H MOVX @DPTR,A INC DPTR ; LOAD 0CH DATA ON PORT B MOV A,#0CH MOVX @DPTR,A MOV R2,#20H ; LOAD 20H TO R2 TO CREAT NEW DELAY LCALL DELY ; CALL DELAY MOV DPTR,#0FF28H ; LOAD F7H DATA TO PORT A
64

; SELECT CONTROL REGISTER ADDRESS ; SELECT ALL PORT AS OUTPUT ; LOAD DATA TO CONTROL REGISTER ; SELECT PORT A ADDRESS ; STORE B6H DATA TO ACCUMULATOR ; LOAD THIS ACCUMULATOR DATA TO PORTA ; SELECT PORT B ADDRESS ; LOAD 0dH DATA TO PORTB

AMC-51 Advanced Microcontroller 8051 Trainer

MOV A,#0F7H MOVX @DPTR,A INC DPTR ; LOAD 0DH DATA ON PORTB MOV A,#0DH MOVX @DPTR,A MOV R2,#20H LCALL DELY ; CALL DELAY DJNZ R7,JOD1 ; DECREMENT R7 & JUMP IF ZERO TO LOOP MOV DPTR,#0FF28H ; LOAD DATA 0AEH DATA TO PORT A MOV A,#0AEH MOVX @DPTR,A INC DPTR ; LOAD 0BH DATA TO PORT B MOV A,#0BH MOVX @DPTR,A MOV R2,#55H LCALL DELY ; CALL DELAY MOV R7,#05H ; LOAD 05H DATA TO R7 REG JOD2: MOV DPTR,#0FF28H ; LOAD 9EH DATA ON PORT A MOV A,#9EH MOVX @DPTR,A INC DPTR MOV A,#07H MOVX @DPTR,A ; LOAD 07H DATA TO ACCUMULATOR MOV R2,#20H LCALL DELY ; CALL DELAY MOV DPTR,#0FF28H MOV A,#0BEH ; LOAD 0BE ON PORT A MOVX @DPTR,A INC DPTR MOV A,#0FH ; LOAD 0FH DATA ON PORT B MOVX @DPTR,A MOV R2,#20H LCALL DELY ; CALL DALAY DJNZ R7,JOD2 LJMP JOD3 ORG 0C30H DELY: PUSH 02H DEL2: PUSH 02H DEL3: PUSH 02H DEL4: DJNZ R2,DEL4 POP 02H DJNZ R2,DEL3 POP 02H DJNZ R2,DEL2 POP 02H DJNZ R2,DELY RET END ; LOOP FOR DELAY

65

AMC-51 Advanced Microcontroller 8051 Trainer

OUTPUT: a) Output shows the demonstration of traffic light control signal. First right Red LED is ON and left Green LED is ON. After some time left Green is OFF, left Yellow start blinking. At this time right Red LED is ON. Left yellow blinking is stop then Left Red is ON, Right Red is OFF and Right Green is ON. Stages from 1 to 3 are repetitive process.

66

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 8 Simple I/O Expansion Experiment


OBJECTIVE: To study the simple I/O expansion method in microcontroller system. CIRCUIT DISCRIPTION: Decoder normally used to enable one of memory devices in system .I /o devices are connected to the microcontroller through decoders. The address of memory location or I /O device is sent out by controller.The relevant memory chip of I/O devices selected by decoder .The decoder 74ls138 has 3 enable pins G1,G2A & G2B. Chip enabled when G1 high and G2A ,G2B are low . A,B&C are select lines When A,B & C are 000,Y0 is selected . The address ,data and control bus lines from microcontroller need to be buffered to prepare them to be connected to many components in system. Further 8051 microcontroller multiplexes address , data & status signals on AD15 to AD0 andA19/S6A16/S3 lines. It outputs address in T1 state of bus cycle and changes to data & status during remaining period of bus cycle .address on address bus should be stable through out a memory or i/o access bus cycle to enable the memory or I/O devices for data transfer .Hence address & data must be demultiplexed . An octal latch has 8 D-latches and 8 tri state buffers. The 74LS173 octal latch has two control inputs Enable(G) & Output Control. The enable control is active high & is connected to CLK inputs of all 8 latches .Logic 1 in clock input will store logic level present at d inputs in respective latches .The output control signal is active low & is connected to control inputs of all 8 tri state buffers. Logic 0 will enable buffers to output data from respective latches. The ALE signal in TI state of a bus cycle .The ale signal enables three octal latches U3,U4 & U5 to capture 20 bit address & store it at its output .The latches provide stable A19 A0 bits of address of through out a bus cycle . It leaves A15 A0 lines for data bus action after TI state . The 8051 data transmit/receive DT/R and data enable signals to enable data bus buffering system for data bus action on AD15-AD0 lines . The signals enables two transreceivers74ls245.74ls245 provides buffered & separated data bus . The buffer 74ls244 buffers control signals , M/IO,WR,RD & DECODER74LS138 CIRCUIT DIAGRAM:

PROCEDURE:
67

AMC-51 Advanced Microcontroller 8051 Trainer

1) Connections:a) Connect I/O EXPANSION UNITCS1 jack to DECODER SECTION-8000H jack using patch cord. b) Connect I/O EXPANSION UNITCS2 jack to DECODER SECTION-9000H jack using patch cord. c) Connect LED OUTPUT UNIT L1~L8 8-pin connector to I/O EXPANSION UNIT Q0~Q7 8-pin connector using 8 pin ribbon cable. (Note: - Make sure LSB or PX.0 of source connector should connect to LSB or 0th bit of destination Connector, where PX = any port). D)Connect SWITCH INPUT UNIT K1~K8 8-pin connector to I/O EXPANSION UNIT Y0~Y7 8-pin connector using 8 pin ribbon cable. (Note: - Make sure LSB or PX.0 of source connector should connect to LSB or 0th bit of destination Connector, where PX = any port). E)Connect JX7 pin connector of I/O EXPANSION UNIT to JX0 pin connector of . DECODER SECTION F) Switch ON power supply. 2) Run program:a) Open respective program IO_EXP.ASM or in 8051 simulation system software. Press compile and load button in the software. We can see the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can
b)

press GO button execution.

for program execution. Use Stop button

to stop the

PROGRAM: ORG 0000H LJMP GOD0 ORG 0B80H GOD0: MOV DPTR,#8000H MOVX A,@DPTR MOV DPTR,#9000H MOVX @DPTR,A SJMP GOD0 END OUTPUT:

; data from switch transfer to accumulator ; data from accumulator transferring to glow led ; jump to loop

Press GO button & observe as you toggle K1 to K8 switches the respective LEDs L1 to L8 are make either ON or OFF. When switch is high then respective LED is OFF and when switch is low then respective LED is ON.

68

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 9 Analog to Digital Conversion Experiment


OBJECTIVE: To study Analog to digital conversion using ADC 0809 IC with microcontroller. CIRCUIT DISCRIPTION: Most transducers and sensors such as temperature ,pressure ,velocity ,humidity are analog. Therefore 8051 used ADCs to convert analog signals in to digital. three Address pins A,B &C are grounded to select IN0 as input .A trimmer is connected between +5V and Gnd to provide variable dc VOLTAGE AS INPUT TO ADC , For 5V output is FF & for 0V output is 00 . ADC resolution is 8 bit . CLK IN is an input pin connected to an external clock source , an external clock is used for timing. To calculate data out use below formula Dout = Vin / Step Size for input voltage. of 2.56 volts ( Vref =1.28 volts) and step size of 10mv Dout =2560/10 =256 or FF that is full scale output. ADC808/809 Chip has 8 analog channel, this means this kind of chip allows to monitor 8 different transducers. ALE: Latch in the address Start : Start of conversion OE: output enable EOC: End of Conversion

69

AMC-51 Advanced Microcontroller 8051 Trainer

Channel IN0 IN1 IN2 IN3 IN4 IN5 IN6 IN7

CBA 000 001 010 011 100 101 110 111

CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections: a) Connect Adjustable Voltage Unit VIN jack to IN-BUILD POWER +5V jack using patch cord. b) Connect Adjustable Voltage Unit VOUT jack to ADC0809 UNIT IN0 jack using patch cord. c) Connect ADC0809 UNIT WR jack to DECODER SECTION IOWR jack using patch cord. d) Connect ADC0809 UNIT RD jack to DECODER SECTION IORD jack using patch cord. e) Connect ADC0809 UNIT CLK jack to MONOPULSE AND CLOCK UNIT- 500K jack using patch cord. f) Connect ADC0809 UNIT CS4 jack to DECODER SECTION 8000H jack using patch cord.

70

AMC-51 Advanced Microcontroller 8051 Trainer

g) Connect ADC0809 UNIT ADDA, ADDB and ADDC jacks to IN-BUILD POWER GND jack using patch cord e) Connect ADC0809 UNIT 8-pin JX6 connector to DECODER SECTION 8-pin JX0 using 8 pin ribbon cable. (Note: - Make sure LSB or PX.0 of source connector should connect to LSB or 0 th bit of destination Connector, where PX = any port). h) Switch ON power supply.
2)

a)
b)

Run program: Open respective program ADC.ASM in 8051 simulation system software.

Press compile and load button in the software. We can see the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can press GO button for program execution. Use Stop button to stop the execution. e) 6 digit 7-segment display shows 0809 ---XX on the display. Where XX varies from 00FF as per input voltage varies from 0 to 5V. PROGRAM: ORG 0000H LJMP SE11 ORG 0590H SE11: MOV SP,#53H MOVp2,#0ffh MOV A,#43H MOV DPTR,#0FF20H MOVX @DPTR,A ; store 53h data in stack pointer ; initialize port2 ; store 43h data in accumulator ; store address ff20h in DPTR ; store 43h data in memory location pointed by DPTR MOV 7EH,#00H MOV 7DH,#08H MOV 7CH,#00H MOV 7BH,#09H MOV 7AH,#10H ; clear 7eh memory location ; store 08h in 7dh memory location ; clear 7ch memory location ; store data 09h to 7bh memory location ; store 10h data in 7ah memory location
71

AMC-51 Advanced Microcontroller 8051 Trainer

MOV 79H,#10H LO18: LCALL SSEE MOV A,#00H MOV DPTR,#8000H MOVX @DPTR,A pointed by DPTR MOV R7,#0FFH LO17: DJNZ R7,LO17 MOVX A,@DPTR accumulator MOV R0,#79H LCALL PTDS SJMP LO18 ORG 05D0H PTDS: MOV R1,A ACALL PTDS1 MOV A,R1 SWAP A PTDS1: ANL A,#0FH MOV @R0,A pointed by r1 reg INC R0 RET ORG 0D50H SSEE: SETB RS1 MOV R5,#05H SSE2: MOV 30H,#20H

; store 10h data in 79h memory location

; clear accumulator ; store 8000h address in DPTR ; store data from accumulator to memory location ; store 0ffh data in r7 reg. ; decrement count in r7 & jump if not zero to Lo17 ; move data from memory location pointed by DPTR to ; move 79h data to r0

;move data from accumulator to r1

; move data from r1 reg. to accumulator ; exchange content of accumulator ; anding ofh data with accumulator data ; move data from accumulator to memory location ; increment content of r0 reg.

; set bit rs1 ; move 05h data to r5 reg. ; move 20h data to 30h memory location

72

AMC-51 Advanced Microcontroller 8051 Trainer

MOV 31H,#7EH MOV R7,#06H SSE1: MOV R1,#21 MOV A,30H CPL A MOVX @R1,A by r1 MOV R0,31H MOV A,@R0 accumulator MOV DPTR,#DDFF MOVC A,@A+DPTR MOV R1,#22H MOVX @R1,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH MOVX @R1,A DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET

; move 7eh data to 31h memory location ; move 06h to r7 reg. ; move 21h data t0 r1 reg. ; move 30h data to accumulator ; complement stored data in accumulator ; move data from accumulator to memory location pointed ; move 31h data to r0 reg. ; move data from memory location pointed by r0 to ; store ddffh address to DPTR ; move code byte related to DPTR to accumulator ; move 22h data to r1 reg. ; move data from accumulator to memory location ; move data from 30h memory location to accumulator ; data stored in accumulator rotate to right ; move data from accumulator to 30h ; decrement content of 31h memory location ; move data 0ffh to accumulator ; move data from accumulator to memory location pointed by r1

; clear rs1

DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0CH,89H,0DEH


73

AMC-51 Advanced Microcontroller 8051 Trainer

END

OUTPUT: Press GO button & observe the variation in XX count from 00FF as per input voltage varies from 0 to 5V on seven segment display.

74

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 10 Digital to Analog 0832 Conversion Experiment


OBJECTIVE: To study Digital to Analog conversion using ADC 0809 IC with microcontroller. CIRCUIT DISCRIPTION: Commonly used DAC0832 works on R/2R ladder method for conversion. Output of DAC 0832 ic Is in current . Calculation for Iout is Iout = Iref (D7/2 + D6/4 + D5/8 + + D0/256) Iout converted to voltage by 741 op-amp. Op-Amp will attempt to cancel any current through the inverting input. To do so, it will cause the current in the feedback resistor to be equal to the current in the inverting input resistor, but with an inverted polarity:

Since the currents are equal but opposite, they cancel each other out, resulting in 0 volts at the inverting input. Thus, the inverting input is at the same potential as ground. This generated ground is virtual ground. Here is what we know and what can be derived from it:

Ifb = -Iin The voltage on the left side of Rfb is 0 due to the virtual ground, so the voltage on the right is the voltage drop across Rfb , which is Vout = Rfb * Ifb. Since Ifb = -Iin, that also means that Vout = Rfb * -Iin

Key Specification of 0832 : Current settling time: 1 s Resolution : 8 bits Linearity : 8, 9, or 10 bits (guaranteed over temp.) Gain Temp co. : 0.0002% FS/C Low power dissipation : 20 mW Single power supply : 5 to 15 VDC

75

AMC-51 Advanced Microcontroller 8051 Trainer

CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect DAC0832 UNIT CS5 jack to DECODER SECTION 8000H jack using patch cord. b) Connect DAC0832 UNIT WR jack to DECODER SECTION IOWR jack using patch cord. c) Connect DAC0832 UNIT 8-pin JX2 connector to DECODER SECTION 8-pin JX0 using 8 pin ribbon cable. (Note: - Make sure LSB or PX.0 of source connector should connect to LSB or 0 th bit of destination Connector, where PX = any port). d) Switch ON power supply. 2)
a) b)

Run program:Open respective program DAC.ASM in 8051 simulation system software.

Press compile and load button in the software. We can see the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can press GO button for program execution. Use Stop button to stop the execution. e) 6 digit 7-segment display shows 0832 ---XX on the display. Where XX from 00FF and FF00.
76

AMC-51 Advanced Microcontroller 8051 Trainer

PROGRAM: ORG 0000H LJMP SE13 ORG 05E0H SE13: MOV SP,#53H ; store 53h data to stack pointer MOV p2,#0ffh ; initialize port2 MOV A,#43H ; move 43h data to accumulator MOV DPTR,#0FF20H ; store address ff20h to DPTR MOVX @DPTR,A ; 1st display value MOV 7EH,#00H ; 2nd display MOV 7DH,#08H ; 3rd display MOV 7CH,#03H ; 4th display MOV 7BH,#02H LO20: MOV R6,#00H LO21: MOV DPTR,#8000H ; select DAC chip MOV A,R6 MOVX @DPTR,A ; store value of r6 reg. to accumulator & memory location pointed by DPTR MOV R0,#79H LCALL PTDS LCALL SSEE MOV R2,#08H ; load 8h data to r2 reg. LCALL DELYA ; call delay INC R6 ; R6++ CJNE R6,#0FFH,LO21 ; compare 0ff data with data of r6 reg. LO22: MOV DPTR,#8000H ; load 8000 to DPTR DEC R6 ; R6-MOV A,R6 ; load data from R6 to accumulator MOVX @DPTR,A ; load accumulator data to memory location pointed by DPTR MOV R0,#79H ; load 79 h to r0 LCALL PTDS LCALL SSEE MOV R2,#0FH LCALL DELYA ; call delay CJNE R6,#00H,LO22 ; check r6 is 00h SJMP LO20 ;ORG 0620H PTDS: MOV R1,A ; load accumulator data to R1 LCALL PTDS1 MOV A,R1 SWAP A ; exchange data stored in accumulator PTDS1: ANL A,#0FH MOV @R0,A ; load data from accumulator to memory location pointed by r0 INC R0 ; increment address stored in R0 RET ORG 0D50H SSEE: SETB RS1 ; set bit rs1 MOV R5,#05H
77

AMC-51 Advanced Microcontroller 8051 Trainer

SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H SSE1: MOV R1,#21H MOV A,30H CPL A MOVX @R1,A MOV R0,31H MOV A,@R0 MOV DPTR,#DDFF ; to display the value MOVC A,@A+DPTR MOV R1,#22H MOVX @R1,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH MOVX @R1,A DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FCH,0CH,89H,0DEH DELYA: PUSH 02H ; no operation DELYB: PUSH 02H DELYC: PUSH 02H DELYD: DJNZ R2,DELYD LCALL SSEE POP 02H DJNZ R2,DELYC POP 02H DJNZ R2,DELYB POP 02H DJNZ R2,DELYA RET END Output: Press GO button ,use multi-meter to measure DAC0832 UNIT-- AOUT jack with respect GND post on the left side of 0832, the voltage should be increasing and then decreasing continuously. Or we can connect AOUT jack to DC MOTOR DJ jack and observe the variation in speed. Assignment: Modify program, to achieve saw tooth wave.
78

AMC-51 Advanced Microcontroller 8051 Trainer

79

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 11

8279 Keyboard Displaying Experiment


OBJECTIVE: To master the method of expansion 8279 keyboard display interface. CIRCUIT DISCRIPTION: Use of 8279 makes design of a keyboard interface circuit simple. This device can drive 8 x 8 keyboard switch array & a 16 digit , segment display. It can be configured through software to support key debouncing , two key lockout , or two key rollover modes of operation & either left or right data entry to display .There are four signal section :MCU interface , key data inputs , display & data outputs , and scan lines used by both keyboard & display . It consist of 8 data bus lines DB) through DB1. These are line over which the MCU outputs data to display key codes , issues commands to the controller & read status information from the controller .Other signals found at the interface are the read , write ,chip select & address buffer control signal .These are the signals that controls data bus transfer tacking place between MCU & 8279.IRQ ,an output that gets return to an interrupt input of microcomputer. The scan lines are used as row drive signals for keyboard & digit drive signals for display. There are just 4 of these linesSL0 to SL3.They can be configured for two different modes of operation through software The second mode of operation called encoded mode , allows use of keyboard matrix with up to eight rows & a display with up to 16 digits. When this mode of operation enabled , the binary coded wave form are output on SL lines. These signals must be decoded with an external decoder circuit to produce digit & column drive signals. The key data lines include 8 return lines RL0 through RL7. These lines receives input from. the column outputs of keyboard array. If logic 0 is detected at return line, it generate key code. This key code input is first debounced & then loaded into an 8 x 8 key code, the IRQ set to logic one. Shift & control/strobe are also stored as part of key code when a switch closure is detected. Write command mode register & status register as per required. CIRCUIT DIAGRAM:

80

AMC-51 Advanced Microcontroller 8051 Trainer

PROCEDURE: 1) Connections:a) Connect 8279 UNIT CS6 jack to DECODER SECTION 8000H jack using patch cord. b) Connect 8279 UNIT 8-pins JSL connector to 8155 UNIT 8-pin JS using 8 pin ribbon cable. c) Connect 8279 UNIT 8-pins JRL connector to 8155 UNIT 8-pin JR using 8 pin ribbon cable.``1` d) Connect 8279 UNIT 8-pins JOUT connector to 8155 UNIT 8-pin JLED using 8 pin ribbon cable. e) Keep SW3, SW4 and SW5 switch located in 4X6 MATRIX KEYBOARD setting at OFF position (slide to left hand direction). f) Switch ON power supply. 2)
a) b)

Run program:Open respective program 8279.ASM in 8051 simulation system software.

Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Debug the whole program step by step using debug tool set or press GO button program execution. Use Stop button to stop the execution. e) 6 digit 7-segment display shows P------ on the display. for

PROGRAM: ORG 0000H LJMP H900 ORG 00D0H H900: MOV SP,#53H MOV DPTR,#8001H ; select chip MOV A,#00H ; clear accumulator MOVX @DPTR,A ; reset chip MOV A,#32H ; load 32h to accumulator MOVX @DPTR,A ; load 32h data to memory location pointed by DPTR MOV A,#0DFH ; load dfh data to memory location pointed by DPTR MOVX @DPTR,A H901: MOVX A,@DPTR ; move data from memory location pointed by DPTR to accumulator JB ACC.7,H901 ; jump if acc.7 is set to H901 MOV a,#85h ; load 85h to accumulator MOVX @DPTR, a ; store data from accumulator to memory location pointed by DPTR MOV DPTR,#8000H ; load c8h data to memory location pointed by DPTR MOV A,#0c8H MOVX @DPTR,A INC DPTR ; load 8001 to DPTR MOV A,#85H ; load 85h to 8001h memory location
81

AMC-51 Advanced Microcontroller 8051 Trainer

MOVX @DPTR,A H902: MOV 30H,#85H MOV 31H,#40H H903: MOV DPTR,#8001H MOVX A,@DPTR ANL A,#07H CJNE A,#00H,H904 AJMP H903 H904: MOV DPTR,#8000H MOVX A,@DPTR MOV B,A MOV R1,#00H MOV DPTR,#GOJZ H905: MOV A,#00H MOVC A,@A+DPTR accumulator CJNE A,B,H906 AJMP H907 H906: INC DPTR INC R1 MOV A,R1 JB ACC.4,H908 AJMP H905 H908: MOV R1,#00H MOV DPTR,#GOJZ1 H909: MOV A,#00H MOVC A,@A+DPTR CJNE A,B,H90A AJMP H90B H90A: INC DPTR INC R1 MOV A,R1 JNB ACC.2,H909 AJMP H900 H907: MOV A,30H MOV DPTR,#8001H MOVX @DPTR,A MOV A,R1 MOV R0,31H MOV @R0,A INC 31H MOV DPTR,#ZOE0 MOVC A,@A+DPTR MOV DPTR,#8000H MOVX @DPTR,A DEC 30H MOV A,30H CJNE A,#7fH,H90C AJMP H902 H90C: AJMP H903 H90B: MOV DPTR,#CKEY3 MOV A,R1

; load 85h to 30h memory location ; load 40h to 31h memory location

; load display table to DPTR ; clear accumulator ; data from accumulator + DPTR memory location to ; compare a & b

82

AMC-51 Advanced Microcontroller 8051 Trainer

RL A ADD A,R1 JMP @A+DPTR CKEY3: LJMP L240 LJMP L241 LJMP L242 LJMP H900 GOJZ: DB 0C9H,0C3H,0D3H,0E1H,0C8H,0D8H,0E8H,0C0H,0D0H DB 0E0H,0F0H,0F8H,0F1H,0F9H,0E9H,0D9H GOJZ1: DB 0F2H,0FAH,0F3H,0FBH ZOE0: DB 0CH,9FH,4AH,0BH,99H,29H,28H,8FH,08H,09H,88H DB 38H,6CH,1AH,68H,0E8H ;ORG 0E41H L240: MOV R5,#0CH LJMP L245 ; to scroll 0 value L241: MOV R5,#9FH LJMP L245 ; to scroll 1 value L242: MOV R5,#4AH ; to scroll 2 number L245: MOV R6,#80H ; store 80h data in r6 L246: MOV A,R6 MOV DPTR,#8001H MOVX @DPTR,A ; load 80h to 8001h memory location MOV A,R5 MOV DPTR,#8000H ; load display value to 800h MOVX @DPTR,A MOV R2,#20H ; load 20h to r2 LCALL DELY ; call delay MOV A,#0FFH ; load FFh data to DPTR memory location MOVX @DPTR,A INC R6 ; increment R6 reg. CJNE R6,#88H,L246 AJMP L245 ; for continuous scrolling RET DELY: PUSH 02H DEL2: PUSH 02H DEL3: PUSH 02H DEL4: DJNZ R2,DEL4 POP 02H DJNZ R2,DEL3 POP 02H DJNZ R2,DEL2 POP 02H DJNZ R2,DELY RET END OUTPUT: a) Press GO button . Press the keys from 4X6 MATRIX KEYBOARD from 0~9 and A~F then respective no. is displayed on 6 digit 7-segment display. b) When press MON key then display shows P on display.
83

; for delay

AMC-51 Advanced Microcontroller 8051 Trainer

c) When press EX, SCAL and STEP key then respective 0, 1 and 2 no. displayed continuously in running fashion and program comes out of program loop. To change the running mode ,we have to reload program. NOTE:Keep SW3, SW4 and SW5 switch located in 4X6 MATRIX KEYBOARD setting at ON position (slide to right hand direction) after completion of this experiment.

84

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 12 Common Used Printer


OBJECTIVE: To study how the printer give print of ASCII code using microcontroller CIRCUIT DISCRIPTION: Serial to Parallel-Printer converter IC is designed to allow printing on most parallel-interface printers via microcontrollers and BASIC Stamps . It allows such devices the ability to create hard-copy output of data or status without the intervention of a PC and without the I/O or timing demands of the printer's parallel interface. Typical applications include data logging, status reports, parameter graphing, etc. Data is written to a single serial data wire at 2400 Baud. IC generates the appropriate printer control signals as well as monitors printer status to cause the incoming serial stream to be printed on the parallel printer, thus allowing designers the ability to use the less-expensive and more readily available parallel-type printers as opposed to the more costly serial-input printers. It can also be used with most PC's, allowing data to be sent to most parallel printers over a single serial wire; hardware handshaking signals are also generated by the IC to allow it to communicate properly with the PC. Connection to most microcontrollers, stamps, or microprocessors can be made using a single data wire, without any type of voltage level conversion. STROBE (Pin 1): ................................................... Printer STROBE Line; pin 1 on parallel printer cable BUSY (Pin 18): ..................................................... Printer BUSY Line; pin 11 on parallel printer cable D0 (Pin 6): ........................................................... Printer Data 0 Line; pin 2 on parallel printer cable D1 (Pin 7): ........................................................... Printer Data 1 Line; pin 3 on parallel printer cable D2 (Pin 8): ........................................................... Printer Data 2 Line; pin 4 on parallel printer cable D3 (Pin 9): ........................................................... Printer Data 3 Line; pin 5 on parallel printer cable D4 (Pin 10): ......................................................... Printer Data 4 Line; pin 6 on parallel printer cable D5 (Pin 11): ......................................................... Printer Data 5 Line; pin 7 on parallel printer cable D6 (Pin 12): ......................................................... Printer Data 6 Line; pin 8 on parallel printer cable D7 (Pin 13): ......................................................... Printer Data 7 Line; pin 9 on parallel printer cable GND (Pin 5):........................................................ Printer Ground Line; pin 18 on parallel printer cable CIRCUIT DIAGRAM:

85

AMC-51 Advanced Microcontroller 8051 Trainer

86

AMC-51 Advanced Microcontroller 8051 Trainer

PROCEDURE: 1) Connections:a) Connect common used printer port to 8255 UNIT-CA4 socket using 14pin FRC female cable. b) Switch ON power supply. 2)
a) b)

Run program:Open respective program print_c.ASM in 8051 simulation system software.

Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Debug the whole program step by step using debug tool set or press GO button program execution. Use Stop button to stop the execution. PROGRAM: ORG 0000H DOE0: MOV DPTR,#0FF2BH MOV A,#88H MOVX @DPTR,A MOV DPTR,#0FF2AH MOV A,#01H MOVX @DPTR,A DOE1: MOVX A,@DPTR JB ACC.4,DOE1 MOV DPL,R0 MOV DPH,R1 MOVX A,@DPTR INC DPTR MOV R0,DPL MOV R1,DPH MOV DPTR,#0FF28H MOVX @DPTR,A MOV DPTR,#0FF2AH MOV A,#00H MOVX @DPTR,A MOV A,#01H MOVX @DPTR,A DJNZ R2,DOE1 DJNZ R3,DOE1 SJMP $ END OUTPUT: Press GO button for

; load 88h data in FF2Bh memory location ; store '1' in accumulator

; store data of R0 in DPL ; store data of R1 in DPH ; increment data stored in DPTR

; load accumulator data in FF28h memory location

;decrement data of R2 & R3 ,jump if not zero

. The printer prints ASCII code.

87

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 13 Micro printer Print Character/Curved shape


OBJECTIVE: To study how to use printer using microcontroller CIRCUIT DISCRIPTION: Serial to Parallel-Printer converter IC is designed to allow printing on most parallel-interface printers via microcontrollers and BASIC Stamps It allows . such devices the ability to create hard-copy output of data or status without the intervention of a PC and without the I/O or timing demands of the printer's parallel interface. Typical applications include data logging, status reports, parameter graphing, etc. Data is written to a single serial data wire at 2400 Baud. IC generates the appropriate printer control signals as well as monitors printer status to cause the incoming serial stream to be printed on the parallel printer, thus allowing designers the ability to use the less-expensive and more readily available parallel-type printers as opposed to the more costly serial-input printers. It can also be used with most PC's, allowing data to be sent to most parallel printers over a single serial wire; hardware handshaking signals are also generated by the IC to allow it to communicate properly with the PC. Connection to most microcontrollers, stamps, or microprocessors can be made using a single data wire, without any type of voltage level conversion. STROBE (Pin 1): ................................................... Printer STROBE Line; pin 1 on parallel printer cable BUSY (Pin 18): ..................................................... Printer BUSY Line; pin 11 on parallel printer cable D0 (Pin 6): ........................................................... Printer Data 0 Line; pin 2 on parallel printer cable D1 (Pin 7): ........................................................... Printer Data 1 Line; pin 3 on parallel printer cable D2 (Pin 8): ........................................................... Printer Data 2 Line; pin 4 on parallel printer cable D3 (Pin 9): ........................................................... Printer Data 3 Line; pin 5 on parallel printer cable D4 (Pin 10): ......................................................... Printer Data 4 Line; pin 6 on parallel printer cable D5 (Pin 11): ......................................................... Printer Data 5 Line; pin 7 on parallel printer cable D6 (Pin 12): ......................................................... Printer Data 6 Line; pin 8 on parallel printer cable D7 (Pin 13): ......................................................... Printer Data 7 Line; pin 9 on parallel printer cable GND (Pin 5):........................................................ Printer Ground Line; pin 18 on parallel printer cable

88

AMC-51 Advanced Microcontroller 8051 Trainer

CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect micro printer port to 8255 UNIT-CA4 socket using 14pin FRC female cable. b) Switch ON power supply. 2)
a)

Run program:Open respective program print_m.ASM in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit.
b)

Debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution. PROGRAM: ORG 0280H D1E0: MOV SP,#53H MOV DPTR,#0FF2BH MOV A,#88H MOVX @DPTR,A ACALL D1E2 ACALL D1E3 MOV R6,#0A6H MOV R7,#0DH D1E1: MOV A,R6 MOVC A,@A+PC ACALL D1E4 INC R6 DJNZ R7,D1E1

; load 88h data in ff2Bh memory location

; increment data of R6
89

AMC-51 Advanced Microcontroller 8051 Trainer

ACALL D1E3 ACALL D1E2 ACALL D1E3 ACALL D1EA ACALL D1E5 MOV R6,#68H ; load 68 in R6 ACALL D1E6 ACALL D1E5 MOV R6,#8CH ACALL D1E6 ACALL D1E7 ACALL D1E7 MOV DPTR,#2000H ; load 2000h in DPTR MOV R6,#14H ; load 14 in R6 ACALL D1E8 MOV R7,#0DH ; load 0D in r7 D1E9: MOV R6,#09H ACALL D1E8 DJNZ R7,D1E9 ; decrement jump if not zero data of r7 SJMP $ D1E3: MOV A,#0AH ; load 0Ah in accumulator ACALL D1E4 RET ; return D1E7: MOV A,#0DH ; data 0Dh store in accumulator ACALL D1E4 RET D1EA: MOV A,#1BH ACALL D1E4 MOV A,#31H ACALL D1E4 MOV A,#00H ACALL D1E4 ACALL D1E3 RET D1E6: MOV R7,#24H D1EB: MOV A,R6 MOVC A,@A+PC ACALL D1E4 INC R6 ; Increment data of R6 DJNZ R7,D1EB ; decrement jump if not zero data of R7 ACALL D1E3 RET D1E8: MOV A,#1BH ACALL D1E4 MOV A,#27H ACALL D1E4 MOV A,R6 ACALL D1E4 D1EC: MOVX A,@DPTR INC DPTR ; increment address of DPTR ACALL D1E4 DJNZ R6,D1EC ; decrement data of r6 till zero
90

AMC-51 Advanced Microcontroller 8051 Trainer

ACALL D1E7 RET D1E5: MOV A,#1BH ACALL D1E4 MOV A,#4BH ACALL D1E4 MOV A,#24H ACALL D1E4 MOV A,#00H ACALL D1E4 RET D1E2: MOV R7,#07H D1ED: MOV A,#23H ACALL D1E4 MOV A,#20H ACALL D1E4 DJNZ R7,D1ED RET D1E4: PUSH DPH PUSH DPL PUSH ACC MOV DPTR,#0FF2AH D1EE: MOVX A,@DPTR JB ACC.4,D1EE POP ACC MOV DPTR,#0FF28H MOVX @DPTR,A MOV DPTR,#0FF2BH MOV A,#00H MOVX @DPTR,A MOV A,#01H MOVX @DPTR,A POP DPL POP DPH RET DB 23H,20H,39H,34H,8CH,31H,32H,8DH,33H,30H,8EH DB 20H,23H DB 00H,00H,00H,7FH,3FH,22H,22H,0A2H,0E2H,62H DB 22H,22H,22H,3EH,7FH,20H,00H,00H DB 00H,00H,00H,00H,20H,21H,27H,3FH,79H,0E1H,0BFH DB 27H,21H,21H,23H,61H,20H,00H DB 00H,03H,06H,0FCH,0FCH,7FH,3EH,22H,22H,22H,22H DB 22H,22H,3FH,7FH,20H,00H,00H DB 00H,00H,00H,00H,04H,0CH,0B8H,70H,22H,02H,0FEH DB 0FEH,00H,40H,38H,1EH,08H,00H END OUTPUT: Press GO button . The printer print curved shape date.
91

AMC-51 Advanced Microcontroller 8051 Trainer

92

AMC-51 Advanced Microcontroller 8051 Trainer

xperiment 14 Relay Control


OBJECTIVE: To master the basic principle and programming method of relay control. CIRCUIT DISCRIPTION: The P1.0 pin of microcontroller is connected to relay through transistor. Led are connected to NO & NC contacts of relay. Transistor is used to amplify current required for relay coil .Diode connected across coil to protect it from damage. Relay switches to one of the contact alternately as port 1.0 high & low. So led are glowing alternately.

CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect RELAY UNIT JIN jack to DECODER SECTION- P1.0 jack using patch cord. b) Connect RELAY UNIT JB jack to ON-OFF OUTPUT UNIT L1 jack using patch cord. c) Connect RELAY UNIT JK jack to ON-OFF OUTPUT UNIT L2 jack using patch cord. d) Connect RELAY UNIT JZ jack to IN-BUILT POWER GND jack using patch cord. e) Switch ON power supply. 2) Run program:a) Open respective program relay.ASM in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed.
b)

93

AMC-51 Advanced Microcontroller 8051 Trainer

d)

Current module window is opened and program is loaded into the kit. Debug for

the whole program step by step using debug tool set or press GO button program execution. Use Stop button to stop the execution. Default L1 is ON. PROGRAM: ORG 0000H LJMP LOOP ORG 0F00H LOOP: CLR P1.0 MOV R2,#30H LCALL DELY SETB P1.0 MOV R2,#30H LCALL DELY SJMP LOOP

; load 00 on port 1 ; store 30h in R2 ; delay sub rout ; load '1' on all pins of port1

DELY: PUSH 02H ; loop for delay DEL2: PUSH 02H DEL3: PUSH 02H DEL4: DJNZ R2,DEL4 POP 02H DJNZ R2,DEL3 POP 02H DJNZ R2,DEL2 POP 02H DJNZ R2,DELY RET END OUTPUT: Press GO button & observe Relay turns ON and off according to P1.0 control line and LED L1 and L2 show the on-off status of relay. L1=Off and L2 =On.

94

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 15 STEPPER MOTOR CONTROL

OBJECTIVE: Interface a stepper motor to the 8051 microcontroller system and write an 8051 assembly language program to control the stepper motor CIRCUIT DISCRIPTION : A stepper motor is a digital motor. It can be driven by digital signal. The center taps of these winding are connected 12V supply. Due to this ,motor can be excited by grounding four terminals of the two windings. Motor can be rotated in steps by giving proper excitation sequence to these windings. The lower nibble of port A of 8255 is used to generate excitation signals in proper sequence .These excitation signals are buffered using 74ls04. 74LS04 used so that they can source rated current for windings. Motor is rotated by 1.80 per excitation. The stepper motors have been designed to work with digital circuits. Binary level pulses of 0-5V are required at its winding inputs to obtain the rotation of the shafts. The sequence of the pulses can be decided, depending upon the required motion of the shaft. By suitable sequence of the pulses the motor can be used in three modes of operation. One phase ON (medium torque) Two phase ON(high torque) half stepping (low torque)

The stepper motor required high rating current so we used 74ls04 as a buffer ic . *Single phase working method. The motor control the positive run electrifying order of A C phaseABCDAReverse electrifying orderADCBA B D Four phase working method positive run electrifying order AABBBCCCDD DAAReverse electrifying orderAADDDCCCBBBAA *double-four phase working method positive run electrifying order ABBCCDDAABpositive run electrifying orderABADDCCBBA. CIRCUIT DIAGRAM:

95

AMC-51 Advanced Microcontroller 8051 Trainer

PROCEDURE: 1) Connections:a) Connect STEPPER UNIT HA jack to DECODER SECTION- P1.0 jack using patch cord. b) Connect STEPPER UNIT HB jack to DECODER SECTION- P1.1 jack using patch cord. c) Connect STEPPER UNIT HC jack to DECODER SECTION- P1.2 jack using patch cord. d) Connect STEPPER UNIT HD jack to DECODER SECTION- P1.3 jack using patch cord. e) Switch ON power supply. 2)
a) b)

Run program:Open respective program stepper.ASM in 8051 simulation system software.

Press compile and load button in the software. We can see the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can press GO button for program execution. Use Stop button to stop the execution. PROGRAM: ORG 0000H MOV P2,#0FFH ; initialize port 2 MOV 7EH,#11H MOV 7DH,#10H MOV 7CH,#10H MOV 7BH,#10H MOV 7AH,#10H MOV 79H,#10H MOV A,#43H MOV DPTR,#0FF20H ; load 43 data in FF20 memory location
96

AMC-51 Advanced Microcontroller 8051 Trainer

MOVX @DPTR,A MOV R0,#59H ; load 59 in R0 MOV A,#7EH ; load 7E in accumulator MOVX @R0,A ; Load7E in 59 DOJ0: MOV SP,#53H ; load 53 in stack pointer DOJ6: LCALL X2 JNC DOJ5 LCALL X3 MOV R1,#7EH SJMP DOJ6 DOJ5: CJNE A,#16H,DOJ6 MOV A,7AH SWAP A ORL A,79H MOV R6,A MOV A,7CH SWAP A ORL A,7BH MOV R7,A MOV A,7EH CJNE A,#00H,DOJ2 DOJ1: MOV P1,#03H LCALL DEL0Y LCALL GGJ0 MOV P1,#06H LCALL DEL0Y LCALL GGJ0 MOV P1,#0CH LCALL DEL0Y LCALL GGJ0 MOV P1,#09H LCALL DEL0Y LCALL GGJ0 SJMP DOJ1 DOJ2: MOV P1,#09H LCALL DEL0Y LCALL GGJ0 MOV P1,#0CH LCALL DEL0Y LCALL GGJ0 MOV P1,#06H LCALL DEL0Y LCALL GGJ0 MOV P1,#03H LCALL DEL0Y LCALL GGJ0 SJMP DOJ2 DEL0Y: MOV A,7DH SWAP A ; loop for clockwise rotation

; loop for anticlockwise rotation

; loop for delay


97

AMC-51 Advanced Microcontroller 8051 Trainer

MOV R2,A MOV R5,#80H DEL1Y: DJNZ R5,DEL1Y LCALL SSEE DJNZ R2,DEL1Y RET GGJ0: CJNE R7,#00H,GGJ1 CJNE R6,#00H,GGJ1 AJMP DOJ4 GGJ1: DJNZ R6,DOJ3 CJNE R7,#00H,DDJ8 DOJ4: LCALL DOJ7 SJMP DOJ4 DDJ8: DJNZ R7,DOJ3 AJMP DOJ4 DOJ3: LCALL DOJ7 RET DOJ7: MOV R0,#79H MOV A,R6 LCALL PTDS5 MOV A,R7 LCALL PTDS5 LCALL SSEE RET PTDS5: MOV R1,A ACALL PTDS6 MOV A,R1 SWAP A PTDS6: ANL A,#0FH MOV @R0,A INC R0 RET ORG 1D00H X3: MOV R4,A MOV R0,#59H MOVX A,@R0 MOV R1,A MOV A,R4 MOV @R1,A CLR A POP DPH POP DPL MOVC A,@A+DPTR INC DPTR CJNE A,01H,X30 CLR A MOVC A,@A+DPTR X31: MOVX @R0,A INC DPTR

; loop for second delay

98

AMC-51 Advanced Microcontroller 8051 Trainer

PUSH DPL PUSH DPH RET X30: DEC R1 MOV A,R1 SJMP X31 X2: MOV R6,#50H X0: ACALL XLE JNB ACC.5,XX0 DJNZ R6,X0 MOV R6,#20H MOV R0,#59H MOVX A,@R0 MOV R0,A MOV A,@R0 MOV R7,A MOV A,#10H MOV @R0,A X1: ACALL XLE JNB ACC.5,XX1 DJNZ R6,X1 MOV A,R7 MOV @R0,A SJMP X2 XX1: MOV R6,A MOV A,R7 MOV @R0,A MOV A,R6 XX0: RET XLE: ACALL DIS ACALL KEY MOV R4,A MOV R1,#48H MOVX A,@R1 MOV R2,A INC R1 MOVX A,@R1 MOV R3,A MOV A,R4 XRL A,R3 MOV R3,04H MOV R4,02H JZ X10 MOV R2,#88H MOV R4,#88H X10: DEC R4 MOV A,R4 XRL A,#82H JZ X11 MOV A,R4 XRL A,#0EH

; o display ; for pressed key

99

AMC-51 Advanced Microcontroller 8051 Trainer

JZ X11 MOV A,R4 ORL A,R4 JZ X12 MOV R4,#20H DEC R2 SJMP X13 X12: MOV R4,#0FH x11: MOV R2,04H MOV R4,03H X13: MOV R1,#48H MOV A,R2 MOVX @R1,A INC R1 MOV A,R3 MOVX @R1,A MOV A,R4 RET LS3: DB 07H,04H,08H,05H,09H,06H,0AH DB 0BH,01H,00H,02H,0FH,03H,0EH DB 0CH,0DH DIS: PUSH DPH PUSH DPL SETB RS1 MOV R0,#7EH MOV R2,#20H MOV R3,#00H MOV DPTR,#LS0 LS2: MOV A,@R0 MOVC A,@A+DPTR MOV R1,#22H MOVX @R1,A MOV A,R2 CPL A DEC R1 MOVX @R1,A CPL A DEC R0 LS1: DJNZ R3,LS1 CLR C RRC A MOV R2,A JNZ LS2 INC R1 MOV A,#0FFH MOVX @R1,A CLR RS1 POP DPL POP DPH RET LS0: DB 0C0H,0F9H,0A4H,0B0H,99H,92H DB 82H,0F8H,80H,90H,88H,83H,0C6H
100

AMC-51 Advanced Microcontroller 8051 Trainer

DB 0A1H,86H,8EH,0FFH,0CH,89H,7FH,0BFH KEY: SETB RS1 ; set bit RS1 MOV R2,#0FEH ; load R2 in FE MOV R3,#08H ; load 08 in R3 MOV R0,#00H ; load 00 in R0 LP1: MOV A,R2 MOV R1,#21H ; load 21 in r1 MOVX @R1,A RL A MOV R2,A MOV R1,#23H MOVX A,@R1 CPL A ; complement content of A ANL A,#0FH JNZ LP0 INC R0 DJNZ R3,LP1 MOVX A,@R1 JB ACC.4,XP33 MOV A,#19H SJMP XP3 XP33: MOV A,#20H ; load 20 in accumulator XP3: CLR RS1 ; clear Rs1 RET LP0: CPL A ; complement A JB ACC.0,XP0 MOV A,#00H SJMP LPP XP0: JB ACC.1,XP1 MOV A,#08H SJMP LPP XP1: JB ACC.2,XP2 MOV A,#10H SJMP LPP XP2: JB ACC.3,XP33 MOV A,#18H LPP: ADD A,R0 CLR RS1 CJNE A,#10H,LX0 LX0: JNC XP35 MOV DPTR,#LS3 MOVC A,@A+DPTR XP35: RET ORG 0D50H SSEE: SETB RS1 MOV R5,#05H SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H SSE1: MOV R1,#21H MOV A,30H
101

AMC-51 Advanced Microcontroller 8051 Trainer

CPL A MOVX @R1,A MOV R0,31H MOV A,@R0 MOV DPTR,#DDFF MOVC A,@A+DPTR MOV R1,#22H MOVX @R1,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH MOVX @R1,A DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0CH,89H,0DEH END OUTPUT: Press GO button & observe p state on 6digit 7-segment display. To rotate the stepper motor. Give the input to the program through 4X6 MATRIX KEYBOARD. Enter 1st digit 0 for clockwise direction, 1 for anti-clock wise direction. Enter 2 nd digit 1~F for rotation speed. Enter 3rd to 6th digit for count, so maximum count is FFFF. This count is always in decreasing fashion whether the rotation is clock wise or anti-clock wise direction. After entering number ,press EX key to start rotate.For changing direction reload program.

102

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 16 8253 Square Wave

OBJECTIVE To know the working principle of 8253 IC & interfacing with microcontroller 8051.. CIRCUIT DISCRIPTION The square wave can be achieved by mode 3, when 8253 is running in channel 0. IC 8253 is a programmable timing/ counter, which have three 16bits counters and +5V single power supply. The counting frequency range is 0-2MHz. Each counter of the 8253 is individually programmed by writing a control word into the Control Word Register. (A0,A1=11) Control World Format D7 SC1 D6 D5 SC0 D4 RL1 D3 D2 RL0 D1 M2 D0 M1 M0 BCD

Definition of Control SC Select Counter SC1 SC0 0 0 Select Counter 0 0 1 Select Counter 1 1 0 Select Counter 2 1 1 Illegal RL Read/Load RL1 0 1 0 1 RL0 0 0 1 1 Counter Latching operation (see READ/WRITE Procedure section) Read / Load most significant byte only Read / Load least significant byte only Read / Load least significant byte first, then most significant byte

M MODE 0 0 X X 0 0 1 1 0 1 0 1 Mode 0 Mode 1 Mode 2 Mode 3


103

AMC-51 Advanced Microcontroller 8051 Trainer

1 1

0 0

0 1

Mode 4 Mode 5

BCD: 0 Binary Counter 16 bits 1 Binary Coded Decimal (BCD) Counter (4 decade) The count register is not loaded until the count value is written (one or two bytes, depending on the mode selected by the RL bits), followed by a rising edge and a falling clock edge may yield Invalid data. MODE Definition: MODE O: Interrupt on Terminal Count. The output will be initially low after the mode set operation. After the counts is loaded into the selected count register, the output will remain low and the counter will count. When terminal count is reached the output will go high and remain until the selected count register is reloaded with mode or a new count is loaded. The counter continues to decrement after terminal count has been reached. Rewriting a counter register during counting results in the following: (1) Write 1st byte stops the current counting (2) Write 2nd byte starts the new count. Read/Write Logic: The Read/Write Logic accepts inputs from the system bus and in turn generates control signals for overall device operation. It is enabled by CS so that no operation can occur to change the function unless the device has been selected by the system logic. RD (Read) A low on this input informs the 8253 that the CPU is inputting data in the form of a counters value. WR (Write) A low on this input informs the 8253 that the CPU is outputting data in the form of mode information or loading counters. AO,A1 This inputs are normally connected to the address bus. Their function is to select one of the three counters to be operated on and to address the control word register for mode selection. CS (Chip Select) A low on this input enables the 8253 . No reading or writing will occur unless the device is selected. The CS Input has no elect upon the actual operation of the counters.

104

AMC-51 Advanced Microcontroller 8051 Trainer

CIRCUIT DIAGRAM:

PROCEDURE:
1) Connections:a) Connect 8255 UNIT CS3 jack to DECODER SECTION- 8000H jack using patch cord. b) Connect 8253 UNIT CLK0 jack to MONOPULSE AND CLOCK UNIT-2MHz jack using patch cord. c) Connect 8253 UNIT-GATE0 jack to IN-BUILT POWER-+5V jack using patch cord. d) Switch ON power supply. 2) Run program:a) Open respective program square.ASM in 8051 simulation system software.
b) Press compile and load button

in the software. We can see the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Here Debug the whole program step by step using debug tool set or press GO button program execution. Use Stop button to stop the execution. PROGRAM: ORG 0000H LJMP L8253 ORG 0EC0H L8253:MOV DPTR,#8003H ; address for 8253 select MOV A,#36H ; control word for 8253 for

105

AMC-51 Advanced Microcontroller 8051 Trainer

MOVX @DPTR,A MOV A,#00H MOVX @DPTR,A MOV A,#10H MOVX @DPTR,A SJMP $ END

; MOV DPTR,#8000H ; load lower byte for count

; load higher byte for count

OUTPUT: Press GO button oscilloscope. . & observe the Square Wave on OUT0 jack of 8253 UNIT using

106

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 17 CONTROLLING SMALL DC MOTORS EXPERIMENT


OBJECTIVE To know how the small dc motor can control using DAC 0832 IC, CIRCUIT DISCRIPTION: Commonly used DAC0832 works on R/2R ladder method for conversion. Output of DAC 0832 IC Is in current . Calculation for Iout is Iout = Iref (D7/2 + D6/4 + D5/8 + + D0/256) Iout converted to voltage by using 741 op - amp.

Op-Amp will attempt to cancel any current through the inverting input. To do so, it will cause the current in the feedback resistor to be equal to the current in the inverting input resistor, but with an inverted polarity:

Since the currents are equal but opposite, they cancel each other out, resulting in 0 volts at the inverting input. Thus, the inverting input is at the same potential as ground. This generated ground is virtual ground. Here is what we know and what can be derived from it:

Ifb = -Iin The voltage on the left side of Rfb is 0 due to the virtual ground, so the voltage on the right is the voltage drop across Rfb, which is Vout = Rfb * Ifb.

Since Ifb = -Iin, that also means that Vout = Rfb * -Iin Key Specification of 0832: Current settling time: 1 s Resolution: 8 bits Linearity: 8, 9, or 10 bits (guaranteed over temp.) Gain Tempco: 0.0002% FS/C Low power dissipation: 20 mW Single power supply: 5 to 15 VDC To control small dc motor ,here DAC 0832 IC used .The output of 0832 IC given
107

AMC-51 Advanced Microcontroller 8051 Trainer

through LM 324 to dc motor to control speed .As voltage at output varying, the speed of dc motor also varying. The working of DAC 0832 is same as in DAC.

CIRCUIT DIAGRAM:

PROCEDURE:
Connections: a) Connect DAC0832 UNIT CS5 jack to DECODER SECTION 8000H jack using patch cord. b) Connect DAC0832 UNIT WR jack to DECODER SECTION IOWR jack using patch cord. c) Connect DAC0832 UNIT 8-pin JX2 connector to DECODER SECTION 8-pin JX0 using 8 pin ribbon cable. (Note: - Make sure LSB or PX.0 of source connector should connect to LSB or 0 th bit of destination Connector, where PX = any port). a) Connect 8255 UNIT AOUT jack to DC MOTOR-DJ jack using patch cord. b) Connect DC MOTOR-HOUT jack to DECODER SECTION-P3.2 jack using patch cord. c) Connect SWITCH INPUT UNIT K1~K8 8-pin connector to DECODER SECTION 8-pin JP1 connector using 8 pin ribbon cable. (Note: - Make sure LSB or PX.0 of source connector should connect to LSB or 0th bit of destination Connector, where PX = any port). d) Switch ON power supply. 2) Run program:a) Open respective program dc_motor.asm in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed.
b)
108

AMC-51 Advanced Microcontroller 8051 Trainer

d)

Current module window is opened and program is loaded into the kit.

Debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution. PROGRAM: ORG 0000H LJMP SE11 ORG 0003H LJMP COUNTER ORG 000BH LJMP CTIME ORG 0590H SE11: MOV SP,#53H MOV P2,#0FFH MOV A,#43H MOV DPTR,#0FF20H MOVX @DPTR,A SETB EA SETB EX0 SETB IT0 SETB ET0 MOV TMOD,#01H MOV TH0,#0B4H MOV TL0,#00H SETB TR0 MOV 40H,#00H MOV 41H,#00H MOV 42H,#00H MOV R6,#00H ; set bit timer request ; clear data in memory location ; clear data in memory location ; clear data in memory location ; set EA signal ; set EX0 ; set pin IT0 ; set pin ET0 ; use timer 0 ; load timer for 20ms ; define port2 ; load 43 in memory location FF20

109

AMC-51 Advanced Microcontroller 8051 Trainer

MOV 7EH,#00H MOV 7DH,#00H MOV 7CH,#14H MOV 7BH,#14H MOV 7AH,#00H MOV 79H,#00H LO18: LCALL SSEE MOV R7,#0FFH LO17: DJNZ R7,LO17 MOV A,42H MOV R0,#79H LCALL PTDS MOV A,P1 MOV B,A ANL A,#0FH MOV 7DH,A MOV A,B SWAP A ANL A,#0FH MOV 7EH,A MOV DPTR,#8000H MOV A,R6 MOVX @DPTR,A MOV A,42H MOV B,P1 SUBB A,B JZ LL AD: JC AA
110

; exchange content of Accumulator

AMC-51 Advanced Microcontroller 8051 Trainer

MOV R2,#09H LCALL DELYA CJNE R6,#01H,L1 JMP LL L1: DEC R6 JMP LL AA: MOV R2,#09H LCALL DELYA CJNE R6,#0FFH,L2 JMP LL L2: INC R6 LL: SJMP LO18 ; compare R6 data with 01

ORG 0700H PTDS: MOV R1,A ACALL PTDS1 MOV A,R1 SWAP A PTDS1: ANL A,#0FH MOV @R0,A INC R0 RET ORG 0D50H SSEE: SETB RS1 MOV R5,#05H SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H
111

AMC-51 Advanced Microcontroller 8051 Trainer

SSE1: MOV R1,#21H MOV A,30H CPL A MOVX @R1,A MOV R0,31H MOV A,@R0 MOV DPTR,#DDFF MOVC A,@A+DPTR MOV R1,#22H MOVX @R1,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH MOVX @R1,A DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET

COUNTER: INC 40H RETI

; loop for counter

CTIME: MOV TH0,#0B4H MOV TL0,#00H


112

AMC-51 Advanced Microcontroller 8051 Trainer

INC 41H MOV A,41H CJNE A,#20,WW MOV 42H,40H MOV 40H,#00H MOV 41H,#00H WW: RETI

DELYA: PUSH 02H DELYB: PUSH 02H DELYC: PUSH 02H DELYD: DJNZ R2,DELYD LCALL SSEE POP 02H DJNZ R2,DELYC POP 02H DJNZ R2,DELYB POP 02H DJNZ R2,DELYA RET

; to create delay ; to create delay ; to create delay

DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0F1H,0C6H,092H,0BFH END OUTPUT:Press GO button & observe 00--00 on the 6 digit 7-segment display. Left most two digit shows reference speed which can be set by SWITCH INPUT UNIT from 00 to 24. Toggles the key K1 to K8 to set the reference speed. Right most two digits show the current speed of DC motor. DC motor always tries to match the current speed with reference speed.

113

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 18 LED16*16 LATTICE DISPLAY EXPERIMENT


OBJECTIVE: To know how to drive 16*16 led dot matrix display drive using 8086

CIRCUIT DISCRIPTION: Here we are interfacing 16 x 16 dot matrix display with common cathode columns and having bright red led. A dot matrix display is a display device used to display information on machines, clocks, railway departure indicators and many and other devices requiring a simple display device of limited resolution. The display consists of a matrix of lights or mechanical indicators arranged in a rectangular configuration (other shapes are also possible, although not common) such that by switching on or off selected lights, text or graphics can be displayed. A dot matrix controller converts instructions from a processor into signals which turns on or off lights in the matrix so that the required display is produced. To drive led dot matrix ,we required 32 input lines .So we have to use decoder IC. We used here 74ls 273 ,74ls244 & 74ls507 IC. Here four 8 x 8 display used to create 16 x 16 display. CIRCUIT DIAGRAM:

114

AMC-51 Advanced Microcontroller 8051 Trainer

PROCEDURE: 1) Connections:a) Connect 16X16 DOT MATRIX UNIT 8-pins JHPC connector to DECODER SECTION 8-pin JX16 using 8 pin ribbon cable. b) Connect 16X16 DOT MATRIX UNIT 8-pins JLPA connector to DECODER SECTION 8-pin JX9 using 8 pin ribbon cable. c) Connect 16X16 DOT MATRIX UNIT 8-pins JLPB connector to DECODER SECTION 8-pin JX15 using 8 pin ribbon cable. d) Connect 16X16 DOT MATRIX UNIT 8-pins JHP1 connector to DECODER SECTION 8-pin JP1 using 8 pin ribbon cable. (Note: - Make sure LSB or PX.0 of source connector should connect to LSB or 0th bit of destination Connector, where PX = any port). e) Switch ON power supply. 2) Run program:a) Open respective program led_n.asm in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit.
b)

debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution. .

PROGRAM: ORG 0000H LJMP START ORG 2D80H XPA EQU 0FF28H ; define Pa address XPB EQU 0FF29H ; define PB address ;------------------------------------------------------------------------------XPC EQU 0FF2AH ; define PC address XPCTL EQU 0FF2BH ; define control word address for 8255 START:MOV DPTR,#XPCTL ; make all ports are output port MOV A,#80H MOVX @DPTR,A CALL OFFLED CLR 00H MOV R6,#28H MOV R7,#0FFH ;---------------------------------------X0: MOV R0,#00H X1: CALL DEL1 ; call delay INC R0 MOV A,R0 ; increment R0
115

AMC-51 Advanced Microcontroller 8051 Trainer

ANLA,#0fh CJNE A,#00h,L2 MOV A,#10h ADD A,R0 mov R0,A L2: CJNE R0,#0E0H,X1 X00: MOV R0,#00H X10: CALL DEL10 INC R0 MOV A,R0 ANL A,#0fh CJNE A,#00h,L20 MOV A,10h ADD A ,R0 MOV R0,A L20: CJNE R0,#0E0H,X10 X000: MOV R0,#00H X100: CALL DEL100 INC R0 MOV A,R0 ANL A,#0fh CJNE A,#00h,L200 MOV A,,#10h ADD A,R0 MOV R0,A L200: CJNE R0,#20H,X100

; add content of R0 & accumulator ; compare data of R0 with E0

; and data 0Fh with data of accumulator

SJMP X0 ;-----------------------------------------------------DISPW:PUSH 00H MOV R1,#01H CLR C DISP1:MOV A,R0 MOV DPTR,#TAB1 ; load data to be display on Port C MOVC A,@A+DPTR MOV DPTR,#XPC MOVX @DPTR,A ;------------------------------------------MOV A,#10h ADDA,R0 MOV DPTR,#TAB1 ; load data to be display on port A MOVC A,@A+DPTR MOV P1,A INC R0 ;------------------------------------------MOV A,R0 ANL A,#0fh CJNE A,#00h,L1 MOV A,#10h
116

AMC-51 Advanced Microcontroller 8051 Trainer

ADD A,R0 MOV R0,A CLR C L1: MOV DPL,R6 MOV DPH,R7 MOV A,R1 CPL A MOVX @DPTR,A MOV R3,#80h DJNZ R3,$ CALL OFFLED MOV A,R1 RLC A MOV R1,A JNC DISP1 JB 00H,EXIT ;---------------------------------SETB 00H CLR C MOV R1,#01H MOV R6,#29H MOV R7,#0FFH AJMP DISP1 ;-----------------------------------------------------DISPW0:PUSH 00H MOV R1,#01H CLR C DISP10:MOV A,R0 MOV DPTR,#TAB2 MOVC A,@A+DPTR MOV DPTR,#XPC MOVX @DPTR,A ;------------------------------------------MOV A,10h ADD A,R0 MOV DPTR,#TAB2 MOVC A,@A+DPTR MOV P1,A INC R0 ;------------------------------------------MOV A,R0 ANL A,#0fh CJNE A,#00h,L10 MOV A,10h ADD A,R0 MOV R0,A CLR C L10: MOV DPL,R6 MOV DPH,R7 MOV A,R1 CPL A

; decrement & jump if not zero

117

AMC-51 Advanced Microcontroller 8051 Trainer

MOVX @DPTR,A mov r3,#80h djnz r3,$ CALL OFFLED MOV A,R1 RLC A MOV R1,A JNC DISP10 JB 00H,EXIT ;---------------------------------SETB 00H CLR C MOV R1,#01H MOV R6,#29H MOV R7,#0FFH AJMP DISP10 EXIT: MOV R6,#28H MOV R7,#0ffH CLR 00H POP 00H RET ;-----------------------------------------------------DISPW00:PUSH 00H MOV R1,#01H CLR C DISP100:MOV A,R0 MOV DPTR,#TAB3 MOVC A,@A+DPTR MOV DPTR,#XPC MOVX @DPTR,A ;------------------------------------------MOV A,#10h ADD A,R0 MOV DPTR,#TAB3 MOVC A,@A+DPTR MOV P1,A INC R0 ;------------------------------------------MOV A,R0 ANL A,0fh CJNE A,#00h,L100 MOV A,#10h ADD A,R0 MOV R0,A CLR C L100: MOV DPL,R6 MOV DPH,R7 MOV A,R1 CPL A MOVX @DPTR,A
118

; load data to be display on Port C

; load data to be display on port A

AMC-51 Advanced Microcontroller 8051 Trainer

MOV R3,#80h DJNZ R3,$ CALL OFFLED MOV A,R1 RLC A MOV R1,A JNC DISP100 JB 00H,EXIT ;---------------------------------SETB 00H CLR C MOV R1,#01H MOV R6,#29H MOV R7,#0FFH AJMP DISP100 ;-------------------------------------------------------------------------------------DEL1: MOV R2,#05H ; delay loop DELY: PUSH 02H DEL2: PUSH 02H DEL3: PUSH 02H DEL4: DJNZ R2,DEL4 CALL DISPW POP 02H DJNZ R2,DEL3 POP 02H DJNZ R2,DEL2 POP 02H DJNZ R2,DELY RET ;--------------------------------------------------------;-------------------------------------------------------------------------------------DEL10: MOV R2,#05H ; delay loop DELY0: PUSH 02H DEL20: PUSH 02H DEL30: PUSH 02H DEL40: DJNZ R2,DEL40 CALL DISPW0 POP 02H DJNZ R2,DEL30 POP 02H DJNZ R2,DEL20 POP 02H DJNZ R2,DELY0 RET ;--------------------------------------------------------;-------------------------------------------------------------------------------------DEL100: MOV R2,#05H ; delay loop DELY00: PUSH 02H DEL200: PUSH 02H
119

AMC-51 Advanced Microcontroller 8051 Trainer

DEL300: PUSH 02H DEL400: DJNZ R2,DEL400 CALL DISPW00 POP 02H DJNZ R2,DEL300 POP 02H DJNZ R2,DEL200 POP 02H DJNZ R2,DELY00 RET ;--------------------------------------------------------OFFLED:MOV DPTR,#XPA MOV A,#0FFH MOVX @DPTR,A MOV DPTR,#XPB MOVX @DPTR,A RET ; to make led off ; load data on port B

tab1: ; F -DB 10H,1FH,11H,11H,17H,10H,08H,00H,00H,00H,03H,1CH,07H,00H,00H,00H ;: A -DB 04H,0FCH,04H,00H,0C0H,00H,00H,00H,04H,3CH,0C4H,40H,40H,0E4H,1CH,04H ; L -DB 10H,1FH,10H,00H,00H,00H,00H,00H,3H,0CH,10H,10H,10H,10H,1CH,00H ; C -DB 04H,0FCH,04H,04H,04H,04H,0CH,00H,0E0H,18H,04H,04H,04H,08H,10H,00H ; O -DB 07H,08H,10H,10H,10H,08H,07H,00H,10H,1FH,0CH,03H,00H,10H,1FH,10H ; N -DB 0F0H,08H,04H,04H,04H,08H,0F0H,00H,04H,0FCH,04H,00H,0E0H,18H,0FCH,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,10H,1FH,11H,11H,17H,10H,08H,00H ; E -DB 00H,00H,00H,00H,00H,00H,00H,00H,04H,0FCH,04H,04H,0C4H,04H,18H,00H


120

AMC-51 Advanced Microcontroller 8051 Trainer

; l -DB 00H,10H,10H,1FH,00H,00H,00H,00H,00H,00H,01H,01H,01H,01H,00H,00H ; e -DB 00H,04H,04H,0FCH,04H,04H,00H,00H,00H,0F8H,44H,44H,44H,44H,0C8H,00H ; c -DB 00H,00H,00H,01H,01H,01H,00H,00H,0H,01H,01H,07H,01H,01H,00H,00H ; t -DB 00H,70H,88H,04H,04H,04H,88H,00H,00H,00H,00H,0F8H,04H,04H,00H,00H ; r -DB 01H,01H,01H,00H,01H,01H,01H,00H,00H,00H,01H,01H,01H,01H,00H,00H ; o -DB 04H,04H,0FCH,84H,04H,00H,80H,00H,00H,0F8H,04H,04H,04H,04H,0F8H,00H ; - -DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,01H,01H,07H,01H,01H,00H,00H ; t -DB 00H,80H,80H,80H,80H,80H,80H,80H,00H,00H,00H,0F8H,04H,04H,00H,00H ;*********************************************************************** tab2: ; e -DB 00H,00H,01H,01H,01H,01H,00H,00H,10H,1FH,00H,00H,01H,01H,01H,00H ; k -DB 00H,0F8H,44H,44H,44H,44H,0C8H,00H,04H,0FCH,24H,40H,0B4H,0CH,04H,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,10H,1FH,10H,10H,10H,10H,0FH,00H ; P -DB 00H,00H,00H,00H,00H,00H,00H,00H,04H,0FCH,84H,80H,80H,80H,00H,00H ; v -DB 01H,01H,01H,00H,00H,01H,01H,01H,00H,01H,01H,07H,01H,01H,00H,00H ; t -DB 00H,80H,70H,0CH,10H,60H,80H,00H,00H,00H,00H,0F8H,04H,04H,00H,00H


121

AMC-51 Advanced Microcontroller 8051 Trainer

; . -DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; --

DB 00H,0CH,0CH,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; L -DB 10H,1FH,10H,00H,00H,00H,00H,00H,00H,01H,01H,07H,01H,01H,00H,00H ; t -DB 04H,0FCH,04H,04H,04H,04H,0CH,00H,00H,00H,00H,0F8H,04H,04H,00H,00H ; d -DB 00H,00H,00H,01H,01H,11H,1FH,00H,00H,00H,00H,00H,00H,00H,00H,00H ; . -DB 00H,70H,88H,04H,04H,08H,0FCH,04H,00H,0CH,0CH,00H,00H,00H,00H,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,10H,1FH,1FH,00H,1FH,1FH,10H,00H ; M -DB 00H,00H,00H,00H,00H,00H,00H,00H,04H,0FCH,00H,0FCH,00H,0FCH,04H,00H ; U -DB 10H,1FH,10H,00H,00H,10H,1FH,10H,10H,1FH,1FH,00H,1FH,1FH,10H,00H ; M -DB 00H,0F8H,04H,04H,04H,04H,0F8H,00H,04H,0FCH,00H,0FCH,00H,0FCH,04H,00H ;*************************************************************************** tab3: ; B -DB 10H,1FH,11H,11H,11H,0EH,00H,00H,00H,00H,03H,1CH,07H,00H,00H,00H ; A -DB 04H,0FCH,04H,04H,04H,88H,70H,00H,04H,3CH,0C4H,40H,40H,0E4H,1CH,04H ; I -DB 00H,10H,10H,1FH,10H,10H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H
122

AMC-51 Advanced Microcontroller 8051 Trainer

; . -DB 00H,04H,04H,0FCH,04H,04H,00H,00H,00H,0CH,0CH,00H,00H,00H,00H,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; -DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; -DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; -DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; --

DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H

123

AMC-51 Advanced Microcontroller 8051 Trainer

END OUTPUT: Press GO button & observe the rolling display shows FALCON Electro-tek Pvt. Ltd. MUMBAI message on 16X16 dot matrix displays.

124

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 19 12864 LCD Experiment


OBJECTIVE: To glow LCD display using 8086 interfacing with 8255. CIRCUIT DISCRIPTION: To display any character on LCD microcontrollerr has to send its ASCII value to the data bus of LCD. For e.g. to display 'AB' microcontroller has to send two hex bytes 41h and 42h respectively.LCD display used here is having 16x2 size. It means 2 lines each with 16 character.

Pin Information of LCD: PIN NUMBER 1 2 3 4 5 6 7 TO 14 15 16 SYMBOL GND VCC V0 RS R/W E D0 TO D7 VB1 VB0 DETAIL GROUND SUPPLY VOLTAGE +5V CONTRAST ADJUSTMENT 0-CONTROL INPUT 1-DATA INPUT READ/WRITE ENABLE DATA BACKLIGHT +5V BACKLIGHT GROUND

Algorithm to send data to LCD: 1.Make R/W low 2.Make RS=0 ;if data byte is command RS=1 ;if data byte is data (ASCII value)
125

AMC-51 Advanced Microcontroller 8051 Trainer

3.Place data byte on data register 4.Pulse E (HIGH to LOW) 5.Repeat the steps to send another data byte LCD Initialization: This is the pit fall for beginners. Proper working of LCD depend on the how the LCD is initialized. We have to send few command bytes to initialize the LCD. Simple steps to initialize the LCD

CIRCUIT DIAGRAM:

PROCEDURE: 1. Connections:a) Connect LCD UNIT 8-pins JX12 connector to DECODER SECTION 8-pin JP1 using 8 pin ribbon cable. b) Connect LCD UNIT 8-pins JX14 connector to DECODER SECTION 8-pin JP3 using 8 pin ribbon cable. (Note: - Make sure LSB or PX.0 of source connector should connect to LSB or 0 th bit of destination Connector, where PX = any port). c) Switch ON power supply. 2. Run program:e) Open respective program lcd_n.asm in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. g) If zero warning and zero error then Compilation and loading-OK message is displayed.
f)
126

AMC-51 Advanced Microcontroller 8051 Trainer

h)

Current module window is opened and program is loaded into the kit.

Debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution. PROGRAM: RS EQU 0B0h RW EQU 0B1H E EQU 0B2H CS1 EQU 0B4H CS2 EQU 0B5H ; P3.0 as RS bit ; P3.1 ; P3.2 ; P3.4 ; P3.5

; ORG 0000H RST: MOV R7, #04H LCALL DELAYXMS CLR E SETB RS SETB CS1 ; SELECT-CS1 CLR CS2 CLR RS MOV P1, #3FH ; DISPLAY ON LCALL WRITE MOV R7, #01H SETB CS2 ; SELECT-CS2 CLR CS1 CLR RS MOV P1, #3FH ; DISPLAY ON LCALL WRITE MAIN: MOV R7, #0FH MOV DPTR, #TAB5 LCALL ZXL MOV R7,#03FH LCALL DELAYXMS ;MOV DPTR,#TAB6 ;LCALL ZXL ;MOV R7,#03FH ;LCALL DELAYXMS LJMP MAIN ;*************************************************** ZXL: CLR CS2 SETB CS1 ;S-CS1 LCALL XPAGE ; R0=08H,R2=B8H,Z=Y=PAG=00 LCALL COM CLR CS1 SETB CS2 ; S-CS2 LCALL XPAGE LCALL COM RET ;***************************************************** XPAGE:CLR E CLR RS
127

AMC-51 Advanced Microcontroller 8051 Trainer

MOV P1, #0C0H ; SET-Z=00,FIRST LCALL WRITE MOV P1, #40H ; SET-Y=00,FIRST LCALL WRITE MOV R0, #08H MOV R2, #0B8H MOV P1, #0B8H ; SET-PAG=00 LCALL WRITE RET ;****************************************************** COM:CLR 00H COM1: MOV R1, #40H ; R0=#08H,R2=#0B8H MOV R3,#10H SETB RS ; WR-DATA PUSH DPH PUSH DPL J4: CLR A MOVC A, @A+DPTR ; DPTR=#TAB5 MOV P1, A LCALL WRITE INC DPTR DJNZ R3,J41 MOV R3,#10H CLR C MOV A,DPL ADD A,#10H MOV DPL,A JNC J41 INC DPH J41: DJNZ R1, J4 ; LOAD-64-BYTE CLR RS ; WR-COMD INC R2 MOV P1, R2 LCALL WRITE ; SET-PAG=01 MOV P1, #40H ; SET-Y=00H LCALL WRITE POP DPL POP DPH CPL 00H JNB 00H,J43 CLR C MOV A,DPL ADD A,#10H MOV DPL,A JNC J42 INC DPH AJMP J42 J43: CLR C MOV A,DPL ADD A,#70H MOV DPL,A JNC J42
128

AMC-51 Advanced Microcontroller 8051 Trainer

INC DPH J42:DJNZ R0, COM1 RET ;*************************************************** WRITE:CLR RW CLR E SETB E LCALL DELAY2MS CLR E RET ;********************************* DELAY2MS: MOV R6, #02H DELAY1: DJNZ R5, DELAY1 DJNZ R6, DELAY0 RET ;************************************* DELAYXMS: MOV R5, #40H D1: MOV R6, #0FFH D2: DJNZ R6, D2 DJNZ R5, D1 DJNZ R7, DELAYXMS RET ; F -DB 08H,0F8H,88H,88H,0E8H,08H,10H,00H,00H,00H,0C0H,38H,0E0H,00H,00H,00H ; A -DB 20H,3FH,20H,00H,03H,00H,00H,00H,20H,3CH,23H,02H,02H,27H,38H,20H ; L -+ DB 08H,0F8H,08H,00H,00H,00H,00H,00H,0C0H,30H,08H,08H,08H,08H,38H,00H ;C -DB 20H,3FH,20H,20H,20H,20H,30H,00H,07H,18H,20H,20H,20H,10H,08H,00H ; O -DB 0E0H,10H,08H,08H,08H,10H,0E0H,00H,08H,0F8H,30H,0C0H,00H,08H,0F8H,08H ; N -DB 0FH,10H,20H,20H,20H,10H,0FH,00H,20H,3FH,20H,00H,07H,18H,3FH,00H ; -DB 00H,00H,00H,00H,00H,00H,00H,00H,08H,0F8H,88H,88H,0E8H,08H,10H,00H ; E -DB 00H,00H,00H,00H,00H,00H,00H,00H,20H,3FH,20H,20H,23H,20H,18H,00H ;********************************************************************** ; e -DB 00H,00H,80H,80H,80H,80H,00H,00H,08H,0F8H,00H,00H,80H,80H,80H,00H ; k -129

AMC-51 Advanced Microcontroller 8051 Trainer

DB 00H,1FH,22H,22H,22H,22H,13H,00H,20H,3FH,24H,02H,2DH,30H,20H,00H ; -DB 00H,00H,00H,00H,00H,00H,00H,00H,08H,0F8H,08H,08H,08H,08H,0F0H,00H ; P -DB 00H,00H,00H,00H,00H,00H,00H,00H,20H,3FH,21H,01H,01H,01H,00H,00H ; v -DB 80H,80H,80H,00H,00H,80H,80H,80H,00H,80H,80H,0E0H,80H,80H,00H,00H ; t -DB 00H,01H,0EH,30H,08H,06H,01H,00H,00H,00H,00H,1FH,20H,20H,00H,00H ; . -DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; -DB 00H,30H,30H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;******************************************************************** ; B -DB 08H,0F8H,88H,88H,88H,70H,00H,00H,00H,00H,0C0H,38H,0E0H,00H,00H,00H ; A -DB 20H,3FH,20H,20H,20H,11H,0EH,00H,20H,3CH,23H,02H,02H,27H,38H,20H ; I -DB 00H,08H,08H,0F8H,08H,08H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; . -DB 00H,20H,20H,3FH,20H,20H,00H,00H,00H,30H,30H,00H,00H,00H,00H,00H ;****************************************************************12 DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;****************************************************************12 ; l -130

AMC-51 Advanced Microcontroller 8051 Trainer

DB 00H,08H,08H,0F8H,00H,00H,00H,00H,00H,00H,80H,80H,80H,80H,00H,00H ; e -DB 00H,20H,20H,3FH,20H,20H,00H,00H,00H,1FH,22H,22H,22H,22H,13H,00H ; c -DB 00H,00H,00H,80H,80H,80H,00H,00H,00H,80H,80H,0E0H,80H,80H,00H,00H ; t -DB 00H,0EH,11H,20H,20H,20H,11H,00H,00H,00H,00H,1FH,20H,20H,00H,00H ; r -DB 80H,80H,80H,00H,80H,80H,80H,00H,00H,00H,80H,80H,80H,80H,00H,00H ; o -DB 20H,20H,3FH,21H,20H,00H,01H,00H,00H,1FH,20H,20H,20H,20H,1FH,00H ; - -DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,80H,80H,0E0H,80H,80H,00H,00H ; t -DB 00H,01H,01H,01H,01H,01H,01H,01H,00H,00H,00H,1FH,20H,20H,00H,00H ;******************************************************************* ; L -DB 08H,0F8H,08H,00H,00H,00H,00H,00H,00H,80H,80H,0E0H,80H,80H,00H,00H ; t -DB 20H,3FH,20H,20H,20H,20H,30H,00H,00H,00H,00H,1FH,20H,20H,00H,00H ; d -DB 00H,00H,00H,80H,80H,88H,0F8H,00H,00H,00H,00H,00H,00H,00H,00H,00H ; . -DB 00H,0EH,11H,20H,20H,10H,3FH,20H,00H,30H,30H,00H,00H,00H,00H,00H

; -DB 00H,00H,00H,00H,00H,00H,00H,00H,08H,0F8H,0F8H,00H,0F8H,0F8H,08H,00H ; M -DB 00H,00H,00H,00H,00H,00H,00H,00H,20H,3FH,00H,3FH,00H,3FH,20H,00H ; U -DB 08H,0F8H,08H,00H,00H,08H,0F8H,08H,08H,0F8H,0F8H,00H,0F8H,0F8H,08H,00H


131

AMC-51 Advanced Microcontroller 8051 Trainer

; M -DB 00H,1FH,20H,20H,20H,20H,1FH,00H,20H,3FH,00H,3FH,00H,3FH,20H,00H ;****************************************************************16 DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H DB 00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H,00H ;****************************************************************16 END OUTPUT: Press GO button & observe the display constantly shows FALCON Electro-tek Pvt. Ltd. MUMBAI message on LCD display.

132

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 20 8250 Serial Interface Experiment


OBJECTIVE: To study how the 8250 interfacing with 8051. CIRCUIT DISCRIPTION: 8250 is a asynchronous receiver transmitter IC. There is a programmable baud rate generator, double buffering on communication data registers and enhanced status and interrupt signaling. The connection of 8250 to implementation simple RS 232 serial communication. Chip select input, CS0,CS1 & CS2.To enable the interface, these inputs must be at logic 1,1 &0 respectively, at the same time address strobe is logic 0.A0,A1 & A2 are using to select resister addresses.

Frequency can be divided within 8250 to produce data communication baud rate. The divisor values that produce standard baud rates shown in table .To set asynchronous data communication rate 4800 baud divisor equal to 40 must be used. The 16 bit divider must be loaded under software control into the divisor are in DLL & DLM. hence the hex code 18 we load in program to create 4800 baud rate.

133

AMC-51 Advanced Microcontroller 8051 Trainer

1. Communication protocol: a initial position,8 data position, 1 stop position , baud rate:4800 2. The port address of internal register in 8250. Communication line control the 7-site of register (DLAB) =0 ** DLAB=1 3. The internal register form of 8250 a) Communication line control internal register form b) Communication line state register form c) Interrupt Enable register form d) Interrupt identification register form e) MODEM control register and MODEM state register form 4. Initialization programming a) Set baud rate. b) Set communication data form c) Set operation mode
134

AMC-51 Advanced Microcontroller 8051 Trainer

d) Set interrupt enable register

CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect 8250 UNIT CS7 jack to DECODER SECTION-8000H jack using patch cord. b) Connect 8250 UNIT TXD jack to 8250 UNITRXD jack using patch cord. c) Connect 8250 UNIT 8-pins JX3 connector to DECODER SECTION 8-pin JX0 using 8 pin ribbon cable. (Note: - Make sure LSB or PX.0 of source connector should connect to LSB or 0 th bit of destination Connector, where PX = any port). d) Switch ON power supply. 2)
i) j)

Run program:Open respective program 8250.asm in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. k) If zero warning and zero error then Compilation and loading-OK message is displayed. l) Current module window is opened and program is loaded into the kit. Debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution. PROGRAM:
135

AMC-51 Advanced Microcontroller 8051 Trainer

ORG 0000H LJMP START ORG 0080H PDATA EQU 8000H ; define memory location for LINE, L stat etc MSB EQU 8001H LINE EQU 8003H LSTAT EQU 8005H START: MOV SP,#50H MOV A,#43H MOV DPTR,#0FF20H MOVX @DPTR,A MOV A,#1FH INC DPTR MOVX @DPTR,A INC DPTR MOV A,#0CEH MOVX @DPTR,A MOV A,#80H ; DLAB=1 MOV DPTR,#LINE MOVX @DPTR,A MOV A,#18H ; baud rate=4800 MOV DPTR,#8000H MOVX @DPTR,A MOV DPTR,#MSB MOV A,#00H MOVX @DPTR,A MOV A,#03H ; 8-BIT,1-STOP MOV DPTR,#LINE MOVX @DPTR,A MOV A,#00H ; NO-INT MOV DPTR,#8001H MOVX @DPTR,A MOV B,#10H MOV DPTR,#4000H MAIN: PUSH DPH PUSH DPL CALL SEND CALL RCV POP DPL POP DPH MOVX @DPTR,A INC DPTR ; increment DPTR content INC B MOV A,B CJNE A,#00H,MAIN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GOOD: MOV R4,#0A0H CALL BUF1 GOOD1: CALL DIS DJNZ R4,GOOD1 CALL BUF2
136

AMC-51 Advanced Microcontroller 8051 Trainer

GOOD2: CALL DIS SJMP GOOD2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ERR: CALL BUF3 ERR1: CALL DIS SJMP ERR1 BUF1: MOV 7EH,#08H MOV 7DH,#02H MOV 7CH,#05H MOV 7BH,#00H MOV 7AH,#14H MOV 79H,#14H RET BUF2: MOV 7EH,#09H MOV 7DH,#00H MOV 7CH,#00H MOV 7BH,#0DH MOV 7AH,#10H MOV 79H,#10H RET BUF3: MOV 7EH,#08H MOV 7DH,#02H MOV 7CH,#05H MOV 7BH,#00H MOV 7AH,#0EH MOV 79H,#15H RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SEND: MOV DPTR,#LSTAT WAIT1: MOVX A,@DPTR ANL A,#20H JZ WAIT1 MOV A,B MOV DPTR,#PDATA MOVX @DPTR,A RET ;-----------------------------------------------------RCV: MOV DPTR,#LSTAT ; to receive data WAIT2: MOVX A,@DPTR JNB ACC.0,WAIT2 ANL A,#0EH JNZ ERR MOV DPTR,#PDATA MOVX A,@DPTR RET ;--------------------------------------------------------DIS: SETB RS1 MOV R5,#05H SSE2: MOV 30H,#20H
137

AMC-51 Advanced Microcontroller 8051 Trainer

MOV 31H,#7EH MOV R7,#06H SSE1: MOV A,30H CPL A MOV DPTR,#0FF21H MOVX @DPTR,A MOV R0,31H MOV A,@R0 MOV DPTR,#LS0 MOVC A,@A+DPTR MOV DPTR,#0FF22H MOVX @DPTR,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH MOV DPTR,#0FF22H MOVX @DPTR,A DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET LS0: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0CH,89H,7FH,0BFH,8FH END

OUTPUT: Press GO button &observe state on 6digit 7-segment display and after few msec display shows 8250---good message on the 6 digit 7-segment display. This means self-transmitting and self-receiving end. STOP the program using button in software and check the result. The result in 4000H~40EFH unit of data store memory should be 10H~FFH.

138

AMC-51 Advanced Microcontroller 8051 Trainer

139

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 21 8251 Programmable Serial Interface and PC Communication


OBJECTIVE: The communication with PC is achieved by the chip in 8251. CIRCUIT DISCRIPTION: The bus interface section is used to connect 8251a to MCU such as 8051.Note that interface includes an 8 bit bidirectional data bus D0 through D7 driven by data bus buffer. Read its status register, And input USART 8251 or universal synchronous and asynchronous receiver and transmitter. The USART chip integrates both a transmitter and a receiver for serial-data The RS-232 protocol for serial data communication is rather simple. The transmitter is connected to the receiver via just two wires (signal and ground) for unidirectional communication. For bidirectional communication between two devices, two separate unidirectional channels are combined, with the transmitter of one device connected to the receiver of the other device. In this case, two signal wires and a common ground connection are required. Several variants of the protocol are in use, which differ in the actual symbol encoding via voltage levels or currents. The original currentloop encoding used a steady-state current of 20 mA to indicate a passive line and zero amps to indicate an active state. This way, a broken connection between the transmitter and receiver could be detected immediately. In microprocessor systems, it is often more convenient to encode the symbols with voltages. Here, a high level ('1') is used to indicate an inactive line, while a low level ('0') indicates the active state of the line. Often, extra converter chips like the popular MAX-232 driver are used to amplify the output signal of a weak transmitter chip and to protect a microprocessor system from glitches on the external communication line(s). or output character data. Data transfer controlled by control/ data, read ,write & chip select.8251 is located at a specific address of microcomputers memory or I/O address space. Control signals tell the 8251A what type of data transfer is to take place over the bus. The 8251A does not have a built in baud - rate generator. For this reason ,the
140

AMC-51 Advanced Microcontroller 8051 Trainer

clock signal that is used to set baud rate.8251A can be configured for various modes of operation through software. Its operation is controlled through setting of bits in three internal control registers: mode control register, command register & status register. The way in which 8251s receiver & transmitter works is determined by contents of mode control register.8251A has a status register that contains information related to its current state

141

AMC-51 Advanced Microcontroller 8051 Trainer

1. Using the dividing frequency in 8253 as the transceiver clock frequency of 8251.
142

AMC-51 Advanced Microcontroller 8051 Trainer

2. When press key once, the numerical value is sending to PC by 8251 and display the value on screen. 1. 8251 state address 03F9H8251 data address03F8H 2. 8253 command address43H8253 counter #1 address41H 3. 8155 command address0FF20H0FF21H PC0FF23HPB0FF22H 4. Communication Protocolasynchronous mode8 characters, a initial bit, a stop bit, the baud rate factor is 16 and the baud rate is 9600. 5. Calculation T/RXCtransceiver clock fcfc=16*9600=153.6K 6. The distribution factor of 82531843.2K / 153.6K=12.

CIRCUIT DIAGRAM:

PROCEDURE: Connections:a)Connect 8251 UNIT CS8 jack to DECODER SECTION-8000H jack using patch cord. b)Connect 8251 UNIT TXD jack to CZ11user communication port UNIT EX-TXD jack using patch cord. c)Connect 8251 UNIT RXD jack to CZ11user communication port UNIT EX-RXD jack using patch cord.

143

AMC-51 Advanced Microcontroller 8051 Trainer

d)Connect 8251 UNIT 8-pins JX20 connector to DECODER SECTION 8-pin JX17 using 8 pin ribbon cable.
e) f) g) h) i)

j)
k)

l)

Connect 8251 UNIT CLK jack to -1.8432M jack using patch cord. Connect 8251 UNIT T/RXC jack to 8253 SECTION-OUT1 jack using patch cord. Connect 8253 UNIT CLK 1 jack to -1.8432M jack using patch cord Connect 8253 UNIT CS8 jack to DECODER SECTION-9000H jack using patch cord. Connect 8251 UNIT GATE 1 jack to IN-BUILT POWER + 5 V jack using patch cord. Set switch position of SW3,SW4 & SW5 to ON position. PC serial port connect to CZ11 of CZ11user communication port. Switch ON power supply. 3) Run program:m) Open respective program P8251TASM in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. o) If zero warning and zero error then Compilation and loading-OK message is displayed. p) Current module window is opened and program is loaded into the kit.
n)

Debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution. 4. Run Serial Debugging Assistant, set the corresponding serial port and byte rate (9600),when at state P, input 25,press F0/EX ,the LED flash P, press keypadthe PC LED should display corresponding figure. Then press MON, return to state P. Experiment Program List File nameP8251TASMDetailed procedures, see CD-ROM PROGRAM: ORG 0000H LJMP START ORG 0080H Z8251 EQU 8001H D8251 EQU 8000H COM_MODEQU 04EH COM_COMEQU 25H XTC EQU 9003H XT1 EQU 9001H ;-----------------------START: MOV P2,#0FFH MOV A,#43H MOV DPTR,#0FF20H

; define port 2

144

AMC-51 Advanced Microcontroller 8051 Trainer

MOVX @DPTR,A MOV DPTR,#Z8251 MOV A,#COM_MOD MOVX @DPTR,A MOV A, #COM_COM MOVX @DPTR,A LCALL FOR8253 L0: MOV R0,#79H MOV A,#10H LT1: MOV @R0,A INC R0 CJNE R0,#7EH,LT1 MOV A,#11H MOV @R0,A ;MOV R0,#59H MOV A,#7EH ;MOVX @R0,A MOV DPTR,#1059H MOVX @DPTR,A L1: LCALL X2 LCALL SEND CJNE A,#1FH,L3 ;LCALL SEND SJMP L0 L3: LCALL X3 DB 79H,7EH SJMP L2 L2: MOV A,B CLR C SUBB A,#0AH JNC L4 MOV A,B ADD A,#30H SJMP L5 L4: MOV A,B ADD A,#37H L5: ;LCALL SEND SJMP L1 ;-----------------------------X3: MOV R4,A ;MOV R0,#59H ;MOVX A,@R0 MOV DPTR,#01059H MOVX A,@DPTR MOV R1,A MOV A,R4 MOV @R1,A ;mov b,a CLR A POP DPH POP DPL MOVC A,@A+DPTR

; load 10h data in 79h memory location

; load 11h data in 7Eh memory location

; clear data stored in accumulator

145

AMC-51 Advanced Microcontroller 8051 Trainer

INC DPTR CJNE A,01H,X30 CLR A MOVC A,@A+DPTR X31: ;MOVX @R0,A INC DPTR PUSH DPL PUSH DPH MOV DPTR,#01059H MOVX @DPTR,A RET X30: DEC R1 MOV A,R1 SJMP X31 ;---------------------X2: MOV R6,#50H X0: ACALL XLE JNB ACC.5,XX0 DJNZ R6,X0 MOV R6,#20H ;MOV R0,#59H ;MOVX A,@R0 MOV DPTR,#01059H MOVX A,@DPTR MOV R0,A MOV A,@R0 MOV R7,A MOV A,#10H MOV @R0,A X1: ACALL XLE JNB ACC.5,XX1 DJNZ R6,X1 MOV A,R7 MOV @R0,A AJMP X2 XX1: MOV R6,A MOV A,R7 MOV @R0,A MOV A,R6 XX0: RET ;------------------------XLE: ACALL DIS LCALL KEY MOV R4,A ;MOV R1,#48H ;MOVX A,@R1 MOV DPTR,#01048H MOVX A,@DPTR MOV R2,A ;INC R1 ;MOVX A,@R1 MOV DPTR,#01049H

; increment address stored in DPTR ; compare data stored in Accumulator with 01h data ; clear accumulator data

; decrement data stored in R1

; jump if not bit

; decrement jump if not zero data of R6

; Increment R1 data by 1

146

AMC-51 Advanced Microcontroller 8051 Trainer

MOVX A,@DPTR MOV R3,A MOV A,R4 XRL A,R3 MOV R3,04H MOV R4,02H JZ X10 MOV R2,#88H MOV R4,#88H X10: DEC R4 MOV A,R4 XRL A,#82H JZ X11 MOV A,R4 XRL A,#0EH JZ X11 MOV A,R4 ORL A,R4 JZ X12 MOV R4,#20H DEC R2 ; decrement r2 data by 1 SJMP X13 X12: MOV R4,#0FH X11: MOV R2,04H MOV R4,03H X13: ;MOV R1,#48H MOV A,R2 ;MOVX @R1,A MOV DPTR,#01048H MOVX @DPTR,A ;INC R1 MOV A,R3 ;MOVX @R1,A MOV DPTR,#01049H MOVX @DPTR,A MOV A,R4 RET LS3: DB 07H,04H,08H,05H,09H,06H,0AH DB 0BH,01H,00H,02H,0FH,03H,0EH DB 0CH,0DH ;----------------------------------------DIS: PUSH DPH PUSH DPL SETB RS1 MOV R0,#7EH MOV R2,#20H MOV R3,#00H ;MOV DPTR,#LS0 LS2: MOV DPTR,#LS0 MOV A,@R0 MOVC A,@A+DPTR ;MOV R1,#22H
147

AMC-51 Advanced Microcontroller 8051 Trainer

;MOVX @R1,A MOV DPTR,#0FF22H MOVX @DPTR,A MOV A,R2 ;DEC R1 CPL A ;MOVX @R1,A

; complement of accumulator ; move accumulator data in memory location pointed by R1

MOV DPTR,#0FF21H MOVX @DPTR,A CPL A DEC R0 LS1: DJNZ R3,LS1 CLR C RRC A ; rotate to right data stored in accumulator MOV R2,A JNZ LS2 ;INC R1 MOV A,#0FFH ;MOVX @R1,A MOV DPTR,#0FF22H MOVX @DPTR,A CLR RS1 ; clear RS1 POP DPL POP DPH RET LS0: DB 0C0H,0F9H,0A4H,0B0H,99H,92H DB 82H,0F8H,80H,90H,88H,83H,0C6H DB 0A1H,86H,8EH,0FFH,0CH,89H,7FH,0BFH ;-----------------------------------------KEY: SETB RS1 ; loop for key pressed MOV R2,#0FEH MOV R3,#08H MOV R0,#00H LP1: MOV A,R2 ;MOV R1,#21H ;MOVX @R1,A MOV DPTR,#0FF21H MOVX @DPTR,A RL A MOV R2,A ;MOV R1,#23H ;MOVX A,@R1 MOV DPTR,#0FF23H MOVX A,@DPTR CPL A ANL A,#0FH JNZ LP0 INC R0 DJNZ R3,LP1 ;MOVX A,@R1 MOV DPTR,#0FF23H
148

AMC-51 Advanced Microcontroller 8051 Trainer

MOVX A,@DPTR JB ACC.4,XP33 MOV A,#19H SJMP XP3 XP33: MOV A,#20H XP3: CLR RS1 RET LP0: CPL A JB ACC.0,XP0 MOV A,#00H SJMP LPP XP0: JB ACC.1,XP1 MOV A,#08H SJMP LPP XP1: JB ACC.2,XP2 MOV A,#10H SJMP LPP XP2: JB ACC.3,XP33 MOV A,#18H LPP: ADD A,R0 CLR RS1 CJNE A,#10H,LX0 LX0: JNC XP35 MOV DPTR,#LS3 MOVC A,@A+DPTR XP35: RET ;-------------------------------SEND: PUSH ACC MOV DPTR,#Z8251 WAITS:MOVX A,@DPTR RRC A JNC WAITS POP ACC MOV DPTR,#D8251 MOVX @DPTR,A ret FOR8253: MOV DPTR,#XTC MOV A,#76H MOVX @DPTR,A MOV DPTR,#XT1 MOV A,#0CH MOVX @DPTR,A MOV A,#00H MOVX @DPTR,A RET END

; clear RS1

; add data of accumulator &R0

; jump if not carry

OUTPUT: a) Short the two connection COMEXT-C using jumper or shorting link located upside of RS-232 D type 9 pin connector. b) Close the 8051 simulation software and open serial debugging
149

AMC-51 Advanced Microcontroller 8051 Trainer

assistance software SSCOM3.2. Set all the parameter like provided in the following picture. c) Now press the respective keys from 0~9 and A~F from 4X6 MATRIX KEYBOARD. observe the respective no. on the SSCOM3.2software screen and 6 digit 7-segment display. d) Press the MON key then 6 digit 7-segment display shows good on the display and program stops. Press RESET key to exit.

150

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 22 DS18B20 Intelligent Temperature Measure Experiment


OBJECTIVE: To study the working principle and application of DS18B20 temperature sensor. CIRCUIT DISCRIPTION : Temperature control system involved interfacing successive approximation ADC and typical method of measuring and controlling the temperature using microcontroller. ADC is among the most widely used devices for data acquisition. A digital computer uses binary values, but in physical world everything is analog, temperature, pressure, humidity, and velocity are few examples of physical quantities that we seal with every day. Temperature measurement is of great importance in industry as most of the processes are temperature dependent. A number of devices and schemes have been used over the years, for the measurement of temperature. Typical sensors include devices like thermocouples, thermostats, RTDs and semiconductor sensor. This system uses semiconductor sensor AD590 to monitor the temperature of water bath. The AD590 is basically a PTAT (proportional to absolute temperature) current regulator. It generates a current O/P of 1A/K above absolute zero temperature that is -2730C. Thus at 00C the current O/P will be 273A and 250 if will be 298A and 373mV at 1000. This O/p is buffered through an OPAMP having a gain of 10. To enable easy equivalence between the transducers O/P in volts and the measured temperature a calibration procedure needs to be done. Program to read and write DS18B20 and display the read temperature in the 6 bits Digital tube.

151

AMC-51 Advanced Microcontroller 8051 Trainer

CIRCUIT DIAGRAM:

PROCEDURE:
1) Connections: a) Connect DIGITAL TEMPERATURE SENSOR DQ jacks to DECODER SECTION -P1.0 jack using patch cord. b) Switch ON power supply. 2) Run program:Open respective program temp.ASM in 8051 simulation system software.
a)

Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. If zero warning and zero error then Compilation and loading-OK message is displayed. Current module window is opened and program is loaded into the kit. Here debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution.

b)
c)

152

AMC-51 Advanced Microcontroller 8051 Trainer

PROGRAM:
TEMPER_L EQU 29H TEMPER_H EQU 28H FLAG1 EQU 38H ORG 0000H LJMP MAIN ORG 0100H MAIN: MOV SP,#53H MOV P2,#0FFH MOV A,#43H MOV DPTR,#0FF20H MOVX @DPTR,A MOV 7EH,#01H MOV 7DH,#08H MOV 7CH,#0BH MOV 7BH,#14H MOV 7AH,#10H MOV 79H,#10H LOOP: LCALL SSEE LCALL GET_TEMPER ; define memory location for temper-h, temper l & flag1

; initialize port 2 ; load 43 in FF20

MOV A,29H ; load 29 in accumulator MOV C,40H ; load 40 in c RRC A ; rotate data stored in accumulator to right MOV C,41H ; move 41h to c RRC A ; rotate data stored in accumulator to right MOV C,42H ; move 41h to c RRC A MOV C,43H RRC A JNB 43H,POSITIVE CPL A ADD A,#01H ; MOV 7BH,#14H JMP MINUS POSITIVE: MOV 7BH,#15H MINUS: MOV 29H,A CPL P1.0 MOV A,29H MOV R0,#8 MOV R3,#00H MOV R4,#00H MOV R3,A NEXT1: CLR C MOV A,R3 RLC A MOV R3,A MOV A,R4 ADDC A,R4
153

AMC-51 Advanced Microcontroller 8051 Trainer

DA A MOV R4,A DJNZ R0,NEXT1 MOV 50H,A MOV A,50H ;***************************** MOV R0,#79H LCALL PTDS SJMP LOOP ORG 05D0H PTDS: MOV R1,A ACALL PTDS1 MOV A,R1 SWAP A PTDS1: ANL A,#0FH MOV @R0,A INC R0 RET ORG 0200H SSEE: SETB RS1 MOV R5,#08H SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H SSE1: MOV R1,#21H

MOV A,30H CPL A MOVX @R1,A MOV R0,31H MOV A,@R0 MOV DPTR,#DDFF MOVC A,@A+DPTR MOV R1,#22H MOVX @R1,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH MOVX @R1,A DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0F1H,0C6H,092H,0BFH,0B9H

154

AMC-51 Advanced Microcontroller 8051 Trainer

INIT_1820: SETB P1.0 ; SET BIT p1.0 NOP ; NO OPERATION CLR P1.0 ; CLEAR P1, MOV R1,#3 TSR1: MOV R0,#107 DJNZ R0,$ DJNZ R1,TSR1 SETB P1.0 NOP NOP NOP MOV R0,#25H TSR2: JNB P1.0,TSR3 DJNZ R0,TSR2 LJMP TSR4 TSR3: SETB FLAG1 CLR P1.7 LJMP TSR5 TSR4: CLR FLAG1 CLR P1.1 LJMP TSR7 TSR5: MOV R0,#117 TSR6: DJNZ R0,TSR6 TSR7: SETB P1.0 RET GET_TEMPER: SETB P1.0 LCALL INIT_1820 JB FLAG1,TSS2 CLR P1.2 RET TSS2: CLR P1.3 MOV A,#0CCH LCALL WRITE_1820 MOV A,#44H LCALL WRITE_1820 LCALL SSEE LCALL INIT_1820 MOV A,#0CCH LCALL WRITE_1820 MOV A,#0BEH LCALL WRITE_1820 LCALL READ_18200 CLR P1.4 RET

WRITE_1820: MOV R2,#8

; LOOP TO WRITE
155

AMC-51 Advanced Microcontroller 8051 Trainer

CLR C WR1: CLR P1.0 MOV R3,#5 DJNZ R3,$ RRC A MOV P1.0,C MOV R3,#21 DJNZ R3,$ SETB P1.0 NOP DJNZ R2,WR1 SETB P1.0 RET READ_18200: MOV R4,#2 MOV R1,#29H RE00: MOV R2,#8 RE01: CLR C SETB P1.0 NOP NOP CLR P1.0 NOP NOP NOP SETB P1.0 MOV R3,#8 RE10: DJNZ R3,RE10 MOV C,P1.0 MOV R3,#21 RE20: DJNZ R3,RE20 RRC A DJNZ R2,RE01 MOV @R1,A DEC R1 DJNZ R4,RE00 RET END OUTPUT:

; DECREMENT JUMP IF NOT ZERO

; FOR READ OPERATION

Press GO button & observe the 6 digit 7-segment display shows 18b XX, where XX means temperature.

156

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 23 Infrared Communication Experiment


OBJECTIVE: To study the working principle and application of INFRARED COMMUNICATION . CIRCUIT DISCRIPTION : The two basic parts for working with IR are the emitter and the detector. The emitter is typically an LED that emits near-infrared light. A typical wavelength is 880nm, which is just beyond the human eyes ability to see. A typical IR detection system will use two emitters. By controlling when the emitters are active, the detection system can determine simple directional information: Left, Right, or Front. There are several types of detectors for IR light. There are photo-diodes, photo-transistors, and a couple others The HS0038B series are miniaturized receivers for infrared remote control systems. PIN diode and preamplifier are assembled on lead frame, the epoxy package is designed as IR filter.The demodulated output signal can directly be decoded by a microprocessor. HS0038B is the standard IR remote control receiver series, supporting all major transmission codes.14 500 Features _ Photo detector and preamplifier in one package _ Internal filter for PCM frequency _ TTL and CMOS compatibility _ Output active low _ Improved shielding against electrical field disturbance _ Suitable burst length .10 cycles/burst _ Low power consumption _ High immunity against ambient light _ Continuous data transmission possible
(800 bit/s)CIRCUIT

DIAGRAM:

PROCEDURE: 1) Connections:-

157

AMC-51 Advanced Microcontroller 8051 Trainer

Connect INFRARED RECEIVER HOUT jacks to DECODER SECTION-P3.2 jack using patch cord. b) Connect BUZZER SP jacks to DECODER SECTION-P1.5 jack using patch cord. c) Check battery cell in the remote. d) Switch ON power supply.
a)

2) Run program:a) Open respective program IR_new.ASM in 8051 simulation system software.
b)

c)
d)

Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. If zero warning and zero error then Compilation and loading-OK message is displayed. Current module window is opened and program is loaded into the kit. Debug the whole program step by step using debug tool set or press GO button program execution. Use Stop button to stop the execution. for

PROGRAM: ORG 0000H AJMP MAIN ORG 0003H AJMP INT ORG 100H a_bit EQU 20H b_bit EQU 21H

; define a-bit ; define b-bit

MAIN: MOV SP,#60H MOV P2,#0FFH ; define port 2 MOV A,#43H MOV DPTR,#0FF20H MOVX @DPTR,A SETB EA ; set EA SETB IT0 ; set bit IT0 SETB EX0 ; set bit EX0 MOV R4,#00H MOV a_bit,#0FFh ; load FFh to a-BIT MOV b_bit,#14H ; load 14h to b-bit LOOP: ACALL SSEE AJMP LOOP SSEE: SETB RS1 MOV R5,#05H SSE2: MOV 30H,#02H MOV 31H,#21H MOV R7,#02H SSE1: MOV A,30H CPL A` ; set bit RS1

; complement of data stored in A


158

AMC-51 Advanced Microcontroller 8051 Trainer

MOV DPTR,#0FF21H MOVX @DPTR,A MOV R0,31H MOV A,@R0 MOV DPTR,#TAB MOVC A,@A+DPTR MOV DPTR,#0FF22H MOVX @DPTR,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH MOV DPTR,#0FF22H MOVX @DPTR,A DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET

;T o display data

; rotate rite data stored in accumulator ; decrement data stored in 31h

TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0CH,89H,0DEH,08CH PDS: PUSH ACC CJNE A,#0AH,A1 MOV A,#11H JMP PDS1 A1: CJNE A,#01H,A2 MOV A,#22H JMP PDS1 A2: CJNE A,#11H,A3 MOV A,#01H JMP PDS1 A3: CJNE A,#12H,A4 MOV A,#02H JMP PDS1 A4: CJNE A,#13H,A5 MOV A,#03H JMP PDS1 A5: CJNE A,#14H,A6 MOV A,#04H JMP PDS1 A6: CJNE A,#15H,A7 MOV A,#05H JMP PDS1 A7: CJNE A,#16H,A9 MOV A,#06H JMP PDS1 A9: CJNE A,#17H,A10 MOV A,#07H JMP PDS1 A10: CJNE A,#18H,A11
159

AMC-51 Advanced Microcontroller 8051 Trainer

MOV A,#08H JMP PDS1 A11: CJNE A,#19H,A12 MOV A,#09H JMP PDS1 A12: CJNE A,#10H,A13 MOV A,#00H JMP PDS1 A13: CJNE A,#1AH,A14 MOV A,#0AH JMP PDS1 A14: CJNE A,#1BH,A15 MOV A,#0BH JMP PDS1 A15: CJNE A,#0EH,A16 MOV A,#0CH JMP PDS1 A16: CJNE A,#02H,A17 MOV A,#0DH JMP PDS1 A17: CJNE A,#03H,A18 MOV A,#0EH JMP PDS1 A18: CJNE A,#1CH,A19 MOV A,#0FH JMP PDS1 A19: NOP PDS1: MOV B,A ANL A,#0FH MOV a_bit,A POP ACC MOV A,B SWAP A ANL A,#0FH MOV b_bit,A RET

INT: CLR EA MOV R6,#10 SB: ACALL YS1 JB P3.2,EXIT DJNZ R6, SB JNB P3.2,$ ACALL YS2 MOV R7,#26 JJJJA: JNB P3.2,$ LCALL YS1 MOV C,P3.2

; loop for interrupt

160

AMC-51 Advanced Microcontroller 8051 Trainer

JNC UUUA LCALL YS3 UUUA: DJNZ R7,JJJJA MOV R1,#1AH MOV R2,#2 PP: MOV R3,#8 JJJJ: JNB P3.2,$ LCALL YS1 MOV C,P3.2 JNC UUU LCALL YS3 UUU: MOV A,@R1 RRC A MOV @R1,A DJNZ R3,JJJJ INC R1 DJNZ R2,PP MOV A,1AH CPL A CJNE A,1BH,EXIT MOV A,1AH ACALL PDS CLR P1.5 LCALL YS2 LCALL YS2 LCALL YS2 SETB P1.5 EXIT: SETB EA RETI YS1: MOV R4,#20 ; loop for delay D1: MOV R5,#19 DJNZ R5,$ DJNZ R4,D1 RET YS2: MOV R4,#10 D2: MOV R5,#216 DJNZ R5,$ DJNZ R4,D2 RET YS3: MOV R4,#2 D3: MOV R5,#230 DJNZ R5,$ DJNZ R4,D3 RET END OUTPUT: Press GO button &observe the 6 digit 7-segment display shows PX. Where X=pressed remote button. When press the remote button from 0 to F, F1 and F2 it display the corresponding beep from buzzer and digit on the display.
161

AMC-51 Advanced Microcontroller 8051 Trainer

Sr. no. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Remote key When program is downloaded F1 F2 1 2 3 4 5 6 7 8 9 0 A B C D E F

Program output P 11 22 01 02 03 04 05 06 07 08 09 00 0A 0B 0C 0D 0E 0F

162

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 24 TL549 Serial A/D Conversion Experiment


OBJECTIVE: To study the interfacing of TL549 with microcontroller CIRCUIT DISCRIPTION: The TLC548 and TLC549 are CMOS analog-to-digital converter (ADC) integrated circuits built around an 8-bit switched-capacitor successive-approximation ADC. These devices are designed for serial interface with a microcontroller or peripheral through a 3-state data output and an analog input. The TLC548 and TLC549 use only the input/output clock (I/O CLOCK) input along with the chip select (CS) input for data control. The maximum I/O CLOCK input frequency of the TLC548 is 2.048 MHz, and the I/O CLOCK input frequency of the TLC549 is specified up to 1.1 MHZ. Operation of the TLC548 and the TLC549 is very similar to that of the more complex TLC540 and TLC541 devices; however, the TLC548 and TLC549 provide an on-chip system clock that operates typically at 4 MHz and requires no external components. The on-chip system clock allows internal device operation to proceed independently of serial input/output data timing and permits manipulation of the TLC548 and TLC549 as desired for a wide range of software and hardware requirements. The I/O CLOCK together with the internal system clock allow high-speed data transfer and conversion rates of 45 500 conversions per second for the TLC548, and 40 000 conversions per second for the TLC549. Additional TLC548 and TLC549 features include versatile control logic, an on-chip sample-and-hold circuit that can operate automatically or under microcontroller control, and a high-speed converter with differential high-impedance reference voltage inputs that ease ratio metric conversion, scaling, and circuit isolation from logic and supply noises. . CIRCUIT DIAGRAM:

163

AMC-51 Advanced Microcontroller 8051 Trainer

PROCEDURE: 1) Connections:a) Connect Serial A/D Device-CS jacks to DECODER SECTION-P1.0 jack using patch cord. b) Connect Serial A/D Device-CLK jacks to DECODER SECTION-P1.6 jack using patch cord. c) Connect Serial A/D Device-D0 jacks to DECODER SECTION-P1.7 jack using patch cord. d) Connect ADJUSTABLE VOLTAGE -VIN jacks to IN BUILT POWER +5V jack using patch cord. e) Connect ADJUSTABLE VOLTAGE VOUT jacks to Serial A/D Device- AIN jack using patch cord. f) Switch ON power supply. 2) Run program:a) Open respective program ADC_ser.ASM in 8051 simulation system software.
b)

c)
d)

Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. If zero warning and zero error then Compilation and loading-OK message is displayed. Current module window is opened and program is loaded into the kit. Here you can debug the whole program step by step using debug tool set or you can press for program execution. Use Stop button to stop the execution.

GO button PROGRAM:

SDA EQU P1.7 ; SERIAL DATA OUT SCL EQU P1.6 ; I/O CLOCK CS EQU P1.0 ; CS MTD EQU 30H MRD EQU 40H ORG 0000H LJMP SE11 ORG 0590H SE11: MOV SP,#53H MOV P2,#0ffh MOV A,#43H MOV DPTR,#0FF20H MOVX @DPTR,A
164

AMC-51 Advanced Microcontroller 8051 Trainer

MOV 7EH,#05H MOV 7DH,#04H MOV 7CH,#09H MOV 7BH,#14H MOV 7AH,#10H MOV 79H,#10H LO18: LCALL SSEE CLR CS ; CLEAR Cs LCALL RDBYTE ; READ BYTE SETB CS ; SET BIT cs NOP ; NO OPERATION ;NOP NOP NOP NOP NOP NOP MOV R0,#79H LCALL PTDS SJMP LO18 ORG 05D0H PTDS: MOV R1,A ACALL PTDS1 MOV A,R1 SWAP A PTDS1: ANL A,#0FH MOV @R0,A INC R0 RET ORG 0D50H SSEE: SETB RS1 MOV R5,#05H SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H SSE1: MOV R1,#21H MOV A,30H CPL A MOVX @R1,A MOV R0,31H MOV A,@R0 MOV DPTR,#DDFF MOVC A,@A+DPTR MOV R1,#22H MOVX @R1,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH MOVX @R1,A ; exchange data stored in accumulator ; anding 0Fh with data stored in accumulator ; Increment R0 ; set bit RS1

165

AMC-51 Advanced Microcontroller 8051 Trainer

DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0F1H,0C6H,092H,0BFH RDBYTE: MOV R0,#08H RLP: SETB SDA ; SDA 7 SCL both high SETB SCL MOV C,SDA ; load SDA in C MOV A,R2 CLR SCL ; clear SCL RLC A ; rotate with carry data stored in accumulator MOV R2,A ; load data from accumulator CLR SCL ; clear SCL DJNZ R0,RLP ; decrement jump if not zero RET END

OUTPUT: press GO button &observe the 6 digit 7-segment display shows 549-00 to 549FF as per voltage applied to serial ADC input using POT.

166

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 25 TL5615 Serial D/A Conversion Experiment


OBJECTIVE: 1. To know the basic principle of serial D/A conversion 2. To know the program and connect of 10 bit serial D/A converter. CIRCUIT DISCRIPTION: The TLC5615 is a 10-bit voltage output digital-to-analog converter (DAC) with a buffered reference input (high impedance). The DAC has an output voltage range that is two times the reference voltage, and the DAC is monotonic. The device is simple to use, running from a single supply of 5 V. A power-on-reset function is incorporated to ensure repeatable start-up conditions. Digital control of the TLC5615 is over a threewire serial bus that is CMOS compatible and easily interfaced to industry standard microprocessor and microcontroller devices. The device receives a 16-bit data word to produce the analog output. The digital inputs feature Schmitt triggers for high noise immunity.

167

AMC-51 Advanced Microcontroller 8051 Trainer

CIRCUIT DIAGRAM:

PROCEDURE:
168

AMC-51 Advanced Microcontroller 8051 Trainer

1)

Connections: a) Connect Serial D/A Device-/CS jacks to DECODER SECTION-P1.0 jack using patch cord. b) Connect Serial D/A Device-SCLK jacks to DECODER SECTION-P1.1 jack using patch cord. c) Connect Serial D/A Device-DIN jacks to DECODER SECTION-P1.2 jack using patch cord. d) Connect Serial D/A Device -OUT jacks to DC MOTOR DJ jack using patch cord. e) Switch ON power supply. Run program: Open respective program DAC_ser.ASM in 8051 simulation system software.
2) a) b)

Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit. Debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution. PROGRAM: ;************************************************************ ORG 0000H LJMP SE13 ORG 0100H SE13: MOV SP,#53H MOV P2,#0ffh ; define port2 MOV A,#43H MOV DPTR,#0FF20H ; load 43 in memory location FF20 MOVX @DPTR,A MOV 7EH,#14H MOV 7DH,#14H MOV 7CH,#14H LOOP: MOV R4,#00H MOV R5,#00H ;LJMP L2 L1: INC R5 ; Increment R5 MOV A,R5 ; load data from R5 to accumulator RLC A ; rotate left with carry data stored in accumulator MOV R7,A ; load data from accumulator to R7 MOV A,R4 RLC A MOV R6,A MOV A,R7
169

AMC-51 Advanced Microcontroller 8051 Trainer

RLC A MOV R7,A MOV A,R6 RLC A MOV R6,A MOV A,R5 MOV R0,#79H LCALL PTDS MOV A,R4 ANL A,#03H MOV @R0,A LCALL SSEE MOV R2,#05H LCALL DELYA

; call delay

LO21: CLR P1.1 ; SLCLK SETB P1.0 ; CS CLR P1.2 ; DIN NOP ; no operation NOP CLR P1.0 MOV R2,#4 SWAP A ; exchange data stored in accumulator LCALL WRDATA MOV R2,#8 MOV A,R7 LCALL WRDATA ; write data CLR P1.1 ; reset sclk SETB P1.0 CJNE R5,#0FFH,L1 MOV R5,#00H INC R4 CJNE R4,#04H,L1 MOV R5,#0FFH MOV R4,#03H L2: DEC R5 MOV A,R5 MOV R7,A MOV A,R4 RLC A MOV R6,A MOV R7,A MOV A,R6 RLC A MOV R6,A MOV R0,#79H LCALL PTDS MOV A,R4 ANL A,#03H MOV @R0,A LCALL SSEE MOV R2,#05H
170

AMC-51 Advanced Microcontroller 8051 Trainer

LO22:

CLR P1.1 ; SLCLK SETB P1.0 ; CS CLR P1.2 ; DIN NOP NOP CLR P1.0 MOV R2,#4 MOV A,R6 SWAP A LCALL WRDATA MOV R2,#8 MOV A,R7 LCALL WRDATA CLR P1.1 SETB P1.0 CJNE R5,#00H,L2 MOV R5,#0FFH DEC R4 CJNE R4,#00H,L2 LJMP LOOP ;********************************************************* PTDS: MOV R1,A LCALL PTDS1 MOV A,R1 SWAP A PTDS1: ANL A,#0FH MOV @R0,A INC R0 RET ORG 0D50H SSEE: SETB RS1 MOV R5,#05H SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H SSE1: MOV R1,#21H MOV A,30H CPL A MOVX @R1,A MOV R0,31H MOV A,@R0 MOV DPTR,#DDFF MOVC A,@A+DPTR MOV R1,#22H MOVX @R1,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH MOVX @R1,A
171

AMC-51 Advanced Microcontroller 8051 Trainer

DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0F1H,0C6H,092H,0BFH,0B9H WRDATA: NOP ; loop for write LOOPA: RLC A ; rotate left with carry MOV P1.2,C CLR P1.1 ; clear p1.1 NOP ; no operation SETB P1.1 ; setbit P1.1 RET DELYA: PUSH 02H ; loop for delay DELYB: PUSH 02H DELYC: PUSH 02H DELYD: DJNZ R2,DELYD LCALL SSEE POP 02H DJNZ R2,DELYC POP 02H DJNZ R2,DELYB POP 02H DJNZ R2,DELYA RET END OUTPUT: Press GO button & observe the 6 digit 7-segment display shows count from --000 (which is equal to 0V) to ---3FF (which is equal to almost 5V) that controls the DC motor speed variation.

172

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 26 PCF8563 Real Time Clock/Calendar Experiment


OBJECTIVE: To study interfacing of PCF8563 with microcontroller(RTC) CIRCUIT DISCRIPTION: The PCF8563 is a CMOS1 Real-Time Clock (RTC) and calendar optimized for low power consumption. A programmable clock output, interrupt output, and voltage-low detector are also provided. All addresses and data are transferred serially via a two-line bidirectional I2C-bus. Maximum bus speed is 400 kbit/s. The register address is incremented

Register organization

173

AMC-51 Advanced Microcontroller 8051 Trainer

174

AMC-51 Advanced Microcontroller 8051 Trainer

The PCF8563 contains sixteen 8-bit registers with an auto-incrementing register address, an on-chip 32.768 kHz oscillator with one integrated capacitor, a frequency divider which provides the source clock for the Real-Time Clock (RTC) and calendar, a programmable clock output, a timer, an alarm, a voltage-low detector, and a 400 kHz I2C-bus interface. All 16 registers are designed as addressable 8-bit parallel registers although not all bits are implemented. The first two registers (memory address 00h and 01h) are used as control and/or status registers. The memory addresses 02h through 08h are used as counters for the clock function (seconds up to years counters). Address locations 09h through 0Ch contain alarm registers which define the conditions for an alarm. Address 0Dh controls the CLKOUT output frequency. 0Eh and 0Fh are the Timer_ control and Timer registers, respectively. The Seconds, Minutes, Hours, Days, Months, Years as well as the Minute_ alaram,
175

AMC-51 Advanced Microcontroller 8051 Trainer

Hour_ alarm, and Day_ alarm registers are all coded in Binary Coded Decimal (BCD) format. When one of the RTC registers is written or read, the contents of all time counters are frozen. Therefore, faulty writing or reading of the clock and calendar during a carry condition is prevented. 2 to 0 N 000[2] unused Table 6. Control_status_2 - control and status register 2 (address 01h) bit description Bit Symbol Value Description Reference 7 to 5 N 000[1] unused 4 TI_TP 0[2] INT is active when TF is active (subject to the status of TIE) Section 8.3.2.1 and Section 8.8 1 INT pulses active according to Table 7 (subject to the status of TIE); Remark: note that if AF and AIE are active then INT will be permanently active 3 AF 0[2] read: alarm flag inactive Section 8.3.2.1 write: alarm flag is cleared 1 read: alarm flag active write: alarm flag remains unchanged 2 TF 0[2] read: timer flag inactive write: timer flag is cleared 1 read: timer flag active write: timer flag remains unchanged 1 AIE 0[2] alarm interrupt disabled 1 alarm interrupt enabled 0 TIE 0[2] timer interrupt disabled 1 timer interrupt enabled PCF8563 All Recommended method for reading the time: 1. Send a START condition and the slave address for write (A2h). 2. Set the address pointer to 2 (VL_ seconds) by sending 02h. 3. Send a RESTART condition or STOP followed by START. 4. Send the slave address for read (A3h). 5. Read VL_ second. 6. Read Minutes. 7. Read Hours. 8. Read Days. 9. Read Weekdays. 10. Read Century_ months. 11. Read Years. 12. Send a STOP condition.

176

AMC-51 Advanced Microcontroller 8051 Trainer

automatically after each written or read data byte. CIRCUIT

DIAGRAM:

PROCEDURE: 1) Connections:a) Connect Real Time Clock / Calendar- SDA jacks to DECODER SECTION-P1.7 jack using patch cord. b) Connect Real Time Clock / Calendar- SCL jacks to DECODER SECTION-P1.6 jack using patch cord. c) Connect SWITCH INPUT UNITK1 jacks to DECODER SECTION P1.0 jack using patch cord. d) Switch ON power supply. 2)
a)

Run program:Open respective program RTC.ASM in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit.
b)

Debug the whole program step by step using debug tool set or GO button program execution. Use Stop button to stop the execution. PROGRAM: SDA SCL MTD MRD PCF8563 ACK SLA SUBA NUMBYTE BIT P1.7 BIT P1.6 EQU 30H EQU 40H EQU 0A2H BIT 10H DATA 50H DATA 51H DATA 52H ; serial data bit ; serial clock

for

; define address for 8563 to select ; acknowledge bit

177

AMC-51 Advanced Microcontroller 8051 Trainer

ORG 0000H AJMP MAIN ORG 0100H MAIN: MOV R4,#0F0H DJNZ R4,$ SETB EA ; interrupt enable SETB EX0 ; set bit EX0 mov p2,#0ffh ; define port2 MOV A,#43H MOV DPTR,#0FF20H MOVX @DPTR,A ;LJMP RD8563 SET8563: MOV MTD,#00H ; value of control register MOV MTD+1,#00H ; value of control register MOV MTD+2,#30H MOV MTD+3,#07H MOV MTD+4,#10H MOV MTD+5,#27H MOV MTD+6,#02H MOV MTD+7,#12H MOV MTD+8,#05H MOV SLA,#PCF8563 MOV SUBA,#00H MOV NUMBYTE,#9 LCALL IWRNBYTE NOP RD8563: MOV SUBA,#02H ; second MOV SLA,#PCF8563 MOV NUMBYTE,#7 LCALL IRDNBYTE MOV A,MRD ANL A,#7FH ; to give second MOV MRD,A ; to read MOV A, MRD+1 ANL A,#7FH ; to give minutes MOV MRD+1,A MOV A, MRD+2 ; to read minutes ANL A,#3FH MOV MRD+2,A MOV A, MRD+3 ; to read hours ANL A,#3FH ; condition for hours MOV MRD+3,A MOV A, MRD+4 ; to read weekday ANL A,#07H ; condition for weekday MOV MRD+4,A MOV A,MRD+5 ANL A,#9FH MOV MRD+5,A NOP
178

AMC-51 Advanced Microcontroller 8051 Trainer

AA:

JNB P1.0,AA LJMP BB LCALL SSEE MOV A,MRD MOV R1,A ANL A,#0FH MOV 79H,A MOV A,R1 SWAP A ANL A,#0FH MOV 7AH,A MOV A,MRD+1 MOV R1,A ANL A,#0FH MOV 7BH,A MOV A,R1 SWAP A ANL A,#0FH MOV 7CH,A MOV R1,A ANL A,#0FH MOV 7DH,A MOV A,R1 SWAP A ANL A,#0FH MOV 7EH,A LCALL SSEE LJMP RD8563 LCALL SSEE MOV A,MRD+3 MOV R1,A ANL A,#0FH MOV 79H,A MOV A,R1 SWAP A ANL A,#0FH MOV 7AH,A MOV A,MRD+5 MOV R1,A ANL A,#0FH MOV 7BH,A MOV A,R1 SWAP A ANL A,#0FH MOV 7CH,A MOV A,MRD+6

; jump if not bit to AA

BB:

179

AMC-51 Advanced Microcontroller 8051 Trainer

MOV R1,A ANL A,#0FH MOV 7DH,A MOV A,R1 SWAP A ANL A,#0FH MOV 7EH,A LCALL SSEE LJMP RD8563 SSEE: SETB RS1 MOV R5,#08H SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H SSE1: MOV R1,#21H MOV A,30H CPL A MOVX @R1,A MOV R0,31H MOV A,@R0 MOV DPTR,#DDFF MOVC A,@A+DPTR MOV R1,#22H MOVX @R1,A MOV A,30H RR A MOV 30H,A DEC 31H MOV A,#0FFH MOVX @R1,A DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0F1H,0C6H,092H,0BFH

START: SETB SDA NOP SETB SCL NOP NOP NOP NOP NOP CLR SDA NOP NOP

; to start- condition

180

AMC-51 Advanced Microcontroller 8051 Trainer

NOP NOP NOP CLR SCL NOP RET STOP: CLR SDA NOP SETB SCL NOP NOP NOP NOP NOP SETB SDA NOP NOP NOP NOP RET MACK: CLR SDA NOP NOP SETB SCL NOP NOP NOP NOP NOP CLR SCL NOP NOP RET MNACK: SETB SDA NOP NOP SETB SCL NOP NOP NOP NOP NOP CLR SCL NOP NOP RET ; ; to stop -condition

; acknowledge

181

AMC-51 Advanced Microcontroller 8051 Trainer

CACK: SETB SDA NOP NOP SETB SCL CLR ACK NOP NOP MOV C,SDA JC CEND SETB ACK CEND: NOP CLR SCL NOP RET

WRBYTE: MOV R0,#08H WLP: RLC A JC WR1 SJMP WR0 WLP1: DJNZ R0,WLP NOP RET WR1: SETB SDA NOP SETB SCL NOP NOP NOP NOP NOP CLR SCL SJMP WLP1 WR0: CLR SDA NOP SETB SCL NOP NOP NOP NOP NOP CLR SCL SJMP WLP1

; to write byte

182

AMC-51 Advanced Microcontroller 8051 Trainer

RDBYTE: MOV R0,#08H RLP: SETB SDA NOP SETB SCL NOP NOP NOP NOP NOP NOP NOP MOV MOV CLR RLC MOV NOP NOP NOP NOP NOP NOP NOP NOP C,SDA A,R2 SCL A R2,A

; to read byte

; +1 ; +1 ; +1 ; +1 ; +1

; no operation ; +1 ; +1 ; +1 ; +1 ; +1

DJNZ R0,RLP RET

IWRBYTE: PUSH ACC IWBLOOP: LCALL START MOV A,SLA LCALL WRBYTE LCALL CACK JNB ACK,RETWRB POP ACC LCALL WRBYTE LCALL CACK LCALL STOP RET RETWRB: POP ACC LCALL STOP RET IRDBYTE: LCALL START
183

AMC-51 Advanced Microcontroller 8051 Trainer

MOV A,SLA INC A LCALL WRBYTE LCALL CACK JNB ACK,RETRDB LCALL RDBYTE LCALL MNACK RETRDB: LCALL STOP RET IWRNBYTE: MOV A,NUMBYTE MOV R3,A LCALL START MOV A,SLA LCALL WRBYTE LCALL CACK JNB ACK,RETWRN MOV A,SUBA LCALL WRBYTE LCALL CACK MOV R1,#MTD WRDA: MOV A,@R1 LCALL WRBYTE LCALL CACK JNB ACK,IWRNBYTE INC R1 DJNZ R3,WRDA RETWRN: LCALL STOP RET IRDNBYTE: MOV R3,NUMBYTE LCALL START MOV A,SLA LCALL WRBYTE LCALL CACK JNB ACK,RETRDN MOV A,SUBA LCALL WRBYTE LCALL CACK LCALL START MOV A,SLA INC A LCALL WRBYTE LCALL CACK JNB ACK,IRDNBYTE MOV R1,#MRD RDN1: LCALL RDBYTE MOV @R1,A ;NOP ;NOP DJNZ R3,SACK
184

AMC-51 Advanced Microcontroller 8051 Trainer

LCALL MNACK RETRDN: LCALL STOP SACK: LCALL MACK INC R1 SJMP RDN1

IWRNBYTEEXT: MOV A,NUMBYTE MOV R3,A LCALL START MOV A,SLA LCALL WRBYTE LCALL CACK JNB ACK,RETWRNE MOV R1,#MTD WRDAE: MOV A,@R1 LCALL WRBYTE LCALL CACK JNB ACK,RETWRNE INC R1 DJNZ R3,WRDAE RETWRNE: LCALL STOP RET IRDNBYTEEXT: MOV R3,NUMBYTE LCALL START MOV A,SLA INC A LCALL WRBYTE LCALL CACK JNB ACK,RETRDNE MOV R1,#MRD RDNE1: LCALL RDBYTE MOV @R1,A DJNZ R3,SACKE LCALL MNACK RETRDNE: LCALL STOP RET SACKE: LCALL MACK INC R1 SJMP RDNE1 END

OUTPUT: 185

AMC-51 Advanced Microcontroller 8051 Trainer

Press GO button & observe when K1 switch is at low level, then 6 digit 7segment display shows hour, minute, second and when K1 at high level, then it shows year, month, date. Discussion Do the Modification in program, the CLKOUT output frequency of user want and set alarm register.

186

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 27 MAX813l Watch Dog Replacement Circuit


OBJECTIVE: To study watch dog timer and its applications. CIRCUIT DISCRIPTION: The MAX813L microcontroller supervisory circuits reduce the complexity and number of components required to monitor power-supply and battery functions in microcontroller systems. These devices significantly improve system reliability and accuracy compared to separate ICs or discrete components. The MAX813L provide four functions: 1) A reset output during power-up, power-down, and brownout conditions. 2) An independent watchdog output that goes low if the watchdog input has not been toggled within 1.6 seconds. 3) A 1.25V threshold detector for power-fail warning, low-battery detection, or for monitoring a power supply other than +5V. The 4)MAX813L generate a reset pulse when the supply voltage drops below 4.65V. PROCEDURE: MAX706/MAX708 generate a reset pulse below 4.40V. 1.MAX 813L has the function of power, power down reset: Connect MAX813L reset output to chip RESET directly. If need low LEVEL valid output, which can be connected add inverter output. 2. Manual reset: The manually reset input (/MR) allow reset to a keyboard switch. The switch eliminate the instability by the least 140ms reset impulse./MR and TTL/CMOS are logical compatible, which can be drive by a external logical line .Connect manual reset /MR to switch K1, socket RESET to LED L1.Press switch K1,to observe a high impulse of continue 200ms. 3.Watch dog timer: MAX813L watch god monitor the operation of microprocessor. If the microprocessor in 1.6S do not trigger WDI and WDI does not have three states, the /WDO should be low LEVEL. If RESET effective or input three states, the WATCHDOG timer will be reset with no count. If release reset signal, and WDI drive by high or low LEVEL, the timer will be count and check the 50ns impulse. A:Take WDI hang in the air,/WDO output remain to the high LEVEL. Connect WDI to switch K1,/WDO to LED L1.When K1 is remain to the high or low LEVEL with above
187

AMC-51 Advanced Microcontroller 8051 Trainer

1.6S,/WDO would convert from high LEVEL to low LEVEL. B:Connect /MR to /WDO, WDI to switch K1, RESET to LED L1. When K1 is remain to the high or low LEVEL with above 1.6S, RESET would generate a reset signal, you can observe by L1. 4. Comparator power failure Connect PFI to output AOUT1 regulation resistance, /PFO to LED L1, adjust regulation resistance. When LEVEL lower than 1.25V, the /PFO convert from high LEVEL to low LEVEL.L1 light. .

188

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 28 Voltage / Frequency Convert Experiment


OBJECTIVE: To study working principle & interfacing of IC KK331 with microcontroller. CIRCUIT DISCRIPTION: This voltage to frequency converter provides the output pulse train at a frequency precisely proportional to the applied input voltage. The KA331 can operate at power supplies as low as 4.0V and be changed output frequency from 1Hz to 100KHz. It is ideally suited for use in simple low-cost circuit for analog-to digital conversion, long term integration, linear frequency modulation or demodulation, frequency-to-voltage conversion, and many other functions. Features: Guaranteed linearity: 0.01% max. Low power dissipation: 15mW at 5V Wide range of full scale frequency: 1Hz to 100KHz Pulse output compatible with all logic forms Wide dynamic range: 100dB min at 10KHz full scale Trimmer is used as a input for IC KK 331.Frequency is getting at pin FREQ. CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect ADJUSTABLE VOLTAGE UNITVIN jacks to IN BUILT POWER- + 5V jack using patch cord. b) Connect ADJUSTABLE VOLTAGE UNITVOUT jacks to V/FUNIT- VIN0 jack using patch cord. c) Connect V/FUNIT FOUT jacks to DECODER SECTION- P3.5 jack using patch cord. d) Switch ON power supply.
189

AMC-51 Advanced Microcontroller 8051 Trainer

2)
a)

Run program:Open respective program vtof.ASM in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit.
b)

Debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution. PROGRAM: ORG LJMP MAIN ORG 000BH LJMP CLK MAIN: ;TIM0 interrupt input address! 0000H

ORG 0100H MOV P2,#0FFH ; define port2 MOV A,#43H MOV DPTR,#0FF20H MOVX @DPTR,A SETB EA ; set bit EA,ET0,EX0 & IT0 SETB ET0 SETB EX0 SETB IT0 MOV TMOD,#51H ; use as counter MOV TH0,#04CH ; load data 4c in timer MOV TL0,#00H MOV TH1,#00H MOV TL1,#00H SETB TR0 ; set timer 0 SETB TR1 ; set timer 1 MOV 50H,#00H MOV 51H,#00H LOOP0: MOV R2,50H MOV R3,51H LCALL LOOP1 MOV R0,#79H MOV A,R6 LCALL PTDS MOV A,R5 LCALL PTDS MOV A,R4 LCALL PTDS LCALL SSEE SJMP LOOP0 LOOP1: CLR A
190

AMC-51 Advanced Microcontroller 8051 Trainer

MOV R4,A MOV R5,A MOV R6,A MOV R7,#10H LOOP2: CLR C MOV A,R3 RLC A MOV R3,A MOV A,R2 RLC A MOV R2,A MOV A,R6 ADDC A,R6 DA A MOV R6,A MOV A,R5 ADDC A,R5 DA A MOV R5,A MOV A,R4 ADDC A,R4 DA A MOV R4,A DJNZ R7,LOOP2 RET PTDS: MOV R1,A ACALL PTDS1 MOV A,R1 SWAP A PTDS1: ANL A,#0FH MOV @R0,A INC R0 RET

; exchange data

SSEE: SETB RS1 MOV R5,#08H SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H SSE1: MOV R1,#21H MOV A,30H CPL A MOVX @R1,A MOV R0,31H MOV A,@R0 MOV DPTR,#DDFF MOVC A,@A+DPTR MOV R1,#22H MOVX @R1,A MOV A,30H RR A MOV 30H,A
191

AMC-51 Advanced Microcontroller 8051 Trainer

DEC 31H MOV A,#0FFH MOVX @R1,A DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0CH,89H,0DEH CLK: CLR TR0 ; timer 0 reset MOV TH0,#04CH ; timer time is 4c00h MOV TL0,#00H CPL P1.1 ; complement p1.1 INC 41H ; increment data of 41h memory location MOV A,41H CJNE A,#20,WWW MOV 41H,#00H CPL P1.0 ; complement p1.0 MOV 50H,TH1 MOV 51H,TL1 MOV TL1,#00H MOV TH1,#00H WWW: SETB TR0 ; set bit timer 0 reset bit RETI END OUTPUT: Press GO button & observe the frequency reading in Hz on the 6 digit 7-segment display. Vary the applied input voltage using POT & see respective change in frequency reading on display. Note down the various reading at various input voltage. For comparison , connect the multi-meter at VIN0 and CRO at FOUT port of V to F Unit.

192

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 29 Serial Memoryory Chip 93C46 R/W Experiment


OBJECTIVE: To study working principle & interfacing of 93c46 with microcontroller. CIRCUIT DISCRIPTION: The Microchip Technology Inc. 93LC46B/56B/66B are1K, 2K and 4K low voltage serial Electrically Erasable PROMs. The device memory is configured as x16. Using the function of serial memory chip 93C46.Firstly, write 8 digital into 93C46,then read them one by one. Secondly, memory in internal RAM30H~37H unit. Finally, send the value of 30H~37H return to P1 port. The P1 port LED L1~L8 will be lighted one by one , to realize a right shift effect of lights. CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect SERIAL EEPROM UNIT CS jacks to DECODER SECTION- P3.0 jack using patch cord. b) Connect SERIAL EEPROM UNIT SK jacks to DECODER SECTION- P3.1 jack using patch cord.
193

AMC-51 Advanced Microcontroller 8051 Trainer

Connect SERIAL EEPROM UNIT DI jacks to DECODER SECTION- P3.2 jack using patch cord. d) Connect SERIAL EEPROM UNIT DO jacks to DECODER SECTION- P3.3 jack using patch cord. d) Connect LED OUTPUT UNIT 8-pin L1~L8 connector to DECODER SECTION 8-pin JP1 using 8 pin ribbon cable. e) Switch ON power supply.
c)

2) Run program:a) Open respective program ser_mem.ASM in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit.
b)

Debug the whole program step by step using debug tool set or Press GO button for program execution. Use Stop button to stop the execution. PROGRAM:

CS_93C46 SK_93C46 DI_93C46 DO_93C46 BIT_CNT BIT_SEND DATSEND MAIN:

BIT P3.0 BIT P3.1 BIT P3.2 BIT P3.3 DATA 10H DATA 11H DATA 12H

; define control signal & inputs

ORG 0000H ;LJMP READDATA ; read data LCALL ERAL WRITEDATA: MOV R7,#00H ; to write data MOV R5,#0FEH MOV R6,#0FDH LCALL WRITE NOP ; no operation NOP MOV R7,#01H MOV R5,#0FBH MOV R6,#0F7H LCALL WRITE NOP NOP MOV R7,#02H MOV R5,#0EFH MOV R6,#0DFH
194

AMC-51 Advanced Microcontroller 8051 Trainer

LCALL WRITE NOP NOP MOV R7,#03H MOV R5,#0BFH MOV R6,#07FH LCALL WRITE NOP NOP READDATA: MOV R7,#00H ; to read data LCALL READ NOP NOP ; no operation MOV 30H,R5 MOV 31H,R6 MOV R7,#01H LCALL READ NOP NOP MOV 32H,R5 MOV 33H,R6 MOV R7,#02H LCALL READ NOP NOP MOV 34H,R5 MOV 35H,R6 MOV R7,#03H LCALL READ NOP NOP MOV 36H,R5 MOV 37H,R6 LOOP4: MOV R3,#08H MOV R0,#30H LOOP3: MOV A,@R0 MOV P1,A INC R0 SETB RS1 MOV R5,#03H LL3: MOV R6,#0FFH LL2: MOV R7,#0FFH LL1: DJNZ R7,LL1 DJNZ R6,LL2 DJNZ R5,LL3 CLR RS1 DJNZ R3,LOOP3 SJMP LOOP4
195

AMC-51 Advanced Microcontroller 8051 Trainer

READ:

CALL START_93C46 MOV DATSEND,#06H MOV BIT_SEND,#03H LCALL SEND_DATA MOV DATSEND,R7 MOV BIT_SEND,#06H LCALL SEND_DATA SETB DO_93C46 MOV BIT_CNT,#16 READ1: SETB SK_93C46 SETB SK_93C46 CLR SK_93C46 CLR SK_93C46 NOP MOV C,DO_93C46 MOV A,R5 RLC A MOV R5,A MOV A,R6 RLC A MOV R6,A DJNZ BIT_CNT,READ1 LCALL STOP_93C46 RET WRITE: LCALL WEN_93C46 LCALL START_93C46 MOV DATSEND,#05H MOV BIT_SEND,#03H LCALL SEND_DATA MOV DATSEND,R7 MOV BIT_SEND,#06H LCALL SEND_DATA MOV DATSEND,R6 MOV BIT_SEND,#08H LCALL SEND_DATA MOV DATSEND,R5 MOV BIT_SEND,#08H LCALL SEND_DATA LCALL STOP_93C46 LCALL WDS_93C46 RET

WRAL: LCALL WEN_93C46 LCALL START_93C46 MOV DATSEND,#11H MOV BIT_SEND,#05H LCALL SEND_DATA MOV DATSEND,#00H
196

AMC-51 Advanced Microcontroller 8051 Trainer

MOV LCALL MOV MOV LCALL MOV MOV LCALL LCALL LCALL RET START_93C46: SETB CLR SETB JNB SETB CLR CLR CLR CLR SETB RET

BIT_SEND,#04H SEND_DATA DATSEND,R6 BIT_SEND,#08H SEND_DATA DATSEND,R5 BIT_SEND,#08H SEND_DATA STOP_93C46 WDS_93C46 SETB DO_93C46 DI_93C46 SK_93C46 CS_93C46 DO_93C46,$ SK_93C46 SK_93C46 CS_93C46 SK_93C46 DI_93C46 CS_93C46

STOP_93C46: CLR SK_93C46 CLR DI_93C46 CLR CS_93C46 SETB DO_93C46 RET WEN_93C46: LCALL START_93C46 MOV DATSEND,#04H MOV BIT_SEND,#03H LCALL SEND_DATA MOV DATSEND,#30H MOV BIT_SEND,#06H LCALL SEND_DATA LCALL RET STOP_93C46

WDS_93C46: LCALL START_93C46 MOV DATSEND,#04H MOV BIT_SEND,#03H LCALL SEND_DATA MOV DATSEND,#00H MOV BIT_SEND,#06H LCALL SEND_DATA LCALL STOP_93C46 RET
197

AMC-51 Advanced Microcontroller 8051 Trainer

ERASE:

LCALL WEN_93C46 LCALL START_93C46 MOV DATSEND,#07H MOV BIT_SEND,#03H LCALL SEND_DATA MOV DATSEND,R7 MOV BIT_SEND,#06H LCALL SEND_DATA LCALL STOP_93C46 LCALL WDS_93C46 RET LCALL LCALL MOV MOV LCALL MOV MOV LCALL LCALL LCALL RET WEN_93C46 START_93C46 DATSEND,#04H BIT_SEND,#03H SEND_DATA DATSEND,#20H BIT_SEND,#06H SEND_DATA STOP_93C46 WDS_93C46

ERAL:

SEND_DATA: MOV BIT_CNT,BIT_SEND MOV A,#08H CLR C SUBB A,BIT_CNT MOV BIT_CNT,A JZ SEND_DATA2 MOV A,DATSEND SEND_DATA1: RL A DJNZ BIT_CNT,SEND_DATA1 JMP SEND_DATA3 SEND_DATA2: MOV A,DATSEND SEND_DATA3: MOV BIT_CNT,BIT_SEND SEND_DATA4: RLC A JC SEND_DATA5 CLR DI_93C46 JMP SEND_DATA6 SEND_DATA5: SETB DI_93C46 NOP NOP SEND_DATA6: SETB SK_93C46 CLR SK_93C46 DJNZ BIT_CNT,SEND_DATA4
198

AMC-51 Advanced Microcontroller 8051 Trainer

RET END

OUTPUT: Press GO button & observe the serial data output port to P1.0~P1.7 to LED L1~L8. LED L1~L8 will be lighted one by one, to realize a right shift effect of lights continuously.

199

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 30 AT24C02 IC Bus Memoryory R/W Experiment


OBJECTIVE: To study working principle & interfacing of AT 24c02 with microcontroller. CIRCUIT DISCRIPTION:
The VCC and ground pins of the EEPROM are directly connected to the VCC and the VSS pins of the AT8xEB5114. The SCL and the SDA pins of the EEPROM are internally bonded to the P3.6 and P3.7 ports of the AT8xEB5114. The other pins (Device/page address and WP) are left unconnected. Internal pull-downs in AT24C02 drive A0, A1, A2 and WP to a Low level. To generate a start condition, it is necessary to set the SDA line to 1. This can be done by the weak pull-up of the port while the microcontroller is under reset. But, due to the high pull-up value of the AT8xEB5114 port, it can take a long time before having this condition satisfied, and in case the EEPROM is outputting a low level, it is absolutely impossible to have... even with the strong transistor which would only produce a a spike on the SDA line. In order to reset the EEPROM, the best solution is to proceed as follows: Make the clock toggles as long as there is not a high Level on the SDA pin while the SCL pin is high. As soon as this condition is satisfied (SDA High while SCL is also High), make a START by driving low the SDA pin while the SCL pin is still high. After this first start, which has reset the TWI line you can create a STOP (by making a transition from low a High level on the SDA pin while the SCL is High), then you are certain that your protocol has been properly reset, and that no untimely data can be transmitted to the EEPROM while no other START has been processed. The small spikes seen on the SDA pin correspond to the software pull-up which tries to rise the SDA pin. The special rising edge on the SCL pin during the AT8xEB5114 is reset is due the standard bidirectional port pull-up resistor. Just after the reset, the microcontroller has to transfer two dummy 0 data bits before being able to reset the EEPROM protocol. Figure 3-2. illustrates an example of AT8xEB5114 reset while the EEPROM does not hold the SDA line to 0. There is no spike visible because in this case only the microcontroller is transmitting data to the EEPROM. The special rising edge of the SCL pin during the microcontroller is reset is due the standard bidirectional port pull-up resistor.

CIRCUIT DIAGRAM:

200

AMC-51 Advanced Microcontroller 8051 Trainer

Procedure:
1. Connections:a) Connect I2CEEPROM UNIT A0, A1 and A2 jacks to IN BUILT POWER- GND jack using patch cord. b) Connect I2CEEPROM UNIT SDA jack to DECODER SECTION- P1.7 jack using patch cord. c) Connect I2CEEPROM UNIT SCL jack to DECODER SECTION- P1.6 jack using patch cord. d) Connect LED OUTPUT UNIT L1 jack to DECODER SECTION- P1.0 jack using patch cord. e) Connect LED OUTPUT UNIT L2 jack to DECODER SECTION- P1.1 jack using patch cord. f) Switch ON power supply.
a) b)

2. Run program:Open respective program 24C02.ASM in 8051 simulation system software. Press compile and load button in the software. Observe the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. If zero warning and zero error then Compilation and loading-OK message is displayed. Current module window is opened and program is loaded into the kit. Debug the whole program step by step using debug tool set or press GO button program execution. Use Stop button to stop the execution. for

c)
d)

PROGRAM:-

SDA SCL WRL RDL

BIT P1.7 BIT P1.6 BIT P1.0 BIT P1.1


201

AMC-51 Advanced Microcontroller 8051 Trainer

MTD MRD AT24C02 ACK SLA SUBA

EQU EQU

30H 40H

EQU 0A0H BIT 10H DATA 50H DATA 51H

NUMBYTE DATA 52H

ORG LJMP ORG MAIN: MOV MOV MOV MOV CLEAR:

0000H MAIN 0100H R5,#00 R6,#00H DPL,#00H DPH,#00H A,#00H

MOV

MOVX INC MOV CJNE MOV MOV NEXT:

@DPTR,A DPTR A,DPH A,#0FFH,CLEAR DPL,#00H DPH,#40H R4,#0F0H

MOV DJNZ MOV INC

R4,$ MTD,R6 R6
202

AMC-51 Advanced Microcontroller 8051 Trainer

MOV INC MOV INC MOV INC MOV INC MOV INC MOV INC MOV INC

MTD+1,R6 R6 MTD+2,R6 R6 MTD+3,R6 R6 MTD+4,R6 R6 MTD+5,R6 R6 MTD+6,R6 R6 MTD+7,R6 R6

WRAT:

MOV MOV MOV MUL MOV MOV CLR SETB

SLA,#AT24C02

A,R5 B,#08 AB SUBA,A NUMBYTE,#08 WRL RDL

LCALL IWRNBYTE MOV R2,#12H

LCALL DELYA
203

AMC-51 Advanced Microcontroller 8051 Trainer

SETB CLR

WRL RDL

RDAT:

MOV MOV MOV MUL MOV MOV

SLA,#AT24C02

A,R5 B,#08 AB SUBA,A NUMBYTE,#08

LCALL IRDNBYTE MOV R2,#12H

LCALL DELYA SETB NOP MOV MOV LL: MOV MOVX INC INC DJNZ NOP INC R5 R1,#MRD R7,#08H A,@R1 @DPTR,A R1 DPTR R7,LL RDL

CJNE R5,#32,NEXT SETB WRL SETB RDL


204

AMC-51 Advanced Microcontroller 8051 Trainer

LO:

SJMP LO

DELYA: DELYB: DELYC: DELYD:

PUSH 02H PUSH 02H PUSH 02H DJNZ R2,DELYD

;delay

POP 02H DJNZ R2,DELYC POP 02H DJNZ R2,DELYB POP 02H DJNZ R2,DELYA RET

START:

SETB SDA

;to start

NOP SETB SCL NOP NOP NOP NOP NOP CLR SDA
205

;high scl

AMC-51 Advanced Microcontroller 8051 Trainer

NOP NOP NOP NOP NOP CLR SCL NOP

;sda low

RET

STOP:

CLR

SDA

;to stop

NOP SETB SCL NOP NOP NOP NOP NOP SETB SDA NOP NOP NOP NOP RET ;high sda ;no operation at high clock

MACK:

CLR

SDA

;acknowledge
206

AMC-51 Advanced Microcontroller 8051 Trainer

NOP NOP SETB NOP NOP NOP NOP NOP CLR NOP NOP RET SCL ;no operation SCL

MNACK: NOP NOP

SETB

SDA

SETB NOP NOP NOP NOP NOP

SCL

CLR SCL NOP NOP


207

AMC-51 Advanced Microcontroller 8051 Trainer

RET

CACK: SETB SDA NOP NOP SETB SCL CLR ACK NOP NOP MOV C,SDA JC CEND

SETB ACK CEND: NOP CLR SCL NOP RET

WRBYTE: MOV R0,#08H WLP: JC RLC A WR1

SJMP WR0 WLP1: DJNZ R0,WLP NOP RET


208

;decrement jump if not zero

AMC-51 Advanced Microcontroller 8051 Trainer

WR1:

SETB SDA

NOP SETB SCL NOP NOP NOP NOP NOP

CLR SCL SJMP WLP1 WR0: CLR SDA NOP SETB SCL NOP NOP NOP NOP NOP

CLR SCL SJMP WLP1

RDBYTE: MOV R0,#08H

; read byte
209

AMC-51 Advanced Microcontroller 8051 Trainer

RLP:

SETB SDA

NOP SETB SCL NOP NOP NOP MOV C,SDA MOV A,R2 CLR SCL RLC A MOV R2,A NOP NOP NOP DJNZ R0,RLP RET

IWRBYTE: PUSH ACC IWBLOOP: LCALL START MOV A,SLA

LCALL WRBYTE LCALL CACK


210

AMC-51 Advanced Microcontroller 8051 Trainer

JNB POP

ACK,RETWRB ACC

LCALL WRBYTE LCALL CACK LCALL STOP RET RETWRB: POP ACC

LCALL STOP RET

IRDBYTE: LCALL START MOV INC A,SLA A

LCALL WRBYTE LCALL CACK JNB ACK,RETRDB

LCALL RDBYTE LCALL MNACK RETRDB: LCALL STOP RET

IWRNBYTE: MOV MOV R3,A

A,NUMBYTE

LCALL START
211

AMC-51 Advanced Microcontroller 8051 Trainer

MOV

A,SLA

LCALL WRBYTE LCALL CACK JNB MOV ACK,RETWRN A,SUBA

LCALL WRBYTE

LCALL CACK MOV WRDA: R1,#MTD A,@R1

MOV

LCALL WRBYTE LCALL CACK JNB INC ACK,IWRNBYTE R1

DJNZ R3,WRDA RETWRN: LCALL STOP RET

IRDNBYTE: MOV

R3,NUMBYTE

LCALL START MOV A,SLA

LCALL WRBYTE LCALL CACK JNB MOV ACK,RETRDN A,SUBA

LCALL WRBYTE
212

AMC-51 Advanced Microcontroller 8051 Trainer

LCALL CACK LCALL START MOV INC A,SLA A

LCALL WRBYTE LCALL CACK JNB MOV RDN1: ACK,IRDNBYTE R1,#MRD

LCALL RDBYTE MOV @R1,A

;NOP ;NOP DJNZ R3,SACK LCALL MNACK RETRDN: RET SACK: LCALL MACK INC R1 LCALL STOP

SJMP RDN1

IWRNBYTEEXT: MOV MOV A,NUMBYTE R3,A


213

AMC-51 Advanced Microcontroller 8051 Trainer

LCALL START MOV A,SLA

LCALL WRBYTE LCALL CACK JNB MOV WRDAE: ACK,RETWRNE R1,#MTD MOV A,@R1

LCALL WRBYTE LCALL CACK JNB INC ACK,RETWRNE R1

DJNZ R3,WRDAE RETWRNE: LCALL STOP RET

IRDNBYTEEXT: MOV R3,NUMBYTE

LCALL START MOV INC A,SLA A

LCALL WRBYTE LCALL CACK JNB MOV ACK,RETRDNE R1,#MRD


214

AMC-51 Advanced Microcontroller 8051 Trainer

RDNE1:

LCALL RDBYTE @R1,A

MOV

DJNZ R3,SACKE LCALL MNACK RETRDNE: LCALL STOP RET SACKE: INC LCALL MACK R1

SJMP RDNE1 END OUTPUT: Press GO button & check the Data store memory location from 4000~40FFH. Contains of that memory location should be 00H~FFH.

Experiment 31 PWM Impulse Width Modulation Experiment

215

AMC-51 Advanced Microcontroller 8051 Trainer

OBJECTIVE: To know the working principle of PWM by using HA17324 IC with microcontroller & see reaction on dc motor. CIRCUIT DISCRIPTION: HA17324 series and HA17324A series are quad operational amplifier that provide high gain and internal phase compensation, with single power supply. They can be widely used to control equipments. Here interfacing microcontroller with HA17324 IC to generate PWM .we are generating PWM in program only by giving different delay for ON-OFF time of P1.7.The p1.7 connected to input pin of HA17324a IC for phase compensation & output of this IC given to DC motor to rotate it at different pulses. Features Wide range of supply voltage, and single power supply used Internal phase compensation

CIRCUIT DIAGRAM:

PROCEDURE: 1) Connections:a) Connect PWM UNIT PWM IN jack to DECODER SECTION- P1.7 jack using patch cord. b) Connect PWM UNIT VOUT jack to DC MOTOR DJ jack using patch cord.
216

AMC-51 Advanced Microcontroller 8051 Trainer

c) 2)
a)

Switch ON power supply.

Run program:Open respective program pwm.ASM in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit.
b)

Debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution. PROGRAM: OUTPORT BIT P1.7 ORG 0000H JMP START ORG 100H START: CLR OUTPORT MOV R2,#6 LCALL DELY SETB OUTPORT MOV R2,#4 LCALL DELY LJMP START DELY: DEL2: DEL3: DEL4: PUSH 02H PUSH 02H PUSH 02H DJNZ R2,DEL4 POP 02H DJNZ R2,DEL3 POP 02H DJNZ R2,DEL2 POP 02H DJNZ R2,DELY RET END ; select port 1.7 as out port ; initialise program ; jump to start ; clear bit p1.7 ; store6 in r2 reg ; call delay ; set bit p1.7 ; store 4 in r2 reg ; call delay ; jump to start ;loop for delay

OUTPUTPress GO button & observe DC motor rotation with controlled speed.

ASSIGNMENT: By changing delay time ,you can see effect on dc motor speed.
217

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 32 74LS164 Serial Input and Parallel Output Experiment


OBJECTIVE: To know the working principle of serial in parallel out shift resister using 74LS164 IC with microcontroller. CIRCUIT DISCRIPTION: HA17324 series and HA17324A series are quad operational amplifier that provide high gain and internal phase compensation, with single power supply. They can be widely used to control equipments. Features Wide range of supply voltage, and single power supply used Internal phase compensation Wide range of common mode voltage, and possible to operate with an input about 0V Features only for A series Low electro-magnetic interference level Here two 74ls164 IC used for shifting serial data input to get parallel output data .P3.0 is connected to input data pin of 1st IC. The Q7 of 1st IC connected to 2nd IC data in pin. The output pins Q0 to Q7 of both ICS are given to 7 segment display. CIRCUIT DIAGRAM:

PROCEDURE: 1. Connections: a) Connect SERIAL IN PARALLEL OUT UNIT A/B jack to DECODER SECTIONP3.0 jack using patch cord. b) Connect SERIAL IN PARALLEL OUT UNIT CP jack to DECODER SECTIONP3.1 jack using patch cord. c) Connect SERIAL IN PARALLEL OUT UNIT /CLR jack to DECODER SECTION- P1.0 jack using patch cord. d) Switch ON power supply. 2. Run program:
218

AMC-51 Advanced Microcontroller 8051 Trainer

Open respective program SIPO.ASM or SIPO.C in 8051 simulation system software.


a)

Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. c) If zero warning and zero error then Compilation and loading-OK message is displayed. d) Current module window is opened and program is loaded into the kit.
b)

Debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution. ROGRAM: ORG 0000H LJMP MAIN ORG 0100H MAIN: MOV 30H,#00H ; clear 30h &31h memory locations MOV 31H,#00H L0: SETB P1.0 ; set bit P1.0 INC 30H ; increment data stored in 30h MOV A,30H ; load 30h data to accumulator CJNE A,#0AH,AA ; compare data stored in accumulator with 0ah data MOV 30H,#00H ; initialize 30h data INC 31H ; increment data stored in 31h memory location MOV A,31H ; move 31h data to accumulator CJNE A,#0AH,AA ; compare data stored in accumulator with 0ah data MOV 30H,#00H ; initialize 30h data MOV 31H,#00H ; initialize 30h data AA: MOV SCON,#00H ; clear SCON reg. MOV R7,#02H ; store 2h data to r7 MOV R0,#30H ; store 30h address to r0 MOV DPTR,#TAB ; move data from tab to DPTR LOOP: MOV A,@R0 ; load accumulator memory location pointed by R0 MOVC A,@A+DPTR ; load data stored in memory location pointed by DPTR + ; accumulator to accumulator MOV SBUF,A ; load accumulator data to SBUF WAIT: JNB TI,WAIT ; jump if timer bit is not high to WAIT CLR TI ; clear TI INC R0 ; Increment R0 DJNZ R7,LOOP ; decrementr7 & jump if not zero to loop MOV R2,#30H ; store data from 30h memory location tor2 LCALL DELYA ; call delay CLR P1.0 ; clear P1.0 SJMP L0 ; jump to L0 TAB: DB 3FH,06H,5DH,04FH,66H,6DH,7DH,07H,7FH,6FH DB 77H,7CH,39H,5EH,86H,8EH,0FFH,0F1H,0C6H,092H,0BFH DELYA: PUSH 02H DELYB: PUSH 02H DELYC: PUSH 02H DELYD: DJNZ R2,DELYD POP 02H ; no operation

219

AMC-51 Advanced Microcontroller 8051 Trainer

DJNZ R2,DELYC POP 02H DJNZ R2,DELYB POP 02H DJNZ R2,DELYA RET END

OUTPUT: Press GO button 00~99 continuously. & observe 2-digit Digital 7-sement displays the number between

220

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 33 165 Parallel /Serial Convert Experiment


OBJECTIVE: To know the working of parallel in serial out shift register using microcontroller. CIRCUIT DISCRIPTION: To know the working of parallel in serial out shift register we used here 74LS165 IC with microcontroller. Port 1 of microcontroller connected to input of shift resister. When S/L is high, data stats shifting serially& Loading data .To receive serial data ,enable receiver enable flag & receiver interrupt of microcontroller . CIRCUIT DIAGRAM: 74LS165 IC with

PROCEDURE: 1. Connections:e) Connect PARALLEL IN SERIAL OUTUNIT Q7 jack to DECODER SECTIONP3.0 jack using patch cord.
221

AMC-51 Advanced Microcontroller 8051 Trainer

m) n) o)

p) 2.
a) b)

Connect PARALLEL IN SERIAL OUTUNIT CP jack to DECODER SECTIONP3.1 jack using patch cord. g) Connect PARALLEL IN SERIAL OUTUNIT S/L jack to DECODER SECTIONP3.2 jack using patch cord. h) Connect PARALLEL IN SERIAL OUTUNIT D0 jack to DECODER SECTIONP1.7 jack using patch cord. i) Connect PARALLEL IN SERIAL OUTUNIT D1 jack to DECODER SECTIONP1.6 jack using patch cord. j) Connect PARALLEL IN SERIAL OUTUNIT D2 jack to DECODER SECTIONP1.5 jack using patch cord. k) Connect PARALLEL IN SERIAL OUTUNIT D3 jack to DECODER SECTIONP1.4 jack using patch cord. l) Connect PARALLEL IN SERIAL OUTUNIT D4 jack to DECODER SECTIONP1.3 jack using patch cord. Connect PARALLEL IN SERIAL OUTUNIT D5 jack to DECODER SECTION- P1.2 jack using patch cord. Connect PARALLEL IN SERIAL OUTUNIT D6 jack to DECODER SECTION- P1.1 jack using patch cord. Connect PARALLEL IN SERIAL OUTUNIT D7 jack to DECODER SECTION- P1.0 jack using patch cord. Switch ON power supply.
f)

Run program:Open respective program PISO.ASM in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. If zero warning and zero error then Compilation and loading-OK message is displayed. Current module window is opened and program is loaded into the kit. Debug the whole program step by step using debug tool set or press GO button program execution. Use Stop button to stop the execution. for

c)
d)

PROGRAM: ORG 0000H LJMP MAIN ORG 0500H MAIN: MOV R7,#10 ; store 10 in R7 MOV R0,#50H ; store 50h data in R0 MOV 40H,#00H START: INC 40H MOV P1,40H ; load 40h at p1 port CLR P3.2 ; clear port pin P3.2 SETB P3.2 ; set bit P3.2 RXDATA: MOV SCON,#10H ; load 10h in SCON WAIT: JNB RI,WAIT CLR RI ; clear data of RI
222

AMC-51 Advanced Microcontroller 8051 Trainer

MOV A,SBUF MOV @R0,A R0

; load SBUF data in accumulator ; load accumulator data in memory location pointed by

INC R0 ; increment data of R0 DJNZ R7,START ; decrement data of R7 & jump if not zero SJMP $ END ; end of program Output: press GO button & check the internal store memory location from 0050H~0059H. Contains of that memory location should be 01H~0AH.

223

AMC-51 Advanced Microcontroller 8051 Trainer

Experiment 34 Playing Electronic Music Experiment


OBJECTIVE: To know how to create electronic music using program. CIRCUIT DISCRIPTION: The port p1.5 pin of microcontroller is connected to buzzer through pnp transistor 9012 The buzzer connected to emitter of transistor with respect to gnd. CIRCUIT DIAGRAM:

PROCEDURE: 1. Connections:q) Connect BUZZER UNIT SP jack to DECODER SECTION- P1.5 jack using patch cord. r) Switch ON power supply. 2. Run program:q) Open respective program music1.asm in 8051 simulation system software. Press compile and load button in the software. See the save message window is displayed. Conform the path where the program supported file was stored and press the YES button. s) If zero warning and zero error then Compilation and loading-OK message is displayed. t) Current module window is opened and program is loaded into the kit.
r)

Debug the whole program step by step using debug tool set or press GO button for program execution. Use Stop button to stop the execution. .

PROGRAM: ORG 0000h LJMP START ORG 000BH

; MUSIC

224

AMC-51 Advanced Microcontroller 8051 Trainer

LJMP INTT0 START: MOV SP,#50H MOV TH0,#0D8H ; select timer time for interrupt MOV TL0,#0EFH MOV TMOD,#01H ; select timer 0 MOV IE,#82H ; enable interrupt MUSIC0: NOP ; no operation MOV DPTR,#DAT ; move DAT to DAT look up table MOV 20H,#00H ; clear 20h memory location MUSIC1: NOP ; no operation CLR A ; clear accumulator MOVC A,@A+DPTR ; move data from memory location whose address is pointed by DPTR +accumulator to accumulator JZ END0 ;jump if zero to loop END0 CJNE A,#0FFH,MUSIC5 ;compare accumulator with 0ffh data & jump if not equal to music5 LJMP MUSIC3 ;long jump music3 MUSIC5: NOP MOV R6,A ;store data from accumulator to R6 INC DPTR ;increment DPTR MOV A,#0 ;clear accumulator MOVC A,@A+DPTR ;move data from memory location whose address is pointed by DPTR +accumulator to accumulator MOV R7,A ;store data from accumulator to

r7 SETB TR0 ; set bit TR0 MUSIC2: NOP CPL P1.5 ; complement port 1.5 MOV A,R6 ; move data from r6 to accumulator MOV R3,A ; move data from accumulator to R3 LCALL DEL ; call delay MOV A,R7 ; store r7 data to accumulator CJNE A,20H,MUSIC2 MOV 20H,#00H ; clear 20h memory location INC DPTR ; Increment DPTR LJMP MUSIC1 MUSIC3: NOP CLR TR0 ; clear TR0 MOV R2,#0DH ; move 0Dh tor2 MUSIC4: NOP MOV R3,#0FFH ; store ffh data to r3 LCALL DEL DJNZ R2,MUSIC4 ; decrement content of r2,jump if not zero to music 4
225

AMC-51 Advanced Microcontroller 8051 Trainer

INC DPTR LJMP MUSIC1 END0: NOP MOV R2,#0FFH MUSIC6: MOV R3,#00H LCALL DEL DJNZ R2,MUSIC6 LJMP MUSIC0 DEL: NOP DEL3: MOV R4,#02H DEL4: NOP DJNZ R4,DEL4 NOP DJNZ R3,DEL3 RET NOP INTT0: INC 20H MOV TH0,#0D8H MOV TL0,#0EFH RETI DAT: DB 18H,30H,1CH,10H DB 20H,40H,1CH,10H DB 18H,10H,20H,10H DB 1CH,10H,18H,40H DB 1CH,20H,20H,20H DB 1CH,20H,18H,20H DB 20H,80H,0FFH,20H DB 30H,1CH,10H,18H DB 20H,15H,20H,1CH DB 20H,20H,20H,26H DB 40H,20H,20H,2BH DB 20H,26H,20H,20H DB 20H,30H,80H,0FFH DB 20H,20H,1CH,10H DB 18H,10H,20H,20H DB 26H,20H,2BH,20H DB 30H,20H,2BH,40H DB 20H,20H,1CH,10H DB 18H,10H,20H,20H DB 26H,20H,2BH,20H DB 30H,20H,2BH,40H DB 20H,30H,1CH,10H DB 18H,20H,15H,20H DB 1CH,20H,20H,20H DB 26H,40H,20H,20H DB 2BH,20H,26H,20H DB 20H,20H,30H,80H DB 20H,30H,1CH,10H DB 20H,10H,1CH,10H

; increment DPTR ; load ffh to r2 reg. ; clear r3 reg.

; loops for creating delay

; increment 20h memory location ; load timer time ; return from interrupt loop

226

AMC-51 Advanced Microcontroller 8051 Trainer

DB 20H,20H,26H,20H DB 2BH,20H,30H,20H DB 2BH,40H,20H,15H DB 1FH,05H,20H,10H DB 1CH,10H,20H,20H DB 26H,20H,2BH,20H DB 30H,20H,2BH,40H DB 20H,30H,1CH,10H DB 18H,20H,15H,20H DB 1CH,20H,20H,20H DB 26H,40H,20H,20H DB 2BH,20H,26H,20H DB 20H,20H,30H,30H DB 20H,30H,1CH,10H DB 18H,40H,1CH,20H DB 20H,20H,26H,40H DB 13H,60H,18H,20H DB 15H,40H,13H,40H DB 18H,80H,00H END OUTPUT: Press GO button & hear different types of tone through the buzzer continuously

227

Potrebbero piacerti anche