Microcontroller 8051
اسلاید 1: Microcontroller 8051Assembly Language
اسلاید 2: Numerical Bases Used in ProgrammingHexadecimalBinaryBCD
اسلاید 3: Hexadecimal BasisHexadecimal Digits:1 2 3 4 5 6 7 8 9 A B C D E F A=10 B=11 C=12 D=13 E=14 F=15
اسلاید 4: Decimal, Binary, BCD, & Hexadecimal Numbers(43)10=(0100 0011)BCD=( 0010 1011 )2 =( 2 B )16
اسلاید 5: RegistersABR0R1R3R4R2R5R7R6DPHDPLPCDPTRPCSome 8051 16-bit RegisterSome 8-bitt Registers of the 8051SP
اسلاید 6: Memory mapping in 8051 ROM memory map in 8051 family0000H0FFFH0000H1FFFH8751AT89C518752AT89C524k8k
اسلاید 7: RAM memory space allocation in the 80517FH30H2FH20H1FH17H10H0FH07H08H18H00HRegister Bank 0(Stack) Register Bank 1 Register Bank 2Register Bank 3Bit-Addressable RAMScratch pad RAM
اسلاید 8: Addressing ModesRegisterDirect Register IndirectImmediateRelativeAbsoluteLongIndexed
اسلاید 9: Register Addressing ModeMOVRn, A;n=0,..,7ADDA, RnMOVDPL, R6MOVDPTR, AMOVRm, Rn
اسلاید 10: Direct Addressing ModeAlthough the entire of 128 bytes of RAM can be accessed using direct addressing mode, it is most often used to access RAM loc. 30 – 7FH.MOVR0, 40HMOV56H, AMOVA, 4; ≡ MOV A, R4MOV6, 2; copy R2 to R6; MOV R6,R2 is invalid !
اسلاید 11: Register Indirect Addressing ModeIn this mode, register is used as a pointer to the data.MOVA,@Ri; move content of RAM loc. where address is held by Ri into A ( i=0 or 1 )MOV@R1,BIn other word, the content of register R0 or R1 is sources or target in MOV, ADD and SUBB insructions.
اسلاید 12: Immediate Addressing ModeMOVA,#65HMOVR6,#65HMOVDPTR,#2343HMOVP1,#65H
اسلاید 13: Relative, Absolute, & Long Addressing Used only with jump and call instructions:SJMPACALL,AJMPLCALL,LJMP
اسلاید 14: Indexed Addressing Mode This mode is widely used in accessing data elements of look-up table entries located in the program (code) space ROM at the 8051MOVCA,@A+DPTR (A,@A+PC)A= content of address A +DPTR from ROM Note:Because the data elements are stored in the program (code ) space ROM of the 8051, it uses the instruction MOVC instead of MOV. The “C” means code.
اسلاید 15: Some Simple Instructions MOV dest,source ; dest = sourceMOV A,#72H;A=72HMOV R4,#62H;R4=62HMOV B,0F9H;B=the content of F9’th byte of RAMMOV DPTR,#7634HMOV DPL,#34HMOV DPH,#76HMOV P1,A;mov A to port 1Note 1:MOV A,#72H ≠ MOV A,72HAfter instruction “MOV A,72H ” the content of 72’th byte of RAM will replace in Accumulator. Note 2:MOV A,R3≡MOV A,3
اسلاید 16: ADDA, Source;A=A+SOURCEADDA,#6;A=A+6ADDA,R6;A=A+R6ADD A,6;A=A+[6] or A=A+R6ADDA,0F3H;A=A+[0F3H]SUBBA, Source;A=A-SOURCE-CSUBB A,#6;A=A-6SUBB A,R6;A=A+R6
اسلاید 17: MUL & DIVMULAB ;B|A = A*BMOVA,#25HMOVB,#65HMULAB;25H*65H=0E99;B=0EH, A=99HDIVAB;A = A/B, B = A mod BMOVA,#25MOVB,#10DIVAB;A=2, B=5
اسلاید 18: SETBbit; bit=1CLRbit; bit=0SETBC; CY=1SETBP0.0;bit 0 from port 0 =1SETBP3.7;bit 7 from port 3 =1SETBACC.2;bit 2 from ACCUMULATOR =1SETB05;set high D5 of RAM loc. 20hNote:CLR instruction is as same as SETBi.e.:CLRC;CY=0But following instruction is only for CLR:CLRA;A=0
اسلاید 19: DECbyte;byte=byte-1INCbyte;byte=byte+1INCR7DECADEC40H; [40]=[40]-1
اسلاید 20: RR – RL – RRC – RLC AEXAMPLE:RRARR:RRC:RL:RLC:CC
اسلاید 21: ANL - ORL – XRLBitwise Logical Operations: AND, OR, XOREXAMPLE:MOVR5,#89HANLR5,#08HCPLA;1’s complementExample:MOVA,#55H;A=01010101 BL01:CPLAMOVP1,AACALLDELAYSJMPL01
اسلاید 22: Stack in the 8051The register used to access the stack is called SP (stack pointer) register.The stack pointer in the 8051 is only 8 bits wide, which means that it can take value 00 to FFH. When 8051 powered up, the SP register contains value 07.7FH30H2FH20H1FH17H10H0FH07H08H18H00HRegister Bank 0(Stack) Register Bank 1 Register Bank 2Register Bank 3Bit-Addressable RAMScratch pad RAM
اسلاید 23: Example:MOVR6,#25HMOVR1,#12HMOVR4,#0F3HPUSH6PUSH1PUSH40BH0AH09H08HStart SP=07H250BH0AH09H08HSP=08HF312250BH0AH09H08HSP=08H12250BH0AH09H08HSP=09H
اسلاید 24: LOOP and JUMP InstructionsConditional Jumps :
اسلاید 25: DJNZ:Write a program to clear ACC, thenadd 3 to the accumulator ten timeSolution: MOVA,#0 MOVR2,#10AGAIN:ADDA,#03 DJNZR2,AGAIN ;repeat until R2=0 (10 times) MOVR5,A
اسلاید 26: LJMP(long jump)LJMP is an unconditional jump. It is a 3-byte instruction. It allows a jump to any memory location from 0000 to FFFFH.AJMP(absolute jump)In this 2-byte instruction, It allows a jump to any memory location within the 2k block of program memory. SJMP(short jump)In this 2-byte instruction. The relative address range of 00-FFH is divided into forward and backward jumps, that is , within -128 to +127 bytes of memory relative to the address of the current PC.
اسلاید 27: CALL InstructionsAnother control transfer instruction is the CALL instruction, which is used to call a subroutine.LCALL(long call)This 3-byte instruction can be used to call subroutines located anywhere within the 64K byte address space of the 8051.ACALL (absolute call)ACALL is 2-byte instruction. the target address of the subroutine must be within 2K byte range.
اسلاید 28: Example:Write a program to copy a block of 10 bytes from RAM location starting at 37h to RAM location starting at 59h.Solution:MOV R0,#37h; source pointerMOV R1,#59h; dest pointer MOV R2,#10; counterL1: MOV A,@R0MOV @R1,AINC R0INC R1DJNZ R2,L1
اسلاید 29: .100s10s1s.156+248=404Decimal Addition156 + 24816 Bit Addition1A44 + 22DB.256s16’s 1s.1 A4 4+2 2D B=3 D1 F= 3D1F
اسلاید 30: Performing the Addition with 80511.Add the low bytes R7 and R5, leave the answer in R3. 2.Add the high bytes R6 and R4, adding any carry from step 1, and leave the answer in R2. 3.Put any carry from step 2 in the final byte, R1.
اسلاید 31: Steps 1, 2, 3MOV A,R7 ;Move the low-byte into the accumulator ADD A,R5 ;Add the second low-byte to the accumulatorMOV R3,A ;Move the answer to the low-byte of the result MOV A,R6 ;Move the high-byte into the accumulator ADDC A,R4 ;Add the second high-byte to the accumulator, plus carry. MOV R2,A ;Move the answer to the high-byte of the result MOV A,#00h ;By default, the highest byte will be zero. ADDC A,#00h ;Add zero, plus carry from step 2. MOV R1,A ;Move the answer to the highest byte of the result
اسلاید 32: The Whole Program;Load the first value into R6 and R7 MOV R6,#1Ah MOV R7,#44h ;Load the first value into R4 and R5 MOV R4,#22h MOV R5,#0DBh ;Call the 16-bit addition routine LCALL ADD16_16 ADD16_16: ;Step 1 of the process MOV A,R7 ;Move the low-byte into the accumulator ADD A,R5 ;Add the second low-byte to the accumulator MOV R3,A ;Move the answer to the low-byte of the result ;Step 2 of the process MOV A,R6 ;Move the high-byte into the accumulator ADDC A,R4 ;Add the second high-byte to the accumulator, plus carry. MOV R2,A ;Move the answer to the high-byte of the result ;Step 3 of the process MOV A,#00h ;By default, the highest byte will be zero. ADDC A,#00h ;Add zero, plus carry from step 2. MOV MOV R1,A ;Move the answer to the highest byte of the result ;Return - answer now resides in R1, R2, and R3. RET
اسلاید 33: Timer & Port OperationsExample:Write a program using Timer0 to create a 10khz square wave on P1.0MOV TMOD,#02H;8-bit auto-reload modeMOV TH0,#-50;-50 reload value in TH0SETB TR0;start timer0LOOP:JNB TF0, LOOP;wait for overflowCLR TF0;clear timer0 overflow flagCPL P1.0;toggle port bitSJMP LOOP;repeatEND
اسلاید 34: InterruptsEnabling and Disabling InterruptsInterrupt PriorityWriting the ISR (Interrupt Service Routine)
اسلاید 35: Interrupt Enable (IE) Register :EA : Global enable/disable.--- : Undefined.ET2 :Enable Timer 2 interrupt.ES :Enable Serial port interrupt.ET1 :Enable Timer 1 interrupt.EX1 :Enable External 1 interrupt.ET0 : Enable Timer 0 interrupt. EX0 : Enable External 0 interrupt.
اسلاید 36: Interrupt VectorsInterruptVector AddressSystem Reset0000HExternal 00003HTimer 0000BHExternal 10013HTimer 1001BHSerial Port0023HTimer 2002BH
اسلاید 37: Writing the ISRExample:Writing the ISR for Timer0 interruptORG 0000H;resetLJMP MAINORG 000BH;Timer0 entry pointT0ISR:.;Timer0 ISR begins.RETI;return to main programMAIN:.;main program..END
اسلاید 38: Structure of Assembly language and Running an 8051 program EDITORPROGRAMASSEMBLERPROGRAMLINKERPROGRAMOHPROGRAMMyfile.asmMyfile.objOther obj fileMyfile.lstMyfile.hex
اسلاید 39: Examples of Our Program InstructionsMOV C,P1.4 JC LINE1SETB P1.0 CLR P1.2
اسلاید 40: 8051 Instruction SetACALL: Absolute Call ADD, ADDC: Add Acc. (With Carry) AJMP: Absolute Jump ANL: Bitwise AND CJNE: Compare & Jump if Not Equal CLR: Clear Register CPL: Complement Register DA: Decimal Adjust DEC: Decrement Register DIV: Divide Accumulator by B DJNZ: Dec. Reg. & Jump if Not Zero INC: Increment Register JB: Jump if Bit Set JBC: Jump if Bit Set and Clear Bit JC: Jump if Carry Set JMP: Jump to Address JNB: Jump if Bit Not Set JNC: Jump if Carry Not Set JNZ: Jump if Acc. Not Zero JZ: Jump if Accumulator Zero LCALL: Long Call LJMP: Long Jump MOV: Move Memory MOVC: Move Code Memory MOVX: Move Extended Memory MUL: Multiply Accumulator by B NOP: No Operation ORL: Bitwise OR POP: Pop Value From Stack PUSH: Push Value Onto Stack RET: Return From Subroutine RETI: Return From Interrupt RL: Rotate Accumulator Left RLC: Rotate Acc. Left Through Carry RR: Rotate Accumulator Right RRC: Rotate Acc. Right Through Carry SETB: Set Bit SJMP: Short Jump SUBB: Sub. From Acc. With Borrow SWAP: Swap Accumulator Nibbles XCH: Exchange Bytes XCHD: Exchange Digits XRL: Bitwise Exclusive OR Undefined: Undefined Instructio
نقد و بررسی ها
هیچ نظری برای این پاورپوینت نوشته نشده است.