PIC Microcontroller Programming in Assembly Language

This might contain material from other websites, books etc since I'm just posting a 
shortnote I made when I was learning for the first time. Just take a glance at the 
instructions and what they do for now. Many instructions will be discussed in 
following tutorials. When you reach the end of tutorial series come back and check 
this again because in the end you will be able to understand instructions that 
I don't discuss.
;
A comment till the next line starts.
bsf
Used for switching any        
bit to 1
Bit set F
F-memory location or register
Syntax - bsf 03h,5
Set bit 5 in address 03h(STATUS REGISTER) to 1.
bit 5 is used to change from bank to bank
so this will change to bank1
bcf
Used for switching any 
bit to 0
Bit Clear F
Syntax - bcf 03h,5
Set bit 5 in address 03h(STATUS REGISTER) to 0
this will change to bank0
movlw
Move Literal Value Into W
Syntax - movlw 06h
movwf
Move The Contents of W into The File Register Address 
That follows
Syntax - movwf 85h
equ
equals anything in the right side to the left side 
variable.
decfsz
Decrement the register by the number that follows 
the comma, when the register reaches  0 skip next 
instruction.
Syntax - decfsz count1,1
incf
incf register,d
same as above but increments the register we specify.
Syntax -
loop incfsz    0C
goto    loop
this will increment till 0c equals 0, 
when it becomes 0 (like 127+1) it will skip next 
instruction
goto LABLE
jumps wherever the label is.
btfsc
Syntax - btfsc PORTA,0
Bit Test register F Skip if it is Clear
checks the value of bit 0 of portA, if it’s a zero 
skip next instruction
(test a flag such as carry flag after two numbers 
are add, if the answer is 0 skip next instruction)
btfss
Syntax - btfss PORTA,0
Bit Test register F Skip if it is Set
checks the value of bit 0 of portA, if it’s a 1 
skip next instruction
Subroutines
Code -
RouteName
innerLables
….. put the program here
return ;returns to the main program
Call this subroutine anywhere in the main program 
by syntax “call RouteName”
Delay loops
Syntax -count equ 06h
LABLE decfsz count,1
goto LABLE
xorwf
Syntax -movlw 02h ; loads 02h to w register
xorwf   PORTA,d ; Exclusive OR the value on PORTA 
with the value of W
(Output will be 1 if inputs are different, and 
output will be 0 if inputs are same. Result will be 
stored in W if d=0, if d=1 it will be stored in PORTA)
andlw
Syntax - andlw number
AND the “number” with the contents of W and store 
the result to W register.
andwf
Syntax - andwf register,d
if d= 0 it will AND the contents of register we specify 
with the contents of w register and store 
it in w register.
if d=1 it will AND the contents of register we specify 
with contents of w register and store it in the 
register we specified..
or
will produce 1 if both bits are 1 or either bit of 
the bits is 1 , will produce 0 if both bits are 0
add
Syntax - addlw number
adds the “number” to the content of w register and 
stores it in w register
addwf
addlw
addwf
Syntax - addwf register,d
if d=0 it will add the contents of register we specify 
with the contents of w and store it in w register
if d=1 it will add the contents of register we specify
with the contents of and store it in the register we 
specified.
addlw
this adds the literal value we specify to the w 
register
if adding exceeds 8bits the additional bit will be 
stored in the carryflag.
subwfsublw
Syntax - subwf register,d
same as above but subtracts.
Carry bit will be set if the result is positive. 
If the result negative carry bit will be clear.
comf(compliment)
Syntax - comf register,d
register, d part is same as above logical operations, 
but inverts all bits in the register we specify.
clrf
Syntax - clrf register
this will clear all contents of the register we specify.
clrw
clears the w register
rlf
will move 1 bite to the left in a register
for example.
Syntax – rlf register
if carry bit = 0,
rlf 00000010
 result - 00000100
carry bit = 0
if carry bit = 1,
rlf     00000000
result - 00000001
carry bit = 0
rrf
will move 1 bite to the right in a register
Advertisements

One thought on “PIC Microcontroller Programming in Assembly Language

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: