Sie sind auf Seite 1von 3

Assembly Instructions

BSF 03h,5 Bit Set F " Set bit 5 in addres


s 03h to 1 - 03h is the STATUS register - go to Bank 1
MOVLW b'00110' Move Literal Value Into W put binary value 00110
into general purpose register W (same as MOVLW 06h)
MOVWF 85h Move The Contents Of W Into The Register Address That Fo
llows - Set TRISA to 00110
MOVF COUNT,0 Move the contents of COUNT into W
BCF 03h,5 Bit Clear F " Set bit 5 in address 03h to
0 - go to Bank 0
STATUS equ 03h equ assigns the word STATUS to the value of 03h, which i
s the address of the STATUS register (eg. - BSF STATUS,5)
(not an instruction for the PIC, but for the assembler,
always put them at the start of the program)
DECFSZ COUNT,1 Decrement the register (in this case COUNT) by the numbe
r that follows the comma, if we reach zero, jump two places forward.
goto LABEL goes to the label LABEL
ROUTINE / RETURN adds a subroutine called ROUTINE which can be called at
any point in our program.
put subroutines at the end of the program because the PI
C does not differentiate between a subroutine and the main program.
CALL Delay calls a subroutine called Delay at any poitn in our prog
ram
BTFSC 05h,0 Bit Test Register F, and Skip If It Is Clear
do a bit test on PortA bit 0, if it is 0 skip next instrucion
BTFSS 05h,0 Bit Test Register F, and Skip If It Is Set
XORWF PORTA,1 Exclusive OR W register with whatever is on our PortA. I
f bit 1 is a 1, it will change to a 0. If bit 1 is a 0, it will change to a 1.
ANDLW <number> where <number> is what we will AND the contents of W wit
h. The result of the AND function will be stored back into the W register.
ANDWF <register>,d where <register> is the register we are interested in, e
.g. PORTA, and d tells the PIC where to place the result.
If d=0, the result is placed in the W register, and of d
=1 the result is stored in the register we specified.
ADDLW <number> where <number> is what we will ADD the contents of W wit
h. The result of the ADD function will be stored back into the W register.
If the result of adding the two numbers exceeds 8 bits,
then a CARRY flag will be set. The CARRY flag is located at address 03h bit 0.
ADDWF <register>,d where <register is the register we specify and d tells t
he PIC where to place the result.
If d=0, the result is placed in the W register, and is d
=1 it placed in the register that we specified.
SUBLW <number> where <number> is what we will SUB the contents of W wit
h. The result of the SUB function will be stored back into the W register.
SUBWF <register>,d where <register is the register we specify and d tells t
he PIC where to place the result.
If d=0, the result is placed in the W register, and is d
=1 it placed in the register that we specified.
INCF <register>,d where <register> is the register, or location, t
hat we are interested in, and d tells the PIC where to place the result.
If d=0, the result is in the W register, and if d=1, the
result is placed in the register we specified.
INCFSZ 0C increment the register 0C, but if we the register equals
0 after the increment, then the PIC will skip the next instruction (1+127)
COMF <register>,d where <register is the register that we want to
invert, and d will tell the PIC where to store the result.
If d=0, the result is stored in the W register. Id d=1,
the result is stored back into the register we specified.
CLRF <register> set the entire contents of a register to 0
CLRW clears the W register
RLF move a bit in a register one place to the left, if we ha
d 00000001 and we used RLF, then we would have 00000010.
10000000 and carried out the RLF then 1 will be placed i
n the carry flag. do RLF instruction again, the 1 will reappear back at the begi
nning
RRF same as RLF but in reverse
RETLW Return, Literal to W Return is used to get ou
t of a Subroutine. RETLW usually used in tables
movlw 03
call table
:
//code goes here
:
table addwf PC // adds 3 to PC
retlw 01
retlw 02
retlw 03 // returns 03 to
W and comes out of the subroutine table
retlw 04
retlw 05
retlw 06
retlw 07
return
ORG 0000h This command means Origin, or start. PIC starts here on
power up and reset.
goto Start
ORG 0004h The PIC will come here on an interrupt. This is our inte
rrupt routine that we want the PIC to do when it receives an interrupt
RETFIE Return from Interrupt Exectuion End of the inter
rupt routine
bsf INTCON,7 GIE Global interrupt enable (1=enable)
bsf INTCON,4 INTE - RB0 interrupt enable (1=enable)
bcf INTCON,1 INTF - Clear flag bit just in case
CLRWDT reset the WDT and prescaler

Delay Example
LABEL decfsz COUNT,1
goto LABEL
Carry on here...

Das könnte Ihnen auch gefallen