In this section, we will study PIC micro registers. In PIC microcontrollers, every feature is ruled by writing registers. Therefore, we get results of instructions by reading special registers.

You can see BANK table below.


When we do a calculation, it affect a special register. For example, when microcontroller implements a subtraction, we can get if the result is zero by reading zero flag of the status register.

MOVLW h’A5′ ;Move A5 to accumulator(W)
SUBLW h’A5′ ;Subtract accumulator(W) from A5
BTFSC STATUS,Z ; If Z is clear skip next instruction.
— ; Do something if the result is zero

In the example, we subtract A5 from A5. The result is zero and zero flag of the option register will be set.

You can find all registers and explanations in device datasheet. We will discuss some special registers which are common in all Microchip PIC microcontrollers. All information below are from Microchip PIC16F628-datasheet But these registers are common in other micro controllers. There might be some changes device to device. So, if you use another PIC micro device have a look at its datasheet.

Special Registers

We will discuss PIC16F628A registers here. Because, it has more functionality(peripherals) which we can study detailed.


STATUS register holds arithmetic results of ADDWF, ADDLW, SUBWF, SUBLW instructions. It also contains bank select bits.

bit 7 <IRP> : indirect adressing bank select bit

1 : Switch to Bank2,Bank3
0 : Switch to Bank0,Bank1

bit 6-5 <RP><1:0> : direct addressing bank select bit

11 : Switch to Bank3
10 : Switch to Bank2
01 : Switch to Bank1
00 : Switch to Bank0

bit 4 <TO’> : Time Out bit

1 : Power-Up, CLRWDT,SLEEP
0 : A WDT(Watch Dog Timer) time out has occured

bit 3 <PD’> : Power-down bit

1 : Power-Up, CLRWDT
0 : SLEEP mode

bit 2 <Z> : Zero bit

1 : The result of operation is zero
0 : The result of operation is non-zero

bit 1 <DC> : Digit Carry/Borrow’

1 : A carry-out from the 4th low order bit of the result occurred
0 : No carry-out from the 4th lower bit of the result

bit 0 <C> : Carry/Borrow’ bit

1 : A carry-out from the MSB(Most significant bit) of the result occured
0 : No carry-out

C and DC bits are borrow’ in subtraction. When bigger number is subtracted from smaller one, an overflow will be occured. Therefore, the C or DC bit will be reset(0). Notice that polarity is reversed.

RRF(Rotate Right F) and RLF(Rotate Left F) instructions affect C(Carry/Borrow’) flag. When you RLF a register, the MSB will be put on C flag. For RRF, the LSB will be put on C flag.


W (Accumulator) Register

In PIC assembly, when moving a register’s content to another register, adding or subtracting the contents of two registers, we need a helper register which is called as accumulator (W). The accumulator can be used to hold one of the register or hold the result.

For example, if we need adding two registers, we put one of the registers to accumulator.


We cannot do this : ADDWF REG1,REG2

The ‘W’ letter after “,” means write the result to the W. If we use F instead of W, the result will be written to the register.

ADDWF REG,W here result will be written to REG register.

PORT registers (PORTA,PORTB,etc.) (BANK0)

This registers are connected to IO pins directly. That means a change on these registers will directly change the physical IO pins.

TRIS registers (TRISA,TRISB,etc.) (BANK1)

This registers contain I/O configuration of the related port. To set a bit as input we put set(1), as output we put reset(0) to the related bit of TRIS register.

For example, we want to use PORTB as four least significant as input and the others as outputs. Then we must put binary 00001111 where zeros are outputs ones are inputs.


This special register has configuration bits for PORTB, timers and WDT.

bit 7 <RBPU’> : PORTB pull-up enable

1 : PORTB pull-ups disabled
0 : PORTB pull-ups enabled

bit 6 <INTEDG> : Interrupt select bit

1 : Interrupt on rising edge of RB0/INT
0 : Interrupt on falling edge of RB0/INT

bit5 <T0CS> : TMR0 clock source select bit

1 : Transition on RA4/T0CKI
0 : Internal instruction cycle clock (CLKOUT)

bit 4 <T0SE> : TMR0 Source edge select bit

1 : Increment on rising edge of RA4/T0CKI
0 : Increment on falling edge of RA4/T0CKI

bit 3 <PSA> : Prescaler assignment bit

1 : Prescaler is assigned to the WDT
0 : Prescaler is assigned to the Timer0

bit 2-0 <PS><2:0> : Prescaler

000 1:2 1:1
001 1:4 1:2
010 1:8 1:4
011 1:16 1:8
100 1:32 1:16
101 1:64 1:32
110 1:128 1:64
111 1:256 1:128

There are pull-up resistors which need to be activated, connected to PORTB. To activate them reset(0) 7th bit of OPTION register.

There are also some interrupt and timer configuration in option register. We will discuss timers and interrupts later.


INTCON holds interrupt configuration and flag bits.

bit 7 <GIE> : Global interrupt enable bit

1 : Enable unmasked interrupts
0 : Disable interrupts

bit 6 <PEIE> : Peripheral interrupt enable bit

1 : Enable unmasked peripheral interrupts
0 : Disable all peripheral interrupts

bit 5 <T0IE> : Timer0 overflow interrupt bit

1 : Enable TMR0 interrupt
0 : Disable TMR0 interrupt

bit 4 <INTE> : RB0/INT external interrupt enable bit

1 : Enable the RB0/INT external interrupt
0 : Disable the RB0/INT external interrupt

bit 3 <RBIE> : RB Port change interrupt enable bit

1 : Enable the RB port change interrupt
0 : Disable the RB port change interrupt

bit 2 <T0IF> : TMR0 overflow interrupt flag bit

1 : TMR0 register has overflowed(must be cleared in software)
0 : TMR0 register did not overflow

bit 1 <INTF> : RB0/INT external interrupt flag bit

1 : The RB0/INT external interrupt occured (must be cleared in software)
0 : The RB0/INT external interrupt did not occured

bit 0 <RBIF> : RB port change interrupt flag bit

1 : When at least one of the RB7:RB4 pins changed state (must be cleared in software)
0 : None of the RB7:RB4 pins changed state

We have studied some common special registers. It is very important to have a look at datasheets before working with microcontrollers.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Reddit
  • Add to favorites
  • Email
  • RSS

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>