8051 micro controller

93
II ECE – SAVEETHA UNIVERSITY(SSE)

description

the working and the applications of 8051 micro controller and the instruction set are explained here

Transcript of 8051 micro controller

  • 1.II ECE SAVEETHA UNIVERSITY(SSE)

2. 22 3. 33 FEATURESFEATURES 8-bit CPU optimized for control applications 64K Program Memory address space 64K Data Memory address space 4K bytes of on-chip Program Memory 128 bytes of on-chip Data RAM 32 bidirectional and individually addressable 1/0 lines Two 16-bit timer/counters Full duplex UART 6-source/5-vector interrupt structure with two priority levels On-chip clock oscillator 4. 44SKB'sSKB's PIN DETAILSPIN DETAILS P1 P3 P0 P2 XTAL + _ RESET 5. Interrupt Control CPU 4K ROM 128 RAM OSC Bus Control 4 I/O Ports Serial Port Timer 1 Timer 0 BLOCK DIAGRAMBLOCK DIAGRAM TXD RXD P0 P1 P2 P3 6. 66SKB'sSKB's ARCHITECUREARCHITECURE All 7. 77SKB'sSKB's ARCHITECUREARCHITECURE 1 8. 88SKB'sSKB's ARCHITECUREARCHITECURE 2 9. 99SKB'sSKB's ARCHITECUREARCHITECURE 3 10. 1010SKB'sSKB's MEMORY STRUCTUREMEMORY STRUCTURE External EXT INT 128 SFR External Program Memory Data Memory 64K 64K EA = 0 EA = 1 4K 60K 11. 1111SKB'sSKB's 128 BYTE RAM128 BYTE RAM 128 BYTE INTERNAL RAM Register Banks Reg Bank 0 Reg Bank 1 Reg Bank 2 Reg Bank 3 BIT Addressable Area General Purpose Area 12. 1212SKB'sSKB's REGISTER BANK STRUCTUREREGISTER BANK STRUCTURE R0R0 R1R1 R2R2 R3R3 R4R4 R5R5 R6R6 R7R7Bank 0 R0R0 R1R1 R2R2 R3R3 R4R4 R5R5 R6R6 R7R7Bank 3 R0R0 R1R1 R2R2 R3R3 R4R4 R5R5 R6R6 R7R7Bank 2 R0R0 R1R1 R2R2 R3R3 R4R4 R5R5 R6R6 R7R7Bank 1 CYCY ACAC F0F0 RS1RS1 RS0RS0 OVOV -- PP Program Status Word -Program Status Word - PSWPSW 13. 1313SKB'sSKB's F8 FF F0 B F7 E8 EF E0 Acc E7 D8 DF D0 PSW D7 C8 CF C0 C7 B8 IP BF B0 P3 B7 A8 IE AF A0 P2 A7 98 SCON SBUF 9F 90 P1 97 88 TCON TMOD TL0 TL1 TH0 TH1 8F 80 P0 SP DPL DPH PCON 87 SFRSFR 14. 1414SKB'sSKB's 15. 1515SKB'sSKB's TIMERS SERIAL PORT INTERRUPTS 16. 1616SKB'sSKB's TIMERS SERIAL PORT INTERRUPTS 17. 1717SKB'sSKB's Timer 0 Mode 3Mode 3 Mode 2Mode 2 Mode 1Mode 1 Mode 0Mode 0 Mode 2Mode 2 Mode 1Mode 1 Mode 0Mode 0 Timer 1 TIMERS 18. 1818SKB'sSKB's M0M0M1M1C/C/GateGateM0M0M1M1C/C/GateGate TMODTMOD IT0IT0IE0IE0IT1IT1IE1IE1TR0TR0TF0TF0TR1TR1TF1TF1 TCONTCON Timer 0Timer 0Timer 1Timer 1 InterruptInterruptTimersTimers SFRs Related to TIMER 19. 1919SKB'sSKB's TIMERS SERIAL PORT INTERRUPTS 20. 2020SKB'sSKB's SERIAL PORT Mode 0 The Serial Port in Mode-0 has the following features: Serial data enters and exits through RXD TXD outputs the shifl clock 8 bits are transmitted / received The baud rate is fixed at (1/12) of the oscillator frequency 21. 2121SKB'sSKB's SERIAL PORT Mode 1 The Serial Port in Mode-1 has the following features: Serial data enters RXD Serial data exits through TXD 10 bits are transmitted / received Start bit (0) Data bits (8) Stop Bit (1) Baud rate is determined by the Timer 1 over flow rate. 22. 2222SKB'sSKB's RIRITITIRB8RB8TB8TB8RENRENSM2SM2SM1SM1SM0SM0 SCONSCON IDLIDLPDPDGF0GF0GF1GF1------SMODSMOD PCONPCON SFRs Related to SERIAL PORT 23. 2323SKB'sSKB's TIMERS SERIAL PORT INTERRUPTS 24. 2424SKB'sSKB's INTERRUPTS The Interrupt structure has the following features: 6 sources / 5 vectored interrupts Each interrupts can be individually programmable Each interrupts can have two priority levels Priority levels can be programmed All interrupts can be masked by a single bit - EA External interrupt type can be programmed Edge triggered Level Triggered 25. 2525SKB'sSKB's 1INT TIMER / COUNTER 0INT 0TF 1TF TI RI INTERRUPT SOURCES IE0 IE1 26. 2626SKB'sSKB's EX0EX0ET0ET0EX1EX1ET1ET1ESES----EAEA IEIE PX0PX0PT0PT0PX1PX1PT1PT1PSPS------ IPIP SFRs Related to INTERRUPTS IE0IE0TF0TF0IE1IE1TF1TF1RI / TIRI / TI LOW HIGH Priority Within LevelPriority Within Level IT0IT0IE0IE0IT1IT1IE1IE1TR0TR0TF0TF0TR1TR1TF1TF1 TCONTCON 27. 2727SKB'sSKB's 28. 2828SKB'sSKB's MEMORY INTERFACING External RAM Interfacing :- MCS 51 ALE EXT RAM Data Address RDWR RD WR ALE P0 P2 P1 P3 29. 2929SKB'sSKB's MEMORY INTERFACING External RAM Interfacing :- D CLK Q D CLK Q D CLK Q D CLK Q AD0 AD1 AD2 AD3 D0 D1 D2 D3 A0 A1 A2 A3 30. 3030SKB'sSKB's MEMORY INTERFACING External ROM Interfacing :- MCS 51 ALE EXT ROM Instr Address PSEN CE ALE P0 P2 P1 P3 EA EEPROM 31. 3131SKB'sSKB's 32. 3232SKB'sSKB's Instruction SetInstruction Set 5 Groups5 Groups Arithmetic Operation GroupArithmetic Operation Group Logical Operation GroupLogical Operation Group Data Transfer GroupData Transfer Group Boolean Variable Manipulation GroupBoolean Variable Manipulation Group Program Branching GroupProgram Branching Group 33. 3333SKB'sSKB's Instruction SetInstruction Set 5 Groups5 Groups Arithmetic Operation GroupArithmetic Operation Group Logical Operation GroupLogical Operation Group Data Transfer GroupData Transfer Group Boolean Variable Manipulation GroupBoolean Variable Manipulation Group Program Branching GroupProgram Branching Group 34. 3434SKB'sSKB's Arithmetic Operation GroupArithmetic Operation Group ADD A,DirectADD A,Direct ADD A,RnADD A,Rn ADD A,@RiADD A,@Ri ADD A,#DataADD A,#Data 35. 3535SKB'sSKB's Arithmetic Operation GroupArithmetic Operation Group ADDC A,DirectADDC A,Direct ADDC A,RnADDC A,Rn ADDC A,@RiADDC A,@Ri ADDC A,#DataADDC A,#Data 36. 3636SKB'sSKB's Arithmetic Operation GroupArithmetic Operation Group SUBB A,DirectSUBB A,Direct SUBB A,RnSUBB A,Rn SUBB A,@RiSUBB A,@Ri SUBB A,#DataSUBB A,#Data 37. 3737SKB'sSKB's Arithmetic Operation GroupArithmetic Operation Group INCINC AA INCINC DirectDirect INCINC RnRn INCINC @Ri@Ri 38. 3838SKB'sSKB's Arithmetic Operation GroupArithmetic Operation Group DECDEC AA DECDEC DirectDirect DECDEC RnRn DECDEC @Ri@Ri 39. 3939SKB'sSKB's Arithmetic Operation GroupArithmetic Operation Group INCINC DPTRDPTR MULMUL ABAB DIVDIV ABAB DADA AA 40. 4040SKB'sSKB's Instruction SetInstruction Set 5 Groups5 Groups Arithmetic Operation GroupArithmetic Operation Group Logical Operation GroupLogical Operation Group Data Transfer GroupData Transfer Group Boolean Variable Manipulation GroupBoolean Variable Manipulation Group Program Branching GroupProgram Branching Group 41. 4141SKB'sSKB's Logical Operation GroupLogical Operation Group ANL A,DirectANL A,Direct ANL A,RnANL A,Rn ANL A,@RiANL A,@Ri ANL A,#DataANL A,#Data ANL Direct,AANL Direct,A ANL Direct,#DataANL Direct,#Data 42. 4242SKB'sSKB's Logical Operation GroupLogical Operation Group ORL A,DirectORL A,Direct ORL A,RnORL A,Rn ORL A,@RiORL A,@Ri ORL A,#DataORL A,#Data ORL Direct,AORL Direct,A ORL Direct,#DataORL Direct,#Data 43. 4343SKB'sSKB's Logical Operation GroupLogical Operation Group XRL A,DirectXRL A,Direct XRL A,RnXRL A,Rn XRL A,@RiXRL A,@Ri XRL A,#DataXRL A,#Data XRL Direct,AXRL Direct,A XRL Direct,#DataXRL Direct,#Data 44. 4444SKB'sSKB's Logical Operation GroupLogical Operation Group CLRCLR AA CPLCPL AA RLRL AA RLCRLC AA RRRR AA RRCRRC AA SWAP ASWAP A 45. 4545SKB'sSKB's Instruction SetInstruction Set 5 Groups5 Groups Arithmetic Operation GroupArithmetic Operation Group Logical Operation GroupLogical Operation Group Data Transfer GroupData Transfer Group Boolean Variable Manipulation GroupBoolean Variable Manipulation Group Program Branching GroupProgram Branching Group 46. 4646SKB'sSKB's Data Transfer GroupData Transfer Group MOV A,DirectMOV A,Direct MOV A,RnMOV A,Rn MOV A,@RiMOV A,@Ri MOV A,#DataMOV A,#Data MOV Rn,DirectMOV Rn,Direct MOV Rn,@RiMOV Rn,@Ri MOV Rn,#DataMOV Rn,#Data 47. 4747SKB'sSKB's Data Transfer GroupData Transfer Group MOV Direct,DirectMOV Direct,Direct MOV Direct,RnMOV Direct,Rn MOV Direct,@RiMOV Direct,@Ri MOV Direct,#DataMOV Direct,#Data MOV Direct,AMOV Direct,A MOV @Ri,AMOV @Ri,A MOV @Ri,#DataMOV @Ri,#Data 48. 4848SKB'sSKB's Data Transfer GroupData Transfer Group MOV @Ri,DirectMOV @Ri,Direct MOV DPTR,#DATA16MOV DPTR,#DATA16 MOVC A,@A+DPTRMOVC A,@A+DPTR MOVC A,@A+PCMOVC A,@A+PC MOVX A,@RiMOVX A,@Ri MOVX @Ri,AMOVX @Ri,A MOVX @DPTR,AMOVX @DPTR,A 49. 4949SKB'sSKB's Data Transfer GroupData Transfer Group PUSH DirectPUSH Direct POPPOP DirectDirect XCHXCH A,RnA,Rn XCHXCH A,DirectA,Direct XCHXCH A,@RiA,@Ri XCHD A,@RiXCHD A,@Ri 50. 5050SKB'sSKB's Instruction SetInstruction Set 5 Groups5 Groups Arithmetic Operation GroupArithmetic Operation Group Logical Operation GroupLogical Operation Group Data Transfer GroupData Transfer Group Boolean Variable Manipulation GroupBoolean Variable Manipulation Group Program Branching GroupProgram Branching Group 51. 5151SKB'sSKB's Boolean Variable Manipulation GroupBoolean Variable Manipulation Group CLRCLR CC CLRCLR bitbit SETBSETB CC SETB bitSETB bit CPLCPL CC CPLCPL bitbit 52. 5252SKB'sSKB's Boolean Variable Manipulation GroupBoolean Variable Manipulation Group ANLANL C,bitC,bit ANLANL C,/bitC,/bit ORLORL C,bitC,bit ORLORL C,/bitC,/bit MOVMOV C,bitC,bit MOVMOV bit,Cbit,C 53. 5353SKB'sSKB's Boolean Variable Manipulation GroupBoolean Variable Manipulation Group JCJC relrel JNCJNC relrel JBJB bit,relbit,rel JNBJNB bit,relbit,rel JBCJBC bit,relbit,rel 54. 5454SKB'sSKB's Instruction SetInstruction Set 5 Groups5 Groups Arithmetic Operation GroupArithmetic Operation Group Logical Operation GroupLogical Operation Group Data Transfer GroupData Transfer Group Boolean Variable Manipulation GroupBoolean Variable Manipulation Group Program Branching GroupProgram Branching Group 55. 5555SKB'sSKB's Program Branching GroupProgram Branching Group ACALLACALL addr11addr11 LCALLLCALL addr16addr16 RETRET RETIRETI AJMPAJMP addr11addr11 LJMPLJMP addr16addr16 SJMPSJMP relrel 56. 5656SKB'sSKB's Program Branching GroupProgram Branching Group JMPJMP @A+DPTR@A+DPTR JZJZ relrel JNZJNZ relrel CJNECJNE A,Direct,relA,Direct,rel CJNE A,#Data,relCJNE A,#Data,rel CJNE Rn,#Data,relCJNE Rn,#Data,rel CJNE @Ri,#Data,relCJNE @Ri,#Data,rel 57. 5757SKB'sSKB's Program Branching GroupProgram Branching Group DJNZ Rn,relDJNZ Rn,rel DJNZ Direct,relDJNZ Direct,rel NOPNOP 58. 5858SKB'sSKB's UNIT - IV 59. 5959SKB'sSKB's UNIT - IV 60. 6060SKB'sSKB's 82558255 Programmable Peripheral InterfaceProgrammable Peripheral Interface 24 Programmable I/O pins Three Configurable Ports - A,B & C BSR Mode TTL Compatible 61. 6161SKB'sSKB's 82558255 Programmable Peripheral InterfaceProgrammable Peripheral Interface 62. 6262SKB'sSKB's 82558255 Programmable Peripheral InterfaceProgrammable Peripheral Interface 63. 6363SKB'sSKB's 82558255 Programmable Peripheral InterfaceProgrammable Peripheral Interface A1 A0 Select 0 0 PA 0 1 PB 1 0 PC 1 1 Control reg. 64. 6464SKB'sSKB's 82558255 Programmable Peripheral InterfaceProgrammable Peripheral Interface Group B PortC (Lower) 1 = Input 0 = Output PortB 1 = Input 0 = Output Mode Selection 0 = Mode 0 1 = Mode 1 Group A PortC (Upper) 1 = Input 0 = Output PortA 1 = Input 0 = Output Mode Selection 00 = Mode 0 01 = Mode 1 1x = Mode 2 D0D0D1D1D2D2D3D3D4D4D5D5D6D6D7D7 Control Word - General BSR Mode Select 0 = BSR Mode Enabled 1 = BSR Mode Enabled 65. 6565SKB'sSKB's 82798279 Programmable Keyboard / Display InterfaceProgrammable Keyboard / Display Interface Simultaneous Keyboard & Display Drive Scanned Keyboard Mode Scanned Sensor Mode 8-Character Keyboard FIFO Duel 8 / 16 Numerical Display R / L Entry 16 bit Display RAM Mode Programmable From CPU Programmable Scan Timing Interrupt Output on Key Entry 66. 6666SKB'sSKB's Pin Diagram :- 82798279 Programmable Keyboard / Display InterfaceProgrammable Keyboard / Display Interface 67. 6767SKB'sSKB's Signal Diagram :- 82798279 Programmable Keyboard / Display InterfaceProgrammable Keyboard / Display Interface 68. 6868SKB'sSKB's Block Diagram :- 82798279 Programmable Keyboard / Display InterfaceProgrammable Keyboard / Display Interface 69. 6969SKB'sSKB's 82518251 Programmable Communication InterfaceProgrammable Communication Interface Pin Diagram :- 70. 7070SKB'sSKB's Block Diagram :- 82518251 Programmable Communication InterfaceProgrammable Communication Interface 71. 7171SKB'sSKB's 82518251 Programmable Communication InterfaceProgrammable Communication Interface Mode Instruction Format 72. 7272SKB'sSKB's UNIT - V 73. 7373SKB'sSKB's 1) Stepper Motor Control 2) Matrix Keyboard 3) Dynamic 7 Segment Display 4) Analog to Digital converter 5) DC Motor Control 6) LCD Display 7) Serial Data Transfer 74. STEPPER MOTOR CONTROLSTEPPER MOTOR CONTROL Stepper MotorStepper Motor Winding DiagramWinding Diagram SpecificationsSpecifications Rotation / Excitation methodsRotation / Excitation methods Clockwise / Anti Clockwise SequenceClockwise / Anti Clockwise Sequence Single & Multi Winding ExcitationSingle & Multi Winding Excitation Driving unit Digital & AnalogDriving unit Digital & Analog 75. STEPPER MOTOR CONTROLSTEPPER MOTOR CONTROL W1 W2 W3 W4 1 1 0 0 0 0 1 1 1 0 0 1 0 1 1 0 0 0 1 1 1 0 0 1 1 1 0 0 0 1 1 0 76. STEPPER MOTOR CONTROLSTEPPER MOTOR CONTROL 77. MATRIX KEYBOARDMATRIX KEYBOARD General Keyboard StructureGeneral Keyboard Structure Adv & Disadv of General KeyboardAdv & Disadv of General Keyboard Layout of Matrix KeyboardLayout of Matrix Keyboard Scanning and Sense LinesScanning and Sense Lines Scan SequenceScan Sequence Key De-bounce MethodsKey De-bounce Methods 78. MATRIX KEYBOARDMATRIX KEYBOARD 1 2 3 4 5 6 7 8 9 0 # ScanLinesSenseLines MATRIXKEYBOARDDRIVER 79. MATRIX KEYBOARDMATRIX KEYBOARD 1 2 3 4 5 6 7 8 9 0 # RL0 RL1 SL0 RL2 SL1 SL2 SL3 ScanLinesSenseLines 80. MATRIX KEYBOARDMATRIX KEYBOARD 11000000 110000 RL0RL0RL1RL1RL2RL2SL0SL0SL1SL1SL2SL2SL3SL3 001100 000011 11 22 33 00110000 110000 001100 000011 44 55 66 00001100 110000 001100 000011 77 88 99 0000000101 110000 001100 000011 00 ## 1 2 3 4 5 6 7 8 9 0 # RL0 RL1 SL0 RL2 SL1 SL2 SL3 1 2 3 4 5 6 7 8 9 0 # RL0 RL1 SL0 RL2 SL1 SL2 SL3 81. MATRIX KEYBOARDMATRIX KEYBOARD 82. MATRIX KEYBOARDMATRIX KEYBOARD 83. DYNAMIC 7 SEGMENT DISPLAYDYNAMIC 7 SEGMENT DISPLAY Seven Segment DisplaySeven Segment Display Eight LEDsEight LEDs Two types Two types Common Anode & Common CathodeCommon Anode & Common Cathode Dynamic Seven Segment DisplayDynamic Seven Segment Display Scan SequenceScan Sequence 84. DYNAMIC 7 SEGMENT DISPLAYDYNAMIC 7 SEGMENT DISPLAY V Seven Segment Display a b c d e f g dp a b c d e f g dp Common 85. DYNAMIC 7 SEGMENT DISPLAYDYNAMIC 7 SEGMENT DISPLAY 86. DYNAMIC 7 SEGMENT DISPLAYDYNAMIC 7 SEGMENT DISPLAY 87. DYNAMIC 7 SEGMENT DISPLAYDYNAMIC 7 SEGMENT DISPLAY 88. LCD DISPLAYLCD DISPLAY Principle of LCDPrinciple of LCD 16x2 LCD16x2 LCD LCD Module LCD Module Driver & ScreenDriver & Screen RAMRAM Character MoldingCharacter Molding Display Type Display Type Cursor, L/R Entry etcCursor, L/R Entry etc 89. LCD DISPLAYLCD DISPLAY 90. LCD DISPLAYLCD DISPLAY 91. LCD DISPLAYLCD DISPLAY 92. 9292SKB'sSKB's Pin number Symbol Level I/O Function 1 Vss - - Power supply (GND) 2 Vcc - - Power supply (+5V) 3 Vee - - Contrast adjust 4 RS 0/1 I 0 = Instruction input, 1 = Data input 5 R/W 0/1 I 0 = Write to LCD module, 1 = Read from LCD module 6 E 1, 1->0 I Enable signal 7 DB0 0/1 I/O Data bus line 0 (LSB) 8 DB1 0/1 I/O Data bus line 1 9 DB2 0/1 I/O Data bus line 2 10 DB3 0/1 I/O Data bus line 3 11 DB4 0/1 I/O Data bus line 4 12 DB5 0/1 I/O Data bus line 5 13 DB6 0/1 I/O Data bus line 6 14 DB7 0/1 I/O Data bus line 7 (MSB) 93. LCD DISPLAYLCD DISPLAY