Top Banner
Microcontroller 8051 Lab Manual VENKATASWAMY R www.venkataswamy.page.tl EEE, SJCE, MYSORE 1 MICROCONTROLLER 8051 LABMANUAL R VENKATASWAMY E & E E, SJCE MYSORE [email protected]
28

8051 Venkat

Apr 08, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 1

MICROCONTROLLER 8051

LABMANUAL

R VENKATASWAMY E & E E, SJCE

MYSORE

[email protected]

Page 2: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 2

Contents

I. PROGRAMMING

1. Data Transfer - Block move, Exchange, Sorting, Finding largest element in an array.

2. Arithmetic Instructions - Addition/subtraction, multiplication and

division, square, Cube – (16 bits Arithmetic operations – bit addressable).

3. Counters.

4. Boolean & Logical Instructions (Bit manipulations).

5. Conditional CALL & RETURN.

6. Code conversion: BCD – ASCII; ASCII – Decimal; Decimal -

ASCII; HEX - Decimal and Decimal – HEX.

7. Programs to generate delay, Programs using serial port and on-Chip timer/ counter.

II. INTERFACING

Write C programs to interface 8051 chip to Interfacing modules to develop single chip solutions.

8. Simple Calculator using 6 digit seven segment display and Hex

Keyboard interface to 8051. 9. Alphanumeric LCD panel and Hex keypad input interface to

8051.

10. External ADC and Temperature control interface to 8051.

11. Generate different waveforms Sine, Square, Triangular, Ramp etc. using DAC interface to 8051; change the frequency and amplitude.

12. Stepper and DC motor control interface to 8051.

13. Elevator interface to 8051.

Page 3: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 3

Assembly Programming

Page 4: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 4

1. Write an ALP to move block of data bytes present in internal memory with starting address 10h and ending address 20h to the destination memory with starting address 30h.

(Without overlap).

Address Label Mnemonic Comment 9000 MOV R1,#10H Starting addr of src

MOV R2,#20H Ending addr of src MOV R0,#30H Starting addr of desti CLR C MOV A,R2 SUBB A,R1 MOV R2,A

Determination of size And stored in R2

LOOP MOV A,@R1 MOV @R0,A

Copy data byte

INC R1 INC R0 DJNZ R2,LOOP LCALL 0003

2. Write an ALP to move block of data bytes present in internal memory with

starting address 10h and ending address 20h to the destination memory with starting address 15h.

(With overlap).

Address Label Mnemonic Comment 9000 MOV R1,#10H Starting addr of src

MOV R2,#20H Ending addr of src MOV R0,#15H Starting addr of desti CLR C MOV A,R2 SUBB A,R1 MOV R2,A

Determination of size And stored in R2

MOV A,R1 ADD A,R2 MOV R1,A

End addr of src

MOV A,R0 ADD A,R2 MOV R0,A

End addr of desti

INC R2 LOOP MOV A,@R1 MOV @R0,A

Copy data byte

DEC R1 DEC R0 DJNZ R2,LOOP LCALL 0003

Page 5: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 5

3. Write an ALP to move block of data bytes present in external memory with starting address 8000h to the destination memory with starting address 9000h and size of array is 10h.

Address Label Mnemonic Comment

8500 MOV R0,#10H Size of an array MOV 82H,#00H DPL=00 LOOP MOV 83H,#80H DPH=80 MOVX A,@DPTR Src data to acc MOV 83H,#90H DPH=90 MOV @DPTR,A Acc to desti INC DPTR DJNZ R0,LOOP LCALL 0003H

4. Write an ALP to exchange block of data bytes present in external memory. Starting address of first is 8000h and starting address of other block 9000h and size of array is 10h.

Address Label Mnemonic Comment

8500 MOV R0,#10H Size of an array MOV 82H,#00H DPL=00h LOOP MOV 83H,#80H DPH=80h MOVX A,@DPTR Src data to acc MOV R1,A MOV 83H,#90H DPH=90h MOV A,@DPTR XCH A,R1 MOVX @DPTR,A MOV 83H,#80H DPH=80h MOV A,R1 MOVX @DPTR,A INC DPTR DJNZ R0,LOOP LCALL 0003H

Page 6: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 6

5. Write an ALP to sort a given array present in external memory with a starting address 9000h and size of an array is 10h using bubble sort technique.

Address Label Mnemonic Comment

8000 MOV R1,#10H Outer loop count OUTLOOP MOV R0,#10H Inner loop count MOV DPTR,#9000H INLOOP CLR C Carry=0 MOVX A,@DPTR MOV R2,A R2=first no INC DPTR MOVX A,@DPTR Acc=second no MOV R3,A SUBB A,R3 Compare JNC SKIP XCH A,R2 Exchange SKIP MOVX @DPTR,A Big no mem DEC 82H DPL=DPL-1 MOV A,R2 MOVX @DPTR,A Small no mem INC DPTR DEC R0 CJNE R0,#01H,INLOOP DEC R1 CJNE R1,#01H,OUTLOOP LCALL 0003H

6. Write an ALP to add ‘n’ bytes stored in external RAM (Starting address 9000 and no of bytes is 10 or 0Ah)

Address Label Mnemonic Comment

8000 MOV R0,#0A No of bytes MOV R1,#00 R1=SUM=0 MOV DPTR,#9000 DPTR=9000 LOOP MOVX A,@DPTR ADD A,R1 Sum=sum+n[i] MOV R1,A INC DPTR DJNZ R0,LOOP LCALL 0003

Page 7: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 7

7. Write an ALP to find largest element in a given array present in external memory with a starting address 9000h and size of an array is 10h.

Address Label Mnemonic Comment

8000 MOV R0,#10H count MOV DPTR,#9000H LOOP CLR C Carry=0 MOVX A,@DPTR MOV R2,A R2=first no INC DPTR MOVX A,@DPTR Acc=second no MOV R3,A SUBB A,R3 Compare JNC SKIP XCH A,R2 Exchange SKIP MOVX @DPTR,A Big no mem DEC 82H DPL=DPL-1 MOV A,R2 MOVX @DPTR,A Small no mem INC DPTR DEC R0 CJNE R0,#01H, LOOP INC DPTR MOV A,@DPTR A=largest no LCALL 0003H

8. Write an ALP to search a byte in an array of bytes stored in external RAM.

Address Label Mnemonic Comment 8000 MOV R0,#0A Array size

MOV R1,#10 Search value MOV R2,#00 Count MOV DPTR,#9000 MOVX A,@DPTR CLR C SUBB A,R1 compare INC DPTR JNZ SKIP INC R2 DJNZ R0,LOOP LCALL 0003

Page 8: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 8

9. Write an ALP to illustrate addition, subtraction, multiplication and division of two 8 bit numbers.

Address Label Mnemonic Comment

8000 MOV R1,#20H First no MOV R2,#10H Second no MOV A,R1 ADD A,R2 MOV R0,A

ADDITION R0=R1+R2

CLR C MOV A,R1 SUBB A,R2 MOV R3,A

SUBTRACTION R3=R1-R2

MOV A,R1 MOV F0,R2 MUL AB MOV R4,A

MULTIPLICATION R4=R1xR2

MOV A,R1 MOV B,R2 DIV AB MOV R5,A

Division R5=R1/R2

LCALL 0003H

10. Write an ALP to illustrate logical operations like AND, OR, NOT and XOR

Address Label Mnemonic Comment 8000 MOV R1,#20H First BYTE

MOV R2,#10H Second BYTE MOV A,R1 ANL A,R2 MOV R0,A

ANDING R0=R1 AND R2

MOV A,R1 ORL A,R2 MOV R3,A

ORING R3=R1 OR R2

MOV A,R1 CPL A MOV R4,A

NEGATION R4=~R1

MOV A,R1 XRL A,R2 MOV R5,A

XORING R5=R1 XOR R2

LCALL 0003H

Page 9: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 9

11. Write an ALP to add two 2 byte numbers.

Address Label Mnemonic Comment 8000 MOV R1,#12

MOV R2,#34 MOV R3,#56 MOV R4,#78

3412 7856 ------- 0AC68

MOV R7,#00 3rd byte=0 CLR C MOV A,R1 ADD A,R3 MOV R5,A MOV A,R2 ADDC A,R4 MOV R6,A JNC SKIP MOV R7,#01 3rd byte=1 SKIP LCALL 0003

12. Write an ALP to subtract 2 byte number from another 2 byte number.

Address Label Mnemonic Comment 8000 MOV R1,#56

MOV R2,#78 MOV R3,#12 MOV R4,#34

7856 3412 ------- 4444

CLR C MOV A,R1 SUBB A,R3 MOV R5,A MOV A,R2 SUBB A,R4 MOV R6,A LCALL 0003

Page 10: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 10

13. Write an ALP to illustrate hexadecimal up counter with a given staring and ending value.

Address Label Mnemonic Comment

8000 MAIN MOV A,#00 Starting value MOV F0,#FF Ending value LOOP MOV R6,A MOV R3,A LCALL 677D Display R6 data MOV R0,#FF MOV R1,#FF LCALL 6850 Delay MOV R0,#FF MOV R1,#FF MOV A,R3 INC A Next value CJNE A,F0,LOOP LJMP MAIN

14. Write an ALP to illustrate hexadecimal down counter with a given staring and ending value.

Address Label Mnemonic Comment

8000 MAIN MOV A,#FF Starting value MOV F0,#00 Ending value LOOP MOV R6,A MOV R3,A LCALL 677D Display R6 data MOV R0,#FF MOV R1,#FF LCALL 6850 Delay MOV R0,#FF MOV R1,#FF MOV A,R3 DEC A Next value CJNE A,F0,LOOP LJMP MAIN

Page 11: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 11

15. Write an ALP to illustrate decimal up counter with a given staring and ending value.

Address Label Mnemonic Comment

8000 MAIN MOV A,#00 Starting value MOV F0,#99 Ending value LOOP ADD A,#00 DA A MOV R6,A MOV R3,A LCALL 677D Display R6 data MOV R0,#FF MOV R1,#FF LCALL 6850 Delay MOV R0,#FF MOV R1,#FF MOV A,R3 INC A Next value CJNE A,F0,LOOP LJMP MAIN

16. Write an ALP to illustrate decimal down counter with a given staring and ending value.

Address Label Mnemonic Comment

8000 MAIN MOV A,#99 Starting value MOV F0,#00 Ending value LOOP ADD A,#00 DA A MOV R6,A MOV R3,A LCALL 677D Display R6 data MOV R0,#FF MOV R1,#FF LCALL 6850 Delay MOV R0,#FF MOV R1,#FF MOV A,R3 DEC A Next value CJNE A,F0,LOOP LJMP MAIN

Page 12: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 12

17. Write an ALP to demonstrate call and return instruction using a program to find factorial of a number.

Address Label Mnemonic Comment

8000 MOV R0,#05 Input number MOV A,R0 LCALL 9000 LCALL FACT LCALL 0003

9000 FACT CJNE R0,#01,9005 CJNE R0,#01,LOOP RET

9005 LOOP DEC R0 MOV F0,R0 MUL AB LJMP 9000 LJMP FACT

18. Write an ALP to convert decimal number to its equivalent hexadecimal number.

Address Label Mnemonic Comment

8000 MOV R0,#16 R0=Input byte MOV A,R0 ANL A,#F0 SWAP A MOV F0,#0A MUL AB MOV R1,A MOV A,R0 ANL A,#0F ADD A,R1 MOV R1,A R1=Output byte LCALL 0003

Page 13: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 13

19. Write an ALP to convert hexadecimal number to its equivalent decimal

number.

Address Label Mnemonic Comment 8000 MOV R0,#FF Input no

MOV A,R0 MOV F0,#64 B=64h DIV AB MOV R1,A First dgt MOV A,B MOV F0,#0A B=0Ah DIV AB MOV R2,A Second dgt MOV A,B MOV R3,F0 Third dgt MOV A,R2 SWAP A ADD A,R3 MOV R2,A LCALL 0003

Pack R2 & R3 to R2

20. Write an ALP to convert decimal number to its equivalent ASCII code.

Address Label Mnemonic Comment

8000 MOV R1,#0B Input char MOV A,R1 LCALL 9000 LCALL CONV LCALL 0003

9000 CONV CLR C 9001 SUBB A,#0A 9003 MOV A,R1 9004 JC 9009 JC DGT 9006 ADD A,#37 ASCII(CHAR) 9008 RET 9009 DGT ADD A,#30 ASCII(NUMBER) 900B RET

Page 14: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 14

21. Write an ALP to convert ASCII code to its equivalent decimal number.

Address Label Mnemonic Comment

8000 MOV R1,#39 Input char MOV A,R1 LCALL 9000 LCALL CONV LCALL 0003

9000 CONV CLR C SUBB A,#41 MOV A,R1 JC DGT CLR C SUBB A,#37 ASCII CHAR RET DGT CLR C SUBB A,#30 ASCII NUMBER RET

22. Write an ALP to convert BCD to its equivalent ASCII code.

Address Label Mnemonic Comment 8000 MOV R0,#23 Input char

LCALL 9000 LCALL CONV LCALL 0003

9000 CONV MOV A,R0 ANL A,#0F ADD A,#30 MOV R1,A ASCII(FIRST DGT) MOV A,R0 ANL A,#F0 SWAP A ADD A,#30 MOV R2,A ASCII(SECOND DGT)

RET

Page 15: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 15

Interfacing &

C Programming

Page 16: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 16

C Program to interface stepper motor to 8051 microcontroller and to rotate stepper motor in a clockwise and anti clockwise direction.

#include <Intel/8051.h> #define p8255_ctl 0x2043 #define portc 0x2042 #define ctlr_word 0x80 // for clockwise phasea is 0d, phaseb is 0e, phasec is 07 and phased is 0b // for anti clockwise phasea is 0b, phaseb is 07, phasec is 0e and phased is 0d #define phasea 0x0d #define phaseb 0x0e #define phasec 0x07 #define phased 0x0b xdata unsigned char *ptr_8255_ctl; xdata unsigned char *ptr_8255_portc; void delay(void); void main () {

int i; ptr_8255_ctl = p8255_ctl; *ptr_8255_ctl = ctlr_word;

while(1) {

ptr_8255_portc=portc; //porta address is taken in pointer variable //different speeds are loaded into pointer

*ptr_8255_portc = phasea; delay(); *ptr_8255_portc = phaseb; delay(); *ptr_8255_portc = phasec; delay(); *ptr_8255_portc = phased; delay();

} } void delay(void) {

int i=0; for(i=0;i<=10000;i++){}

}

Page 17: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 17

C program to demonstrate elevator double priority operation using control circuit consisting of LEDs and keys.

#include <Intel\8051.h> #define p8255_ctl 0x2043 #define porta 0x2040 #define portb 0x2041 #define portc 0x2042 #define ctl_word 0x82 // Port A-Output Port B-Input void floor1(void); void floor2(void); void floor3(void); void floor4(void); void moveup(void); void movedown(void); void delay_ms(void); idata unsigned char req,preq,freq,temp,fg,i,j; xdata unsigned char *ptr_8255_ctl; xdata unsigned char *ptr_8255_porta; xdata unsigned char *ptr_8255_portb; xdata unsigned char *ptr_8255_portc; void main () { ptr_8255_ctl = p8255_ctl; *ptr_8255_ctl = ctl_word; ptr_8255_porta = porta; ptr_8255_portb = portb; ptr_8255_portc = portc; *ptr_8255_porta = 0x0f; //porta lower bits for green and amber delay_ms(); //leds,higher bits for enabling 4 flipflops *ptr_8255_porta = 0xf0; // mem. locn to hold adc data to display freq=0xf0; //default request is from ground floor

*ptr_8255_portb = 0x0;

while(1) {

// floor status 1st floor

if(freq==0xf0) // when elevator is at ground floor or default { *ptr_8255_porta=0xf0; req = *ptr_8255_portb; //read the request from portb temp = req; req = req & 0x0f;

Page 18: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 18

if(req == 0x0e) //request is from same floor {

floor1(); }

if(req == 0x0d) //request from second floor {

preq = 0xf0; // update the preq and freq freq = 0xf3; //freq holds the future request, moveup(); //preq holds present stage floor2(); } if(req ==0x0b) //request from third floor when it is in flr1 { preq = 0xf0; freq = 0xf6; moveup(); //blink leds from floor 1 to 3 floor3(); //red led is off and green led is on } if(req ==0x07) //request from fourth floor { preq = 0xf0; freq = 0xf9; moveup(); //blink leds from floor 1 to 4 floor4(); //red led is off and green led is on } } //end of for loop

// floor status 2nd floor if(freq==0xf3)

{ req = *ptr_8255_portb; temp = req; req = req & 0x0f; if(req ==0x0e) //request from first floor when it is flr2 { preq = 0xf3; freq = 0xf0; movedown(); //blink leds from floor 2 to 1 floor1(); //red led is off and green led is on } if(req == 0x0d) //request from same floor { floor2(); //red led is off and green led is on } if(req ==0x0b) //request from third floor when it is flr2 { preq = 0xf3; freq = 0xf6;

Page 19: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 19

moveup(); //blink leds from floor 2 to 3 floor3(); //red led is off and green led is on } if(req ==0x07) //request from fourth floor { preq = 0xf3; freq = 0xf9; moveup(); //blink leds from floor 2 to 4 floor4(); //red led is off and green led is on } } //end of for loop

// floor status 3rd floor if(freq==0xf6)

{ req=*ptr_8255_portb; temp =req; req = req & 0x0f; if(req ==0x0e) //request from first floor when it is flr3 { preq = 0xf6; freq = 0xf0; movedown(); //blink leds from floor 3 to 1 floor1(); //red led is off and green led is on } if(req ==0x0d) //request from second floor { preq = 0xf6; freq = 0xf3; movedown(); //blink leds from floor 3 to 2 floor2(); //red led is off and green led is on }

if(req == 0x0b) //request from same floor {

floor3(); //red led is off and green led is on }

if(req ==0x07) //request from fourth floor {

preq = 0xf6; freq = 0xf9; moveup(); //blink leds from floor 3 to 4 floor4(); //red led is off and green led is on } } //end of for loop

// floor status 4th floor

if(freq==0xf9)

Page 20: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 20

{ req = *ptr_8255_portb; temp = req; req = req & 0x0f; if(req ==0x0e) //request from first floor when it is flr4 { preq = 0xf9; freq = 0xf0; movedown(); //blink leds from floor 4 to 1 floor1(); //red led is off and green led is on } if(req ==0x0d) //request from second floor { preq = 0xf9; freq = 0xf3; movedown(); //blink leds from floor 4 to 2 floor2(); //red led is off and green led is on } if(req ==0x0b) //request from third floor when it is flr4 { preq = 0xf9; freq = 0xf6; movedown(); //blink leds from floor 4 to 3 floor3(); //red led is off and green led is on }

if(req == 0x07) //request from same floor {

floor4(); //red led is off and green led is on } } //end of for loop }// end of while(1) } //end of main() void floor1(void) {

*ptr_8255_porta=0xe0; //to make red led off and corresponding green on delay_ms(); } void floor2(void) { *ptr_8255_porta=0xd3; delay_ms(); }

Page 21: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 21

void floor3(void) { *ptr_8255_porta=0xb6; delay_ms(); } void floor4(void) { *ptr_8255_porta=0x79; delay_ms(); } void moveup(void) { // initialise loop to on leds

// unsigned char i; for(i=preq;i<freq;i++) { delay_ms(); *ptr_8255_porta = i; //leds blink from lower to upper value delay_ms(); } } // end of move up void movedown(void) { /* initialise loop to on leds */

// unsigned char j; for(j =preq;j>freq;j--) { delay_ms(); *ptr_8255_porta = j; //leds blink from upper to lower value delay_ms(); } } /* end of move down */ void delay_ms(void) { int i=0;

for(i=0;i<=10000;i++){} }

Page 22: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 22

C program to display the temperature on LCD screen #include <Intel\8051.h> #include <standard.h> #define PORTA 0x2040 #define PORTB 0x2041 #define PORTC 0x2042 #define CNTL 0x2043 #define buff 0x196 xdata unsigned char *p8255_cntl ; xdata unsigned char *p8255_porta ; xdata unsigned char *p8255_portb ; xdata unsigned char *p8255_portc ; xdata unsigned char *buff_ptr; idata unsigned char temp1,adc_val; void main () { buff_ptr=buff; // mem. locn to hold adc data to display p8255_porta = PORTA; p8255_portc = PORTC; p8255_portb = PORTB; p8255_cntl = CNTL;

*p8255_cntl = 0x98;// Ppa=i/p,Pb=o/p,PCu=i/p,PCl=o/p, *p8255_cntl = 0x03;// channel 1 selection Wr=1,PC1=1 *p8255_cntl = 0x00;// start=0, PC0=0

delay(200); while(1) { p8255_porta = PORTA; p8255_portc = PORTC; p8255_portb = PORTB; p8255_cntl = CNTL; *p8255_cntl = 0x01;// start=1,PC0=1 delay(200); *p8255_cntl = 0x00;// start=0, PC0=0// check for eoc,PC7=1 do { temp1=*p8255_portc; temp1=temp1 & 0x80; } while(temp1 != 0x80);

Page 23: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 23

//delay(200);// after eoc, read the adc data from PA adc_val = *p8255_porta;// display adc result on the data field *buff_ptr = adc_val; // This assembly program displays the adc_val on LCD screen ACC=*buff_ptr; asm a,#00h asm da a asm mov r6,a asm lcall 677dh asm mov r0,0ffh asm mov r1,0ffh asm lcall 6850h asm mov r0,0ffh asm mov r1,0ffh asm lcall 6850h delay(200); } // end of while(1) }

Page 24: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 24

Understanding 8051

Programming

Page 25: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 25

Unit 1: Data Transfer Operation a. ALP : Data transfer using immediate addressing method Address Label Mnemonic Comment

9000 MOV A,#10 A=10h MOV F0,#20 F0=20h or B=20h MOV R0,#FF R0=FF MOV R1,#41 R1=41 LCALL 0003 Halt instruction

b. C Program : Data transfer using immediate addressing method #include <Intel\8051.h> typedef unsigned char BYTE; void main() { BYTE a,b,c,d;

a=0x10; b=0x20; c=0xFF; d=0x41; ACC=a; B=b; R0=c; R1=d;

}

Before Execution After Execution A=xx B=xx R0=xx R1=xx

A=10 B=20 R0=FF R1=41

b. Data transfer using direct addressing method Address Label Mnemonic Comment

9000 MOV A,10 A=&10 MOV F0,20 F0=&20 or B=&20 MOV R0,FF R0=&FF MOV R1,41 R1=&41 LCALL 0003 Halt instruction

Page 26: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 26

#include < Intel\8051.h> typedef unsigned char BYTE; void main() {

BYTE *p1,*p2,*p3,*p4; BYTE a,b,c,d; a=0x10; b=0x20; c=0xFF; d=0x41; *p1=a; *p2=b; *p3=c; *p4=d; ACC=*p1; B=*p2; R0=*p3; R1=*p4;

}

Before Execution After Execution A=xx B=xx R0=xx R1=xx

A=10 B=20 R0=FF R1=41

b. Data transfer using indirect addressing method Address Label Mnemonic Comment

9000 MOV R0,#10 R0=10 MOV A,@R0 A=&R0(=&10) MOV R0,#20 MOV F0,@R0 F0=&R0(=&20) LCALL 0003 Halt instruction

Page 27: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 27

#include < Intel\8051.h> typedef unsigned char BYTE; void main() {

BYTE *p1,*q1, *p2,*q2; BYTE a,b; a=0x10; b=0x20; *q1=a; *p1=*q1; *q2=b; *p2=*q2; ACC=*p1; B=*p2; R0=*p3; R1=*p4;

}

Before Execution After Execution A=xx B=xx R0=xx

&10=20 &20=40

A=20 B=40 R0=20

Page 28: 8051 Venkat

Microcontroller 8051 Lab Manual VENKATASWAMY R

www.venkataswamy.page.tl EEE, SJCE, MYSORE 28

Pre requisites

For Assembly level programming • Number systems (Hexadecimal, decimal, binary, octal). • Internal block diagram of 8051 and internal components. • Pin diagram, definition of each pin. • Serial and parallel ports. • Memory structure and allocation. • Basic kit familiarization, connections and supply. • Boolean algebra. • Instruction set.

For C programming • Programming languages (HLL, ALL, LLL). • Compiler, interpreter, assembler. • Algorithms, flow chart. • Basic block of C program • Pre processor directive like Header files inclusion, definition etc. • Primitive, derived, user defined datatypes. • Control and Looping statements (if, while, do while, for, goto etc). • Functions. • Pointers. • New added features in the compiler. For Interfacing • Serial and parallel port connection. • Direct interfacing and interfacing external device trough intermediate

device like 8255. • Block diagram of 8255 and its connection with 8051. • Configuration of 8255 (control word of 8255). • Stepper motor, LCD, key boards, ADC, DAC, Sensors, Latches and DC

motor etc.

Thank you…VENKAT