You are on page 1of 28

Microcontroller 8051 Lab Manual

VENKATASWAMY R

MICROCONTROLLER 8051

LABMANUAL

R VENKATASWAMY E & E E, SJCE MYSORE venkataswamy.r@gmail.com

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

Microcontroller 8051 Lab Manual Contents


I. PROGRAMMING

VENKATASWAMY R

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 onChip 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.

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

Microcontroller 8051 Lab Manual

VENKATASWAMY R

Assembly Programming

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

Microcontroller 8051 Lab Manual

VENKATASWAMY R

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 9000 Label Mnemonic MOV R1,#10H MOV R2,#20H MOV R0,#30H CLR C MOV A,R2 SUBB A,R1 MOV R2,A MOV A,@R1 MOV @R0,A INC R1 INC R0 DJNZ R2,LOOP LCALL 0003 Comment Starting addr of src Ending addr of src Starting addr of desti Determination of size And stored in R2 Copy data byte

LOOP

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 9000 Label Mnemonic MOV R1,#10H MOV R2,#20H MOV R0,#15H CLR C MOV A,R2 SUBB A,R1 MOV R2,A MOV A,R1 ADD A,R2 MOV R1,A MOV A,R0 ADD A,R2 MOV R0,A INC R2 MOV A,@R1 MOV @R0,A DEC R1 DEC R0 DJNZ R2,LOOP LCALL 0003 Comment Starting addr of src Ending addr of src Starting addr of desti Determination of size And stored in R2

End addr of src

End addr of desti

LOOP

Copy data byte

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

Microcontroller 8051 Lab Manual

VENKATASWAMY R

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 8500 Label Mnemonic MOV R0,#10H MOV 82H,#00H MOV 83H,#80H MOVX A,@DPTR MOV 83H,#90H MOV @DPTR,A INC DPTR DJNZ R0,LOOP LCALL 0003H Comment Size of an array DPL=00 DPH=80 Src data to acc DPH=90 Acc to desti

LOOP

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 8500 Label Mnemonic MOV R0,#10H MOV 82H,#00H MOV 83H,#80H MOVX A,@DPTR MOV R1,A MOV 83H,#90H MOV A,@DPTR XCH A,R1 MOVX @DPTR,A MOV 83H,#80H MOV A,R1 MOVX @DPTR,A INC DPTR DJNZ R0,LOOP LCALL 0003H Comment Size of an array DPL=00h DPH=80h Src data to acc DPH=90h

LOOP

DPH=80h

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

Microcontroller 8051 Lab Manual

VENKATASWAMY R

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

6. Write an ALP to add n bytes stored in external RAM (Starting address 9000 and no of bytes is 10 or 0Ah) Address 8000 Label Mnemonic MOV R0,#0A MOV R1,#00 MOV DPTR,#9000 MOVX A,@DPTR ADD A,R1 MOV R1,A INC DPTR DJNZ R0,LOOP LCALL 0003 Comment No of bytes R1=SUM=0 DPTR=9000 Sum=sum+n[i]

LOOP

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

Microcontroller 8051 Lab Manual

VENKATASWAMY R

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

LOOP

SKIP

A=largest no

8. Write an ALP to search a byte in an array of bytes stored in external RAM. Address 8000 Label Mnemonic MOV R0,#0A MOV R1,#10 MOV R2,#00 MOV DPTR,#9000 MOVX A,@DPTR CLR C SUBB A,R1 INC DPTR JNZ SKIP INC R2 DJNZ R0,LOOP LCALL 0003 Comment Array size Search value Count

compare

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

Microcontroller 8051 Lab Manual

VENKATASWAMY R

9. Write an ALP to illustrate addition, subtraction, multiplication and division of two 8 bit numbers. Address 8000 Label Mnemonic MOV R1,#20H MOV R2,#10H MOV A,R1 ADD A,R2 MOV R0,A CLR C MOV A,R1 SUBB A,R2 MOV R3,A MOV A,R1 MOV F0,R2 MUL AB MOV R4,A MOV A,R1 MOV B,R2 DIV AB MOV R5,A LCALL 0003H Comment First no Second no ADDITION R0=R1+R2 SUBTRACTION R3=R1-R2

MULTIPLICATION R4=R1xR2

Division R5=R1/R2

10. Write an ALP to illustrate logical operations like AND, OR, NOT and XOR Address 8000 Label Mnemonic MOV R1,#20H MOV R2,#10H MOV A,R1 ANL A,R2 MOV R0,A MOV A,R1 ORL A,R2 MOV R3,A MOV A,R1 CPL A MOV R4,A MOV A,R1 XRL A,R2 MOV R5,A LCALL 0003H Comment First BYTE Second BYTE ANDING R0=R1 AND R2 ORING R3=R1 OR R2 NEGATION R4=~R1 XORING R5=R1 XOR R2

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

Microcontroller 8051 Lab Manual 11. Write an ALP to add two 2 byte numbers. Address 8000 Label Mnemonic MOV R1,#12 MOV R2,#34 MOV R3,#56 MOV R4,#78 MOV R7,#00 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 LCALL 0003

VENKATASWAMY R

Comment 3412 7856 ------0AC68 3rd byte=0

3rd byte=1

SKIP

12. Write an ALP to subtract 2 byte number from another 2 byte number. Address 8000 Label Mnemonic MOV R1,#56 MOV R2,#78 MOV R3,#12 MOV R4,#34 CLR C MOV A,R1 SUBB A,R3 MOV R5,A MOV A,R2 SUBB A,R4 MOV R6,A LCALL 0003 Comment 7856 3412 ------4444

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

Microcontroller 8051 Lab Manual

VENKATASWAMY R

13. Write an ALP to illustrate hexadecimal up counter with a given staring and ending value. Address 8000 Label MAIN LOOP Mnemonic MOV A,#00 MOV F0,#FF MOV R6,A MOV R3,A LCALL 677D MOV R0,#FF MOV R1,#FF LCALL 6850 MOV R0,#FF MOV R1,#FF MOV A,R3 INC A CJNE A,F0,LOOP LJMP MAIN Comment Starting value Ending value

Display R6 data

Delay

Next value

14. Write an ALP to illustrate hexadecimal down counter with a given staring and ending value. Address 8000 Label MAIN LOOP Mnemonic MOV A,#FF MOV F0,#00 MOV R6,A MOV R3,A LCALL 677D MOV R0,#FF MOV R1,#FF LCALL 6850 MOV R0,#FF MOV R1,#FF MOV A,R3 DEC A CJNE A,F0,LOOP LJMP MAIN Comment Starting value Ending value

Display R6 data

Delay

Next value

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

10

Microcontroller 8051 Lab Manual

VENKATASWAMY R

15. Write an ALP to illustrate decimal up counter with a given staring and ending value. Address 8000 Label MAIN LOOP Mnemonic MOV A,#00 MOV F0,#99 ADD A,#00 DA A MOV R6,A MOV R3,A LCALL 677D MOV R0,#FF MOV R1,#FF LCALL 6850 MOV R0,#FF MOV R1,#FF MOV A,R3 INC A CJNE A,F0,LOOP LJMP MAIN Comment Starting value Ending value

Display R6 data

Delay

Next value

16. Write an ALP to illustrate decimal down counter with a given staring and ending value. Address 8000 Label MAIN LOOP Mnemonic MOV A,#99 MOV F0,#00 ADD A,#00 DA A MOV R6,A MOV R3,A LCALL 677D MOV R0,#FF MOV R1,#FF LCALL 6850 MOV R0,#FF MOV R1,#FF MOV A,R3 DEC A CJNE A,F0,LOOP LJMP MAIN Comment Starting value Ending value

Display R6 data

Delay

Next value

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

11

Microcontroller 8051 Lab Manual

VENKATASWAMY R

17. Write an ALP to demonstrate call and return instruction using a program to find factorial of a number. Address 8000 Label Mnemonic MOV R0,#05 MOV A,R0 LCALL 9000 LCALL 0003 CJNE R0,#01,9005 RET DEC R0 MOV F0,R0 MUL AB LJMP 9000 Comment Input number LCALL FACT

9000 9005

FACT LOOP

CJNE R0,#01,LOOP

LJMP FACT

18. Write an ALP to convert decimal number to its equivalent hexadecimal number. Address 8000 Label Mnemonic MOV R0,#16 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 LCALL 0003 Comment R0=Input byte

R1=Output byte

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

12

Microcontroller 8051 Lab Manual

VENKATASWAMY R

19. Write an ALP to convert hexadecimal number to its equivalent decimal number. Address 8000 Label Mnemonic MOV R0,#FF MOV A,R0 MOV F0,#64 DIV AB MOV R1,A MOV A,B MOV F0,#0A DIV AB MOV R2,A MOV A,B MOV R3,F0 MOV A,R2 SWAP A ADD A,R3 MOV R2,A LCALL 0003 Comment Input no B=64h First dgt B=0Ah Second dgt Third dgt Pack R2 & R3 to R2

20. Write an ALP to convert decimal number to its equivalent ASCII code. Address 8000 Label Mnemonic MOV R1,#0B MOV A,R1 LCALL 9000 LCALL 0003 CLR C SUBB A,#0A MOV A,R1 JC 9009 ADD A,#37 RET ADD A,#30 RET Comment Input char LCALL CONV

9000 9001 9003 9004 9006 9008 9009 900B

CONV

JC DGT ASCII(CHAR) ASCII(NUMBER)

DGT

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

13

Microcontroller 8051 Lab Manual

VENKATASWAMY R

21. Write an ALP to convert ASCII code to its equivalent decimal number. Address 8000 Label Mnemonic MOV R1,#39 MOV A,R1 LCALL 9000 LCALL 0003 CLR C SUBB A,#41 MOV A,R1 JC DGT CLR C SUBB A,#37 RET CLR C SUBB A,#30 RET Comment Input char LCALL CONV

9000

CONV

ASCII CHAR

DGT

ASCII NUMBER

22. Write an ALP to convert BCD to its equivalent ASCII code. Address 8000 Label Mnemonic MOV R0,#23 LCALL 9000 LCALL 0003 MOV A,R0 ANL A,#0F ADD A,#30 MOV R1,A MOV A,R0 ANL A,#F0 SWAP A ADD A,#30 MOV R2,A RET Comment Input char LCALL CONV

9000

CONV

ASCII(FIRST DGT)

ASCII(SECOND DGT)

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

14

Microcontroller 8051 Lab Manual

VENKATASWAMY R

Interfacing & C Programming

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

15

Microcontroller 8051 Lab Manual

VENKATASWAMY R

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 #define phaseb #define phasec #define phased 0x0d 0x0e 0x07 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++){} }

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

16

Microcontroller 8051 Lab Manual

VENKATASWAMY R

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 void floor1(void); void floor2(void); void floor3(void); void floor4(void); void moveup(void); void movedown(void); void delay_ms(void);

// Port A-Output

Port B-Input

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; *ptr_8255_portb = 0x0; //default request is from ground floor

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;

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

17

Microcontroller 8051 Lab Manual

VENKATASWAMY R

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;

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

18

Microcontroller 8051 Lab Manual moveup(); floor3();

VENKATASWAMY R //blink leds from floor 2 to 3 //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)

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

19

Microcontroller 8051 Lab Manual {

VENKATASWAMY R

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; delay_ms(); } void floor2(void) { *ptr_8255_porta=0xd3; delay_ms(); }

//to make red led off and corresponding green on

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

20

Microcontroller 8051 Lab Manual 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; delay_ms(); } } // end of move up

VENKATASWAMY R

//leds blink from lower to upper value

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++){} }

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

21

Microcontroller 8051 Lab Manual

VENKATASWAMY R

C program to display the temperature on LCD screen #include <Intel\8051.h> #include <standard.h> #define #define #define #define #define PORTA PORTB PORTC CNTL buff 0x2040 0x2041 0x2042 0x2043 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 = *p8255_cntl = *p8255_cntl = 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); 0x98;// Ppa=i/p,Pb=o/p,PCu=i/p,PCl=o/p, 0x03;// channel 1 selection Wr=1,PC1=1 0x00;// start=0, PC0=0

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

22

Microcontroller 8051 Lab Manual

VENKATASWAMY R

//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)

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

23

Microcontroller 8051 Lab Manual

VENKATASWAMY R

Understanding 8051 Programming

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

24

Microcontroller 8051 Lab Manual Unit 1: Data Transfer Operation

VENKATASWAMY R

a. ALP : Data transfer using immediate addressing method Address 9000 Label Mnemonic MOV A,#10 MOV F0,#20 MOV R0,#FF MOV R1,#41 LCALL 0003 Comment A=10h F0=20h or B=20h R0=FF R1=41 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 A=xx B=xx R0=xx R1=xx After Execution A=10 B=20 R0=FF R1=41

b. Data transfer using direct addressing method Address 9000 Label Mnemonic MOV A,10 MOV F0,20 MOV R0,FF MOV R1,41 LCALL 0003 Comment A=&10 F0=&20 or B=&20 R0=&FF R1=&41 Halt instruction

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

25

Microcontroller 8051 Lab Manual #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 A=xx B=xx R0=xx R1=xx

VENKATASWAMY R

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

b. Data transfer using indirect addressing method Address 9000 Label Mnemonic MOV R0,#10 MOV A,@R0 MOV R0,#20 MOV F0,@R0 LCALL 0003 Comment R0=10 A=&R0(=&10) F0=&R0(=&20) Halt instruction

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

26

Microcontroller 8051 Lab Manual #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 A=xx B=xx R0=xx &10=20 &20=40

VENKATASWAMY R

After Execution A=20 B=40 R0=20

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

27

Microcontroller 8051 Lab Manual

VENKATASWAMY R

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 youVENKAT

www.venkataswamy.page.tl

EEE, SJCE, MYSORE

28

You might also like