Vous êtes sur la page 1sur 36

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

MICRO CONTROLLER LAB MANUAL

FOR BE YEAR 2ND SEMESTER

BE (ECE) 2nd Semester MICRO CONTROLLER LAB LIST OF EXPERIMENTS

Exp No. 1- Familiarity and use of 8051 Micro controller Trainer. Exp No. 2- Instruction set for simple programs for data transfer, & 3 manipulation, arithmetic operations, branching operations, logical operations and testing condition of bit in a byte. Exp No. 4- Code conversion programs. Exp No. 5- Timer and counter programming using 8051 Exp No. 6- Serial mode operation of 8051 Exp No. 7- Interfacing DAC module using 8051 Exp No. 8- Interfacing Traffic signal control using 8051 Exp No. 9- Interfacing 7-segment display using 8051 Exp No.10-Interfacing Stepper motor control using 8051 Exp No.11-Familiarity with MCBX51 board and writing programs for MCBX51. Program for Blinking of LEDs. Exp No.12-Real time clock using 8051.

BE (ECE) 2ND SEMESTER MICRO CONTROLLER LAB LIST OF EXPERIMENTS


Experiment No.1: Familiarity and use of 8051 (ESA-31) Micro controller kit trainer. Experiment No.2: Simple programs in 8051 Assembly code and their execution. Program 1: Addition of two 16 bit numbers using registers. Program 2: Copying of byte data in RAM memory locations using a) Direct addressing b) Register indirect addressing c) Using loop structure. Program 3: Sum of a series of byte elements Program 4: Copying a data block from source to destination. Program 5: Count number of 1s in a byte. Program 6: Multiplication of two unsigned 8-bit binary numbers. Program 7: Division of two unsigned 8-bit binary numbers. Program 8: Searching of a byte element in a data block.

Experiment No.3: Arithmetic, Logical & Branching operations. Program 9: Multi byte binary addition Program 10: Multi byte BCD addition Program 11: Multi byte binary subtraction

Program 12: Testing condition of a bit in a byte of data. Program 13: Finding largest element in a block of data array. Program 14: Checking a character string for a palindrome. Experiment No. 4: Code conversion Programs. Program 15: ASCII to Packed BCD conversion. Program 16: Packed BCD to ASCII conversion. Program 17: BCD to Binary conversion.

Experiment No. 5: Timer Programming using 8051 Experiment No. 6: Communication with host computer system. Experiment No. 7: Interfacing of DAC using 8051 and its programming.

Experiment No. 8: Interfacing of traffic signal control using 8051 and its programming. Experiment No. 9: Interfacing of 7-segment display using 8051 and its programming. Experiment No. 10: Program to control Stepper motor using 8051 . Experiment No. 11: Introduction to KEIL Software and MCBX51 kit. Experiment No. 12: Blinky: LED flasher program. Experiment No. 13: Interfacing elevator simulator control using 8051.

EXPERIMENT NO. 1
Familiarity with ESA 31 micro controller kit:
Main features of ESA 31 (8031 based): ESA 31 can be operated either from onboard keyboard or from a CRT terminal through its RS 232-C interface. Keyboard and serial monitor programs support the entry of users program, editing, debug facilities like breakpoints, single stepping & full execution of user programs. 1-pass Assembler can assemble any memory resident assembly language program. 1-pass Dis-assembler disassembles the object code into standard INTEL mnemonics. Total of 120KB memory is provided of which 64KB of memory is program memory and 56KB of memory is data memory. The monitor of the trainer occupies 32KB out of 64KB of program memory. Standard bus compatible signals available on the bus connector for easy expansion. SPECIFICATIONS: Microcontroller: 8031/8051 operated at 11.0592 MHz Memory follows: : Four 28-pin JEDEC sockets offer 120KB of memory as

32KB of firmware in one 27256 (Program memory) 32KB of SRAM using one 62256 (User program memory) 56KB of SRAM as data memory using two 62256s.
5

The memory map is as follows: DEVICE 27256 62256 62256 62256 ADDRESS RANGE 0000-7FFF 8000-FFFF 0000-7FFF 8000-FFFF TYPE OF MEMORY Program memory User program memory User data memory User data memory.

The dip switch settings for either mode of operation are as follows: For Hexadecimal keypad mode: All switches in OFF position. For Serial mode : Switches 1 and 4 in ON position.

KEYBOARD MONITOR In the keyboard mode, the user enters the commands and data by pressing the appropriate keys on the keypad. Responses are displayed by the system on the seven-digit 7-segment LED display. The RESET key causes a hardware reset and restarts the monitor. The monitor displays the sign-on message ESA 51 across the address & data fields of the display.

KEYBOARD & DISPLAY The display consists of 7 seven segment LED displays, separated into three fields. The leftmost single digit forms the special field. Next four digits form the address field. Note: Address can be 256B or 64KB max. Last two digits form the data field.

The 36-key keypad consists of the following group of keys. A). Hex pad 16 keys representing hex digits 0 through F. B). Command Group 13 command keys. C). Memory Group 4 keys (PRGMEM, EXTDATA, BITMEM, INTDATA) to select the type of memory. D). System Operation keys RESET, BREAK, and EXEC keys BREAK can be used to stop the execution without affecting the register contents.

MONITOR COMMANDS The keyboard monitor is capable of executing fifteen individual commands. EXAMINE/MODIFY MEMORY Displays/modifies the contents of a memory location. Syntax Format: EXAM MEM {PRG MEM/EXT DATA/BIT MEM/INT DATA} Addr1 NEXT [[[data] NEXT/PREV].] EXEC After pressing EXAM MEM key, enter the type of memory by pressing PRGMEM, EXTDATA, BITMEM, or INTDATA key. A dot appears at the last digit of the address field indicating that an address entry is required. Enter the memory address of the byte to be examined. (Memory address is evaluated modulo 64K if it is program memory or data memory and modulo 256 if it is internal data memory or bit memory). The value is displayed in the address field of the display.

EXAMINE/MODIFY REGISTER This command is used to examine and optionally modify the contents of some of the 8031/8051s registers. EXAM REG [reg key] [[Data] NEXT/PREV].] EXEC. Note: When any of the registers R0-R7 has to be examined, press EXAMREG key and then BITMEM key. Now press keys 0-7 on the hex keypad, which corresponds to registers R0-R7. The displayed registers contents of R0-R7 is w.r.t the current bank selected. GO COMMAND: Is used to transfer control of the system from the monitor to the users program. GO [Starting addr] EXEC To abort execution of user program, press RESET key. By doing so all registers information about user program is lost. In any case, contents of the user portion of the RAM area are not altered by the monitor. There are two ways to break the user program execution. a) Set breakpoints at specific addresses and enable them. b) Press BREAK key. If BREAK key is pressed, control returns to the monitor which saves all the registers and displays the address where the program broke and the data at that address on the display. It displays U on the special field of 7-segment display.

EXPERIMENT NO 2 & 3 Execution of simple programs using ESA-31 in keyboard mode. Program Examples: 1. Write a program in 8051 to add two 16-bit numbers. The numbers are 3CE7H and 3B8DH. Place the sum in registers R7 and R6; R6 has the lower byte. Address 8000 8001 8003 8005 8006 8008 800A 800B OBJECT Code C3 74 E7 24 8D FE 74 3C 34 3B FF 80 FE Mnemonic CLR C MOV A, #0E7H ADD A, #8DH MOV R6, A MOV A, #3CH ADDC A, #3BH MOV R7, A HERE: SJMP HERE

(Relative address = Target address PC contents) Enter the codes using the format given below. <EXAMMEM><PRGMEM> 8000 <NXT> DATA <NXT>..<NXT>EXEC Note: After executing the program using GO<8000>EXEC press BREAK key.

Press EXAMREG key twice to check result in regs R6 and R7 respectively. Format: <EXAMREG><EXAMREG><BITMEM>6<NEXT><NEXT>

2. Write an 8051 program to copy the value 55H into RAM memory locations 40H to 44H using A) Direct addressing mode B) Register addressing mode without using Loop and C) With a Loop. A) Using direct addressing mode MOV A, #55h MOV 40h, A MOV 41h, A MOV 42h, A MOV 43h, A MOV 44h, A HERE: SJMP HERE

; copy A to RAM Location

B) using reg-indirect addressing mode without loop MOV A. #55h MOV R0, #40h MOV @R0, A INC R0 MOV @R0, A INC R0 MOV @R0, A INC R0 MOV @R0, A INC R0 MOV @R0, A HERE: SJMP HERE
10

C) With Loop MOV A, #55h MOV R0, #40h MOV R2, #05h; Counter AGAIN: MOV @R0, A INC R0 DJNZ R2, AGAIN HERE: SJMP HERE

3. Six bytes of data are stored in memory locations starting at 50H. Add all the bytes. Use reg R7 to save any carries generated. Store the sum at memory locations 60H&61H. (50) = 10h, (51) = 25H, (52) = 2AH, (53) = 4FH, (54) = 60H, (55) = 3FH Sample data: (50) =10h, (51)=25h, (52)=2AH, (53)=4Fh, (54)=60h, (55)=3Fh Result = (60)=4Dh (61)=01h (MS byte) Source Code MOV R0, #50h MOV R2, #06h CLR A MOV R7, A AGAIN: ADD A, @R0 JNC NEXT INC R7 NEXT : INC R0 DJNZ R2, AGAIN MOV 60h, A MOV 61h, R7 HERE : SJMP HERE

014Dh

; Counter ; initial sum=0 ; clear R7 to save carry

; Keep track of carries

; store LSBy of sum ; store MSBy of sum

11

Format: for entering, executing & Checking results.

Enter source code <EXM MEM> <PRG MEM> 8000 <NXT> DATA <NXT>. <EXEC> Feed Sample Data <EXM MEM> <INTDATA> 50 <NXT> DATA <NXT> DATA.. <EXEC> <EXM MEM> <INTDATA> 60 <NXT>00XT>00<EXEC> Run the Program <GO><8000> <EXEC> Reset Check Results <EXM MEM> <INT DATA> 60 <NXT>.

4. Write an 8051 program to copy a block of 10 bytes of data from RAM locations starting at 35h to RAM locations starting at 60h. Sample Prob Source block (35)=10h, (36) =20h, (37) = 30h, (38) = 40h, (39) = 50h, (3A) = 60h, (3B) = 70h, (3C) = 80h, (3D) = 90h, (3E) =A0h MOV R0, #35h MOV R1, #60h MOV R3, #0Ah BACK: MOV A,@R0 MOV @R1, A INC R0 INC R1 DJNZ R3, BACK HERE: SJMP HERE ; Source pointer ; destination pointer ; counter

12

5. A byte is stored in register R0. Write a 8051 Program to find the Number of 1s in a byte stored in RO and Store the number of 1s in register R2. Let R0 = AAh MOV R0, #AAh MOV A, R0 MOV R2, #00h MOV R1, #08h LOOP: RLC A JNC CONT INC R2 CONT: DJNZ R1, LOOP HERE: SJMP HERE 10101010

6. Write a 8051 program to multiply two unsigned 8-bit binary Numbers. The numbers are stored in memory locations 8050h and 8051h. Store the result in 8060h and 8061h. Sample data: (8050)= 41h (65)10 (8051)= 08h (8060)= 08h (8061)= 02h i.e. 65X8 = (520)10 = 0208h MOV DPTR, #8051H MOVX A,@DPTR MOV 0F0h, A MOV DPTR, #8050h MOVX A,@DPTR MUL AB MOV DPTR, #8060h MOVX @DPTR, A INC DPTR MOV A, 0F0h MOVX @DPTR, A HERE: SJMP HERE

; multiplier in B reg ; multiplicand in A reg

13

7. Division of two unsigned 8-bit binary numbers. Divide the number in 8050h by the number in 8051h.Store the quotient and remainder in 8060h & 8061h of data memory respectively. Sample data: (8050) =41h dividend (8051)=08h divisor Result : (8060) =08h quotient (8061)=01h reminder

Hint: Similar to multiplication program. Store initial divisor in B reg and dividend in A reg. Use instruction DIV AB in place of MUL AB, After division operation, quotient is in A reg & remainder is in B reg.

8. Write a 8051 program to find the number 64h from the set of five Readings starting from address location 50H to 54h. If present Store 00h in R0, otherwise store FFh in R0. Sample Problem (1): i) (50) =76h, (51) =45h, (52) =64h, (53) =25h, (54) =22h. Result = (R0) =00h

MOV R1, #50h MOV R2, #05h LOOP: CJNE @R1, #64H, CONT MOV R0, #00h HERE1: SJMP HERE1 CONT: INC R1 DJNZ R2, LOOP MOV R0, #FFh HERE2: SJMP HERE2 Sample prob (2) Replace data in (52) by 94h Result = (R0) =FFh.

14

Program No 9: Multi byte Binary Addition. Write a Program to add 4627342AH to 32B35642H.The two binary strings starts (LSB first) in RAM memory 20H and 30H respectively and save the result in RAM Memory locations starting at 30H replacing the second binary string. Sample Proof: - 4627342A H +32B35642 H 78DA8A6CH Sample data. (20) =2AH, (21) =34H, (22) =27H, (23) =46H (30) =42H, (31) =56H, (32) =B3H, (33) =32H Result= (30) =6CH, (31) =8AH, (32) =DAH, (33) =78H. Source Code Listing MOV R0, #20H MOV R1, #30H MOV R3, #04H; Count=4 CLR C CLR A AGAIN: MOV A,@R0 ADDC A,@R1 MOV @R1, A INC R0 INC R1 DJNZ R3, AGAIN HERE: SJMP HERE.

15

Program N0 10: Multi byte BCD Addition. Write a Program to add 4 byte packed BCD 46273420H to 32105644H and save the BCD result in RAM memory locations starting at 30H. The two BCD Strings starts (LSB first) from RAM Locations 20H & 30H respectively. 46273420 +32105644 78379064 Source code listing MOV R0, #20H MOV R1, #30H MOV R3, #04H; COUNT=4 CLR C CLR A AGAIN: MOV A,@R0

ADDC A,@R1 DAA MOV @R1, A INC R0 INC R1 DJNZ R3, AGAIN HERE: SJMP HERE.

16

Program No 11: Multi byte Binary Subtraction Write a Program to subtract 14DF35B8H from 2F5BA7C3H, and save the result in RAM memory location Starting at 30H.The two binary strings starts(LSB first)from RAM location 20H & 30H respectively 2F5BA7C3H - 14DF35B8H 1A7C720BH Source code listing MOV R0, #20H MOV R1, #30H MOV R3, #04H CLR C CLR A AGAIN: MOV A,@R0 SUBB A,@R1 MOV @R1, A INC R0 INC R1 DJNZ R3, AGAIN HERE: SJMP HERE.

; COUNT = 4

17

Program No 12: Checking a character string for a Palindrome. Write a program to check if the character string of length 7, stored in RAM locations 50H onwards is a Palindrome. If it is, output Y to P1. Solution: A Palindrome is a string in which the characters are the same whether the string is read in the forward or backward direction. Example, MADAM, RADAR. MOV R2, #03 MOV R0, #50H MOV R1, #56H ; take half the string length as counter value ; take R0 as pointer to the forward reading ; take R1 as pointer for the backward reading Of the string ; move into A the character pointed by R0 ; move into B the character pointed by R1 ;compare it with the character pointed by R1 ; increment the forward counter ; decrement the backward counter ; repeat until all characters are compared ; since the string is a Palindrome output Y ; if not equal, do nothing since it is not a Palindrome

Back: MOV A, @R0 MOV B, @R1 CJNE A, B, NEXT INC R0 DEC R1 DJNZ R2, BACK MOV P1, #Y NEXT: NOP

END

18

EXPERIMENT -4 CODE CONVERSION 1) ASCII to Packed BCD Conversion Write a program to convert two ASCII decimal digits available in RAM locations 30H and 31H into packed BCD number and store the result in RAM location 40H. Sample data:- (30) =34H 4 (31)=37H 7 Result= (40) =47H (packed BCD) Source code listing MOV R0, #30H MOV R1, #40H MOV A,@R0 ANL A, #0FH SWAP A INC R0 MOV 02H,@R0 ANL R2, #0FH; mask upper nibble (R2=07H) ORL A, R2 ; A=47H, packed BCD ; mask upper nibble (A=04H) : A=40H

MOV @ R1, A ; store packed BCD HERE: SJMP HERE

19

2) Packed BCD to ASCII Conversion PROGRAM: Assume that register A has Packed BCD, write a program to convert packed BCD to two ASCII numbers and place them in RAM memory location 40H and 41H respectively. Source code listing MOV A, #29H MOV R2, A MOV R0, #40H ANL A, #0FH ORL A, #30 MOV R6, A MOV A, R2 ANL A, #0F0H SWAP A ORL A, #30H MOV R7, A MOV @R0, 06 INC R0 MOV @R0, 07 HERE: SJMP HERE ;A=29H,packed BCD ; copy of BCD data in R2 ;point to result location ;mask upper nibble ;make it an ASCII,A=39H ;save it ;get the packed BCD again ;mask lower nibble ;A=32H ;save ASCII ;store ASCII character ;in memory locations ; in memory locations

20

3) BCD to binary Conversion PROGRAM Sample example (40) = 6910 (packed BCD) Result= (50) = 45H (Binary equivalent) Steps. 1. Split the packed BCD into unpacked BCD digit BCD1 & BCD2 01101001 BCD1 00001001 BCD2 00000110 2. Multiply BCD2 by 10 3. Add BCD1 to the answer in step2 Source code listing MOV R0, #40H MOV R1, #50H MOV A, @R0 MOV R2, A ANL A, #0FH MOV R3, A MOV A, R2 ANL A, #0F0H SWAP A MOV 0F0H, #0AH MUL AB ADD A, R3 MOV @R1, A HERE : SJMP HERE

;get packed BCD in A reg ; save it in R2 reg ;mask the lower nibble ;BCD1 IN R3 ;get packed BCD again ;mask the upper nibble ;BCD2 in A reg ;Reg B loaded with 10 decimal ;add to BCD1` ;store binary equivalent

21

EXPERIMENT NO. 5 TIMER PROGRAMMING USING 8051


Task: Assuming XTAL = 11.0592MHz, write a program for timer 1 in mode 1 to generate a square wave of 2KHz frequency on Pin P1.5 (Pin No. 6) GND (Pin 20) Steps: T = 1/f = 1/2 KHz = 500s. Delay time = T/2 = 250s. 250s/1.085s = 230 clocks. 65536 230 = (65306)10 Initial count value = FF1A h TL1 = 1AH TH1 = FFH PROGRAM: MOV TMOD, #10H AGAIN: MOV TL1, #1AH MOV TH1, #0FFH SETB TR1 BACK: JNB TF1, BACK CLR TR1 CPL P1.5 CLR TF1 SJMP AGAIN ; Start timer 1 ; Stay until timer rolls over ; Stop timer ; complement P1.5 to get HI, LO ; clear timer flag ; reload timer ; timer1, mode1

Note: SFR address of TMOD = 89H, TL1 = 8BH, TH1 = 8DH, TR1 = 8EH, TF1 = 8FH, P1.5 = 95H. Note: Observe the output waveform across Pin 6 & 20 on CRO; and note down time period.

22

Write a program using timer 1 to generate a square wave of 2KHz frequency on Pin P1.5 (Pin 6) in mode 2 configuration (auto reload mode) GND (Pin 20) XTAL = 11.0592 MHz T = 1/f = 500s. Delay time = T/2 = 250s. 250s/1.085s = 230 clocks. 256 230 = (26)10 = 1A H Load TH1 with initial count value of 1AH. PROGRAM: MOV TMOD, #20h; timer1, mode2 MOV TH1, #1Ah SETB TR1 BACK: JNB TF1, BACK CPL P1.5 CLR TF1 SJMP BACK; mode 2 is auto reload. Note: Observe the output waveform across Pin 6 & 20 on CRO; and note down time period.

23

Experiment No.6 Communication with a Host Computer System


ESA 31 operating in the serial mode, can be connected to either a CRT terminal or a host computer system. When a computer system is the controlling element, it must be executing driver software to communicate with the ESA 31 target kit. ESA 31 is supplied with DOS communication driver package XT51 which allow the user to establish serial communication between the trainer and a host PC thro its Asynchronous com ports (COMI and COM2). INSTALLATION a) Configure ESA 86/88E for serial mode of operation and set the serial port of ESA 86/88E for 9600 Baud rate and No parity(keep DIP switches 1 and 4 in ON position) b) Connect the PC to ESA 31 trainer over COM1/COM2 serial port using the RS232C serial interface cable connecter.

The Serial mode of operation a) Supports for downloading user programs in to the target ESA 31 kit from a
Host computer system in INTEL HEX format. b) Also supports for uploading user program to host PC and saving them as HEX files o a system.

Using of X8051 Cross Assembler


A convenient way of creating a file to be downloaded in to ESA31 is to use a cross assembler for 8051 that can generate the object code in extended HEX format. X8051 is such a package. It is a powerful cross assembler for 8051. It can run on any PC/XT/AT compatible system and supports all the standard mnemonics, pseudo opcodes (directives) and addressing modes of 8051.

Steps involved in creating a HEX file are as follows:Step1:Select the path folder directory C:\> cd C:\> cd51 C:\> edit filename
24

Step2:Create a source file using the DOS text editor and save it as filename.asm. Example:
Write a source program for 16 bit addition using DOS text editor. The numbers are 3CEH and 3B8DH. Place the sum in R7 and R6; R6 should have the lower byte.

Org 8000h CLR C Mov a ,#0E7h Add a,#8Dh Mov r6,a Mov a,#3ch Addc a,#3bh Mov r7,a Here :sjmp here Save and exit from editor, Let the source file be saved as add 16.asm Step3:Assemble the source file add16.asm using X8051 to create an object file add16.obj as follows C:\51 x8051 Listing destination <N,T,D,E,L,P<CR>=N>:d Generate cross reference?<Y/N <CR>=N>:n Input Filename : add16.asm Output Filename: 8051 CROSS ASSEMBLER-VERSION 4.00f Input Filename : add16.asm Output Filename : add16.obj Lines Assembled:________ Assembly Errors:_______ C:\51
25

Step4:Link the single file add16.obj Specify code offset and options H for HEX format. This process creates a hex file add16.hex that can download into ESA 31 kit. C:\51 link51 Linker copyright<c>1985-version 4.00g Input Filename:add16.obj Enter Offset For CODE Input Filename: Output Filename: : 0

Options(D,S,A,M,X,H,E,T,1,2,3,(CR)=Default):h Link Errors:________ C:\51 Output Format:_______

Step5:-(Optional) Check the directory to see the files Created for add 16 C:\51 dir Also check the list file for add16 as C:\51 edit add16.list

Step6:Set the system in the serial communication mode using the XT51 command

C:\86>xt51
26

Now the following message will appears on the Screen __________________XT51 Version x, y_____________________ ELECTRO SYSTEM ASSOCIATES PVT LTD BANGALORE Press any Key to Continue _____________________________________________________________

XT51 Checks for the presence of communication ports COM1 and COM2 If Serial communication is established successfully the command prompt . Appears on the screen otherwise the communication parameters are set appropriately using ALT+S command and continue. Subsequently during the POWER ON RESET, the following sign on message appears on the screen followed by command prompt. ESA 31 MONITOR VERSION x.y

Step7:Download the program hex file from host PC to ESA 51 trainer using the CTRL+D command CTRL+D Specify download filename Add16.hex Specify memory type Specify starting address Specify ending address :P : 8000 :

Downloading program Run the program using G command as G 8000 Press Break Key Note:

27

If input data is to be entered use >md commands to enter the data. Press ESC key to return to command Prompt. > Use the M (Modify memory) command to examine the contents of specified memory locations. Further, if the locations are in RAM, their contents can be altered if desired. Format: - M {P|D|I|B} addresses 1[address 2] <cr> Ex 1: Examine a series of RAM locations starting at 8820H and modify the contents of the location 8822H. >MD88220 88220 XX<CR> 88221 XX<CR> 88222 XX 55<CR> > 88220 XX<ESC> EX 2: To enter data at int RAM locations starting at 40H. >MI 40<CR> 40 XX 21<CR> 41 XX 22<CR> 43 XX 55<CR> >44 XX<ESC> (2) M (Display Memory) Command. This command is used to display the contents of the Program or External or Internal Memory. Foramt: M {P|D|I}, address1.address2<CR> EX: To display the Contents of 5 Bytes from location 8020H. >Md8020, 8024<CR>.

MICROCONTROLLER LAB

28

EXPERIMENT NO.7 Generation of Waveforms using DAC interface module AIM: To write and execute program in 8051 assembly language for interfacing a DAC interface module with ESA 31 microcontroller trainer kit. APPARATUS: 1. ESA 31 Microcontroller trainer kit 2. Dual channel DAC module 3. Power supply units 4. 26 Pin connector cable 5. CRO DESCRIPTION: To use DAC, initialize 8255A for mode 0 operation with port A and port B as output. Output data on the appropriate port and observe output wave form at Xout and Yout of the DAC using CRO. The 16 bit port addresses for 8255A available at J2 connector are: Port A Equ E800H Port B Equ E801H Port C Equ E802H Port D Equ E803H Note: Port A controls Xout and Port B controls Yout of DAC interface module. PROGRAMS: 1. 2. 3. 4. Write an ALP to generate Saw tooth (Up-going and down-going) Write an ALP to generate Triangular waveform. Write an ALP to generate Symmetrical Square wave. Write an ALP to generate A). Up going stair case with 5 steps. B). Down going stair case with 5 steps.

29

Program 7.1 ; Assume the DAC interface is connected over J2 of the ESA 31 trainer. ORG 8000H PORT_A EQU E800H PORT_B EQU E801H PORT_C EQU E802H CWR EQU E803H ; Program to generate Continuous up going saw tooth. MOV MOV MOVX CLR AGAIN: MOV MOVX INC MOVX INC SJMP DPTR,#0E803H A,#80H @DPTR,A ;initialize 8255A for mode 0 with PA&PB as OUT A ;Start with value 00H DPTR, #0E800H;Point to Port A @DPTR,A ;Out to Port A and DPTR @DPTR,A ;Out to Port B A ;increment DAC input AGAIN ;Repeat forever.

; Program to generate continuous down going Sawtooth MOV MOV MOVX MOV AGAIN: MOV MOVX INC MOVX DEC SJMP DPTR,#0E803H A,#80H @DPTR,A A,#0FFH DPTR,#0E800H @DPTR,A DPTR @DPTR,A A AGAIN

30

; Program to generate continuous triangular waveform MOV DPTR,#0E803H MOV A,#80H MOVX @DPTR,A CLR A UP: MOV DPTR,#0E800H MOVX @DPTR,A INC DPTR MOVX @DPTR,A INC A CJNE A,#0FFH,UP DOWN :MOV DPTR,#0E800H MOVX @DPTR,A INC DPTR MOVX @DPTR,A DEC A CJNE A,#00H,DOWN SJMP UP ; Program to generate Symmetrical Square Wave MOV MOV MOVX BACK:MOV MOV MOVX MOV DLY1:DJNZ MOV MOVX MOV DLY2:DJNZ SJMP DPTR,#0E803H A,#80H @DPTR,A A,#0FFH DPTR,#0E800H @DPTR,A R0,#0FFH R0,DLY1 A,#00H @DPTR,A R0,#0FFH R0,DLY2 BACK

31

; Program for Stair case (Up-going) with 5 steps. MOV MOV MOVX MOV RPT: ADD MOV MOVX MOV DLY1: DJNZ CJNE INC MOVX MOV DLY2: DJNZ SJMP DPTR,#0E803H A,#80H @DPTR,A A,#00H A,#33H DPTR,#0E800H @DPTR,A R0,#0FFH R0,DLY1 A,#0FFH,RPT A @DPTR,A R0,#0FFH R0,DLY2 RPT

; Program for Stair case (down-going) with 5 steps MOV MOV MOVX MOV MOV RPT: MOVX MOV DLY1: DJNZ AGAIN:CLR SUBB MOVX MOV DLY2: DJNZ CJNE DEC SJMP DPTR,#0E803H A,#80H @DPTR,A A,#0FFH DPTR,#0E800H @DPTR,A R0,#0FFH R0,DLY1 C A,#33H @DPTR,A R0,#0FFH R0,DLY2 A,#00H,AGAIN A RPT

32

EXPERIMENT NO.8 Interfacing of Traffic Light Controller Using 8051 The traffic light interface simulates the control and operation of traffic lights at a junction of four roads. The interface provides a set of 6 LED indicators at each of the four corners. Each of these LED s can be controlled by a port line. Thus the interface allows the user to simulate a variety of traffic simulations using appropriate software routines. DESCRIPTION OF THE CIRCUIT : The organization of 6 LED s is identical at each of the four corners. The organization with reference to the LED s at South-West corner is shown in figure.1

R = SOUTH RED A = SOUTH AMBER L = SOUTH LEFT S= SOUTH STRAIGHT Rg=SOUTH RIGHT DL=SOUTH PEDESTRIAN

The five LED s (except Pedestrian) will be ON or OFF depending on the state of corresponding port line LED is ON, if the Port line is Logic HIGH and LED is OFF, if it is at logic LOW. The last LED marked DL is a set of two dual color LED s and they both will be either RED or GREEN depending on the state of the corresponding port line RED if the port line is logic HIGH and GREEN if the port line is logic LOW. 24 LEDS AND CORRESPONDING PORT LINES: PORT A: D7 D6 D5 D4 D3 D2 D1 D0 _____________________________________________ ER EA ERg EL SR SA SRg SL

33

PORT B: D7 D6 D5 D4 D3 D2 D1 D0 _____________________________________________ WR WA WRg WL NR NA NRg NL

PORT C: D7 D6 D5 D4 D3 D2 D1 D0 ____________________________________________ EP SP WP NP SS ES NS WS

There are four such sets of LED s and these are controlled by 24 port lines of 8255A. Each port line is inverted and buffered using 7406 (open collector inverter buffers) and is used to control an LED. Dual color LEDs are controlled by a port line and its complement. INSTALLATION: The interface module has 26 pin connector at one edge of the card. This is used for connecting the interface over J2 of the ESA 31 trainer. The trainer can be in KEYBOARD MODE or SERIAL MODE. PROBLEM STATEMENT: Generate the sequence for PA, PB, and PC such that the following traffic situations are simulated. 1. Vehicles from SOUTH can go NORTH and WEST Vehicles from WEST can go NORTH Vehicles from NORTH can go SOUTH Pedestrians can cross on EAST 2. Vehicles from EAST can go WEST and SOUTH Vehicles from WEST can go EAST Vehicles from SOUTH can go WEST Pedestrians can cross on NORTH 3. Vehicles from EAST can go SOUTH Vehicles from NORTH can go SOUTH and EAST Vehicles from SOUTH can go NORTH Pedestrians can cross on WEST

34

4. Vehicles from EAST can go WEST Vehicles from WEST can go EAST and NORTH Vehicles from NORTH can go EAST Pedestrians can cross on SOUTH 5. No vehicle movement Pedestrians can cross on all four roads.

The system moves from one state to another state after fixed time delay. The state transition is indicated by turning ON all the AMBER LEDs and all Pedestrians RED LEDs for a fixed duration. The sequence of the above states is repeated again and again. ; Program memory from 8000H to 804FH ORG PORTA PORTB PORTC CWR MOV MOV MOVX AGAIN: MOV NEXTST: MOVX PUSH PUSH MOV MOVX POP POP INC MOVX PUSH PUSH MOV MOVX POP POP INC MOVX PUSH PUSH MOV MOVX 8000H E800H E801H E802H E803H

EQU EQU EQEU EQU

DPTR,#0E803H A,#80H @DPTR,A DPTR,#PORTS A,@DPTR DPL DPH DPTR,#0E800H @DPTR,A DPH DPL DPTR A,@DPTR DPL DPH DPTR,0E801H @DPTR,A DPH DPL DPTR A,@DPTR DPL DPH DPTR,#0E802H @DPTR,A

;Port A value.

;Port B value.

;Port C value.

35

POP POP INC LCALL MOV CJNE SJMP DELAY: MOV LOOP3: MOV LOOP2: MOV LOOP1: DEC CJNE DEC CJNE DEC CJNE RET

DPH DPL DPTR DELAY A,DPL A,#1EH,NEXTST AGAIN R2,#06 R4,#0FFH R3, #0FFH R3 R3,#00,LOOP1 R4 R4,#00,LOOP2 R2 R2,#00,LOOP3

;Provide delay

;Delay routine

; Enter the data mentioned below from 0000H to 001EH in data memory. PORTS: DB DB DB DB DB DB DB DB DB DB DB 10H, 81H, 7AH 44H, 44H, 0F0H 08H, 11H, 0E5H 44H, 44H, 0F0H 81H, 10H, 0DAH 44H, 44H, 0F0H 11H, 08H, 0B5H 44H, 44H, 0F0H 88H, 88H, 00H 44H, 44H, 0F0 00H ;state 1 ;All Ambers ON ;State 2 ;All Ambers ON ;State 3 ;State 4 ;State 5 ;Dummy

36

Vous aimerez peut-être aussi