Table of Contents
1. Introduction to Simulator 2. Data Move Instructions MOV, MOVX, MOVC 3. Introduction to Kit / Arithmetic Instructions 4. Bit level Programming 5. Logical instruction

Jump and Call Instructions----- Short and Long jumps

7. Interrupts 8. Seven Segment and Keyboard interfacing 9. LCD interfacing


Introduction To

Simulator usually shows the internal register and memory location on the screen of the personal computer and allows the programmer to perform all of the operations. One can also watch the data change as the program operates. This saves considerable time because the register and memory contents do not have to be displayed using separate monitor commands. The visual representation also gives the programmer better feel for what is taking place in the program. The 8051 simulator runs on IBM PC and compatible computers and the requirements for the PC are :  512 K RAM  DOS version 2.1 or newer  IBM mono, CGA, EGA compatible monitor  Two disk drives How to Simulate a Program: 1. 2. 3. 4. 5. 6. Go to the command prompt and type a51<filename.asm> Go to the command prompt and type s51 Type L for Load Type P for previous machine Then type book.bss Again type L for load 7. Then type O for object file <filename.obj> 8. Now press R to run To run a simulation the screen set file is loaded into the simulator first followed by programming the object code format. The program is then run using this simulator commands:  Reset the program counter(PC) to 0000H  Single step the program  Free run the program  Free run until breaking is reached  Stop free run

TL0. .TH0 and TH1 can be found in the internal RAM window 2 which displays a portion of the SFR area. DPTR. A. 2. The SP. Internal RAM window 1 shows registers banks 0 and 1.lst. Screen 4: (ALT-F4) The external RAM screen External RAM from addresses 0000h to 00BFh are displayed in external data memory windows 1 to 3. Also observe the . which includes SCON and SBUF. Try to assemble any set of instructions (detailed idea of the instructions not expected) and also simulate the program.DPH. Special function registers DPL.DPTR and instruction execution windows are also part of this screen. Screen 2: (ALT-F2) The internal RAM Screen Internal RAM windows 3 to 5 display internal RAM from 10h to 3fh. The PC.A. DPTR and instruction execution windows are also part of this screen. TL1. A and PC are also shown.MICROCONTRELLER LAB MANUAL Screen 1: (ALT-F1) The main screen The viewer can observe the operations of the PC.SP. Define • Machine language • Assembly language • Lower level language • Higher level language • Assembler • Linker • Cross compiler • Interpreter • Simulator 3 . Window 6 shows the SFR area. The PC. Screen 3: (ALT-F3) The code ROM Screen Program code addresses from 0000h to 00BFh are displayed in code memory windows1 to 3. Exercise:1.obj and .PCON.exe file. An instruction execution window will display program mnemonics as the program is operated.IE and A registers and ports P1 and P3 in individual windows.TMOD.

r2 10h. • What is size of registers in program? • What will be the size of the date bus accordingly? • What will be the contents of the PC at the instruction mov r0.#10h b.#10h r1.MICROCONTRELLER LAB MANUAL 2. 4) Write the function of each instruction used in the program. 3) Find out the total length of the program.#10h r0. 2) To understand how 8051 executes a program-using simulator. 5) Modify the above program to reduce its size. Transfer ction Objectives:- Data Instru 1) To understand the data transfer operations in the 8051. 4 .#FFh Modifications: 1) Check all the instruction whether they are valid or not. also write the addresses of the individual instruction assuming the initial address in number of bytes of the program after correction. Sample program: mov mov mov mov mov mov a. Exercise:• Write down the hex code for the instructions and differentiate opcodes and operands. 2) Rewrite the instructions.a r1.a ? • Mention addressing mode of each instruction. which are invalid so as to provide the same function.

5 . • Do inverse of program 8.MICROCONTRELLER LAB MANUAL • Write down the sequence of steps for the first instructions from fetching it from memory to its execution in the CPU. • Write a program to transfer byte from code memory to internal RAM and external RAM. • Write instructions to transfer the value 10H to internal RAM location 8H. 0010H and 0100H.external ram location 0008H and 0100H. • Write a program to transfer byte from external RAM to external ROM. • Write an instruction or a set of instructions to transfer a byte from internal RAM location 7H to external RAM location 0007H. • Write a program to transfer byte from internal RAM to internal ROM.

#30h mov a.#20h mov 40h. Reduce the size of the program Length wise Machine cycle wise State the function of addc function. Arithmetic Instructions Objectives: 1) To understand arithmetic operation of the 8051 and their limitation.#00h mov a. Sample Program:mov 3Fh.MICROCONTRELLER LAB MANUAL 3.a Modifications:1) 2) 3) 4) 5) Identify the function of the program.#00h addc a.3fh and a. 2) To follow the instruction execution at machine cycle level. 6 .40h mov 41h.a mov 42h.42h mov 42h.

-70d + (-70d). -30d + (-50d). 100d + 50d. Div and DAA (BCD addition) of two numbers. • Write a program to reverse the elements of an array. • Write a program to Mul. 45d +75d. -1d + 27d. Store the result with carry/borrow.MICROCONTRELLER LAB MANUAL Exercise:• Write a program to perform addition/subtraction of two 32-bit numbers. 7 . • Write a program to count number of positive negative and zero elements of an array of eight bit signed elements. • Do signed additions.

#00h mov dpl.a movc a.a Modifications: 1) What is the function of above program ? 2) Modify the above program to complement the lower nibble and set the higher nibble to 1111 in the bytes of the code memory.@a+dptr anl a. Store the resulting bytes in same external RAM location.a mov a.@a+dptr mov r1.a movc a.r1 movx @dptr.MICROCONTRELLER LAB MANUAL 4. mov a.a mov a. 8 . 2) To follow the instruction execution at machine cycle level Sample program.r0 swap a anl dph.#0fh anl 01h.#0fh movx @ro. ctions Objectives: Logic Instru 1) To understand arithmetic operation of the 8051 and their limitation.r0 swap a mov r0.#21h mov r0.a mov a.

Mask of the upper nibble of R0 by ones. • Write a program to transfer the LSB of 4 memory locations starting from 0f00H in the code memory in lower nibble of R0. 9 .MICROCONTRELLER LAB MANUAL Exercise: • Write a program to find parity of a 16 bit number.

c mov psw.a Modifications:1) Reduce the length of the above program.#0ch mov 20h.4.acc.30h clr c mov psw. To compare the effects of bit level and byte level operations on various elements of the 8051.0 cpl c mov 01h.c mov r0. Sample Program:mov a.3.MICROCONTRELLER LAB MANUAL 5. 2) Rewrite the above program so as to repeat the above operation on 10 eight-bit numbers starting from 30h.c mov a. Exercise: • Implement function Y1 = ABC + ABC +ABC 10 .#0eh mov c.r0 mov r0. Level Instructions Objective: Bit 1).20h orl a.

#00h mov dptr. 3) To understand the importance of stack with reference to branching.@dptr mov r7.#4000h movx a.MICROCONTRELLER LAB MANUAL Y2 = ABC + ABC +ABC Jumps & Cal ls Objectives: 1) To develop the ability of transferring control within a program.lowhigh sjmp limit lowhigh: jnc back limit: mov a.r1 movx @dptr. 2) To identify the situation where a sub program can be used for helping the main program.r7 anl a.a sjmp same again: next: same: checkbcd: clr 00h mov a.#09h.a inc dptr movx a.next inc r1 djnz ro.a lcall check bcd jnb 00h. Sample program: mov r1.@dptr mov r0.r7 11 .again inc dptr mov a.#ofh cjne a.

End of the array is detected by a non-BCD number. Identify the function of the program. • Write a program to transfer 10 bytes from internal RAM 30H onwards to external RAM 30H onwards. Reduce the size of the program  Length wise  Machine cycle wise Exercise: • Rewrite the subroutine using jc instruction. 12 .final Setone: setb 00h Back: ret Final: jnc back sjmp setone .#09h. • Write a program using procedure to find the number of one in dptr.MICROCONTRELLER LAB MANUAL anl a. Count the number of elements in array. 2.end Modifications: 1.#0f0h swap a cjne a. • Rewrite the main program using jb instruction • An array of BCD numbers starts from 4001h in memory. • Write a program to transfer 10 bytes from external RAM location 30H onwards to 300H onwards.

#3ch mov th0.MICROCONTRELLER LAB MANUAL 7. 2) To realize hardware requirements for using external interrupt in place of internal interrupt.0 mov r0.#01h mov ie.#5dh reti .#82h setb tr0 here: cjne r0.#20h.org 0000h mov r0. Objectives: Interrupts 1) To understand the concept of interrupts and distinguish normal subroutine and service routine.end 13 .#00h mov tl0.#3ch mov th0.org 000bh inc r0 mov tl0.#5dh mov tmod. Sample program: .#00h sjmp here .here cpl p1.

• Interface a push button switch at one of the external interrupt pins.MICROCONTRELLER LAB MANUAL Modification: 1) Modify the above program such that you write a delay routine of 0. Note:. Also see what all problems you are facing. 14 . • Now interface the push button with keydebouncing circuit and see the difference between the two. Also mention the setting of various SFRs.5ms. Write an assembly program such that every time you push the button your accumulator is incremented by one and the content is transferred to an external memory location. Exercise: • Write the program to generate a pure software delay of one second demonstrate on an oscilloscope.Crystal frequency = 10 Mhz. which is called 100 times which in turn is called 20 times.

2) To understand the operation of keyboard matrix.2 15 . And Segment Keyboard Seven Interfacing Objective: 1) To develop a program based on available hardware to utilize keyboard and seven segment display devices.0 setb 20h lcall routine setb p1.#00h .0 clr p1. first bit is used to provide the ground mov 20h.#0ffh mov p3.2 clr 21h setb 22h lcall routine setb p1.1 clr 20h setb 21h lcall routine setb p1. Sample Program: repeat: . to common cathode seven segment mov p2.#0ffh mov p1.1 clr p1.org 0000h mov p0.#00h .#00000001b clr p1.MICROCONTRELLER LAB MANUAL 8.

#10110110b ljmp last .4 ljmp repeat routine: mov a.1.a cjne a.3 clr p1. display pattern for 6 .row03 mov p2.MICROCONTRELLER LAB MANUAL clr p1.#11111010b ljmp last row02: jnb 22h. display pattern for 1 .row11 mov p2.#11111000b ljmp last col1: jb acc.col1 jnb 20h. display pattern for b row03: mov p2.col2 jnb 20h. display pattern for 2 16 .p0 mov r0.3 clr 22h setb 23h lcall routine setb p1.row01 mov p2.check last: ret check: jb acc.0. display pattern for A .#11011110b ljmp last .4 clr 23h setb 24h lcall routine setb p1.row02 mov p2.#0ffh.#00001100b ljmp last row01: jnb 21h.

display pattern for E row13: mov p2.row23 mov p2. display pattern for 7 . 17 mov p2. .#11110011b . display pattern for d .#11001000b ljmp last row31: jnb 21h.#00001110b ljmp last row12: jnb 22h.#11111001b ljmp last col3: jb acc.last jnb 20h. display pattern for 4 .2. row23: mov p2. display pattern for 8 .row13 mov p2.row31 mov p2.MICROCONTRELLER LAB MANUAL row11: jnb 21h.#11111110b ljmp last row22: jnb 22h.#11110010b ljmp last col2: jb acc. display pattern for 3 .row33 mov p2.#00111110b ljmp last row21: jnb 21h.row12 mov p2.col3 jnb 20h.3. display pattern for E. display pattern for A.#11011111b ljmp last .#10111100b ljmp last .row32 mov p2. display pattern for d. display pattern for 9 . display pattern for b.row22 mov p2.#11011110b ljmp last row32: jnb 22h. .row21 mov p2.#10111101b ljmp last row33: .

18 .MICROCONTRELLER LAB MANUAL ljmp last .end Exercise: 1) Find out the output of the program. 2) Now modify the program and interface two seven segments and continuously scroll GOD over it.

cursor off acall command lcall delay .#3ch . 2) To write a program for displaying desired information on the LCD Sample Program 1: . cursor on.#070h .0.no blink 19 . blinking acall command lcall delay .0.0.org 0000h clr p1.here6 mov a.MICROCONTRELLER LAB MANUAL 9.#0f0h .#0b0h . erfacing Objective: LCD Int 1) To study the LCD interfacing in the available hardware using various commands.here0 mov a. herex: jb p3.0. here6: jb p3.8bits. 2 rows.wait for key mov a.screen on. 5*10 acall command lcall delay here0: jb p3.3 lcdisp: jb p3.lcdisp .herex mov a.

blink off. here1: jb p3.cursor off.0. screen on acall command lcall delay here9: jb p3.#0e1h .0.here9 mov a.#30h .shift cursor right acall command lcall delay here2: jb p3.#40h .cursor off.position of cursor line1.#60h .here5 mov a.here2 mov a. screen on acall command mov a.0.0.screen off mov a.space7 acall command here8: jb p3.home cursor and clear memory acall command 20 .display 'H' lcall delay here3: jb p3.#0b0h .0.#0D0h acall command lcall delay .here1 mov a.#12h acall display .here3 mov a.here8 .0. here5: jb p3.MICROCONTRELLER LAB MANUAL acall command lcall delay .

here7 mov a.a clr p1.rw setb p1.1 .wait clr p1.0.MICROCONTRELLER LAB MANUAL lcall delay here4: jb p3.0.cs clr p1.2 .#80h .cs ret ready: clr p1.rw setb p1.cs jb p2.home cursor and clear memory acall command here:sjmp here command: acall ready mov p2. .rs setb p1.1 .cs ret display: acall ready mov p2.rs clr p1.2 .bsy 21 .0 .0 .#0ffh clr p1.cs ret .0 .cs setb p1.0 .cs mov p2.0 .a setb p1.0 .rs clr p1.2 .0 .#12h .display 'H' acall display lcall delay here7: jb p3.0 .here4 mov a.1 .cs clr p1.rw wait: clr p1.0.

screen on.#10100010b acall display mov a. 2 rows. cursor on.wait for key mov a.here0 mov a.#12h acall display mov a.org 0000h clr p1.#0ffh mov r4. blinking acall command mov a.#60h . 5*10 acall command lcall delay here0: jb p3.delay2 Sample Program 2: .MICROCONTRELLER LAB MANUAL delay: delay1: delay2: delay3: delay4: djnz djnz ret . delay4 r5.#0ffh djnz r4.cursor shift acall command mov a.3 lcdisp: jb p3.#0ah mov r5.0.display 'l' 22 .#3ch .delay3 r6.0.display 'e' .8bits.end nop mov r6.#0f0h .#00110010b .display 'H' .lcdisp .

display 'e' .#11110010b acall display lcall delay here1: jb p3.#80h .#0a0h .#11110010b acall display lcall delay here4: jb p3.0.display '0' mov a.#00110010b acall display mov a.display '0' .#10100010b acall display mov a.#00110010b acall display .#0e0h .here4 mov a.display 'H' .screen shift acall command mov a.here5 23 .display 'l' .#00110010b acall display mov a.screen shift(right) acall command here5: jb p3.clear screen acall command mov a.#12h acall display mov a.display 'l' .MICROCONTRELLER LAB MANUAL acall display mov a.display 'l' mov a.0.0.here1 .

#0a0h .#80h .display 'l' .#12h acall display mov a.#00110010b acall display mov a.#60h .screen shift(left) acall command here3: jb p3.clear screen acall command mov a.display 'l' .0. cursor off.#0a0h .here3 mov a.screen on.0.cursor shift acall command mov a.#30h . blinking off acall command mov a.here2 mov a.MICROCONTRELLER LAB MANUAL mov a.display 'o' 24 .#00110010b acall display mov a.#10100010b acall display mov a.screen shift(left) acall command lcall delay here2: jb p3.display 'h' .display 'e' .#11110010b acall display here: ljmp here .

rs clr p1.0 .cs ret display: acall ready mov p2.rw setb p1.#0ffh mov r4.cs ret ready: clr p1.#0ffh djnz r4.cs clr p1.cs jb p2.wait clr p1.bsy nop mov r6.1 .1 .0.rs setb p1.a clr p1.end .0 .0 .1 .0 .0 .MICROCONTRELLER LAB MANUAL command: acall ready mov p2.rs clr p1.2 .cs setb p1.delay3 r6.0 .rw setb p1.0 . delay4 r5.2 .0 .delay2 25 .cs ret delay: delay1: delay2: delay3: delay4: djnz djnz ret .a setb p1.cs mov p2.#0ffh clr p1.cs clr p1.rw wait: clr p1.2 .#0ah mov r5.

MICROCONTRELLER LAB MANUAL Exercise: • Find out the output of the programs. 26 . • Now modify the program to display two words in two screens and swap them.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.