Understanding PIC16F876A Microprocessor Instructions: Assembly Language Basics
This guide provides an in-depth look at the assembly language instructions for the PIC16F876A microprocessor. It covers essential operations such as moving literals to registers, arithmetic operations like addition and subtraction, logical operations, bit manipulation, jumps and calls, and working with the stack. Particularly, it emphasizes the importance of conditional branching based on flags and how to handle the Watchdog Timer (WDT). Ideal for beginners and those looking to deepen their grasp of microcontroller programming.
Understanding PIC16F876A Microprocessor Instructions: Assembly Language Basics
E N D
Presentation Transcript
Mikroprotsessorid PIC16F876A KÄSUD 2
NB!Move Literal to fpuudub MOVLW kPane konstant k registrisse WMOVLW 0x5A MOVWF fKopeeri registri W sisu registrisse fMOVWF PORTB CLRWW = 0 ; Z = 1CLRW CLRFf = 0 ; Z = 1CLRF STATUS MOVF f,dKopeeri registri f sisu registrisse f või WMOVWF 0x20,0MOVWF 0x20,1 MOVF f,fKopeeri registri f sisu registrisse fMOVWF 0x20,1 d=0: Wd=1: f NB! Mõjub Z-ile
SWAPF f,dSWAPF 0x20,W SWAPF STATUS,fSWAPF STATUS,WSWAPF STATUS,f NB! Sama misMove f to W,aga Z ei muutu d=0: Wd=1: f
Liitmine ja lahutamine LIITMINE 0xFC + 0x03 = 0xFF ; C=00xFC + 0x05 = 0x02 ; C=1 LAHUTAMINE 0x06 - 0x0A = -0x04 ; C=00x0A - 0x06 = 0x04 ; C=1 Kui tulemus on negatiivne, siis C=0Kui tulemus on positiivne, siis C=1 d=0: Wd=1: f
Loogika 0x0F 000011110x5A 01011010 AND: 00001010 Z=0 OR: 01011111 Z=0 XOR: 01010101 Z=0 0x0F 000011110xF0 11110000 AND: 00000000 Z=1 OR: 11111111 Z=0 XOR: 11111111 Z=0 d=0: Wd=1: f
Rotate 00110101 C=1 RLF: 01101011 C=0 00110101 C=1 RRF: 10011010 C=1 d=0: Wd=1: f
Bit Set, Bit Clear BCF f,bSea NULLIKS registri f bitt number bBCF 0x03,0x05 ; RP0 = 0 BSF f,bSea ÜHEKS registri f bitt number bBSF 0x03,0 ; C = 0
GOTO, CALL Aadressi vanemad 2 bitti tulevad registrist PCLATH GOTO 0x50CALL 0x50
Computed GOTO Program Counter on täiesti tavaline register!
Computed GOTO MOVLW 0x06 ADDWF 0x02,1 ; mine siit 6 käsku edasi1.käsk2.käsk3.käsk4.käsk5.käsk6.käsk d=0: Wd=1: f
STACK RETURN CALL PC PC InterruptKatkestus 1 RETFIE PC 2 3 4 5 6 7 8 CALL ja katkestuse ajal kirjutatakse Program Counter Stacki pealmiseks.RETURN ja RETFIE ajal loetakse Stackist pealmine Program Counter.NB! Stack on 13-bitine ja sinna mahub ka see osa,mis muidu on registris PCLATH.Stacki mahub ülimalt 8 CALLi ja katkestust.Edaspidi hakatakse alates esimesest üle kirjutama!
CALL, RETURN Addr0000 MOVLW 0xAA ; W=AA0001 CALL 0x040002 GOTO 0x000003 MOVLW 0x00 ; W=00004 MOVLW 0xFF ; W=FF0005 RETLW 0x55 ; W=55
Tingimuslik suunamine BTFSC f,b (BTFSS f,b)Kui registri f bitt number b on NULL (ÜKS),siis jäta järgmine käsk vahele. NOP d=0: Wd=1: f
Tingimuslik suunamine BTFSC f,b (BTFSS f,b)Kui registri f bitt number b on NULL (ÜKS),siis jäta järgmine käsk vahele. 0000 BTFSC 0x8E,0 ; Kas BOR on null?0001 GOTO 0x03 ; BOR ei olnud null0002 GOTO Kuskile ; BOR oli null0003 BTFSC 0x8E,1 ; Kas POR on null?0003 GOTO 0x05 ; Ka POR ei olnud null0004 GOTO KuskileMujale ; POR oli null0005 TeeMidagiMuud ; Kumbki ei olnud null
Tingimuslik suunamine DECFSZ f,d (INCFSZ f,d)1. Lahuta või liida registrile f üks2. Pane tulemus vastavalt d väärtusele kas registrisse f või registrisse W3. Kui tulemus oli null, siis jäta järgmine käsk vahele. 0000 CLRF 0x200001 COMF 0x20,10002 DECFSZ 0x20,10003 GOTO 0x020004 TeeMidagiMuud d=0: Wd=1: f
Start WDT CLRWDT CLRWDT aeg Reset WDT WDT work SLEEP work SLEEP NOPÄra tee midagi, viida lihtsalt aega (4 OSC takti)