Let's talk about REGISTER. REGISTER A type of MEMORY CELL. It can read or write information. Different REGISTERs can be accessed with their name or address. In the picture below, the names and addresses of different REGISTERs are given. The addresses are given in Hexadecimal number. I will describe some important REGISTERs later.



Click here to see the previous part



All the registers of PIC 16f84 micro-controller are divided into Bank0, Bank1. The registers located in Bank1 are involved in the operation control of the device. And bank0 registers are involved in various data changes. For example, if we want to give high output to RA0 pin of PORTA, then first we have to select PORTA as output, then send to logical 1, RA0 pin. Now to fix the RA0 pin of PORTA as output, you have to make the 0 bit of TRISA Register 0. Because PORTA's control register is TRISA Register. Notice the location of TRISA Register in Bank1 and PORTA in Bank0.


Status register: This register's job is to display arithmetic status and change the bank. For example, to go from Bank0 to Bank1, you have to set the 5 number bit (RP0) of the Status Register. Similarly, to go from Bank1 to Bank0, you have to clear the 5 number bit (RP0) of the Status Register. Here set means logical 1 and clear means logical 0. Address of STATUS REGISTER is 03h. Here h means hexadecimal number system.





TRISA and TRISB REGISTER: TRISA REGISTER, PORTA's INPUT / OUTPUT CONTROL REGISTER and TRISB, PORTB's. The SIZE of any PORT and its corresponding TRIS register will be the same size, that is, if the size of the PORTA is 5bit, then the TRISA register must be 5bit. PORTA's RA0, RA1, RA2, RA3, RA4, will control the pins of the 0,1,2,3,4 bit of TRISA respectively. If you want to select any PIN of any PORT as input, you have to set the relevant bit of TRIS register associated with it i.e. 1. Similarly, if you want to select any PIN of any PORT as output, you have to clear the relevant bit of TRIS register associated with it, i.e. 0. Let's give an example, what do we do if we want to fix RB0 and RB1 pins of PORTB as input and the rest of the pins as output !! Since PORTB's RB7, RB6, RB5, RB4, RB3, RB2, RB1, RB0 pins will control the 7,6,5,4,3,2,1,0 bit of TRISB respectively so we have 1 in 0 and 1 in bit. And I will send 0 to the rest of the bits. If TRISB = 00000011 then our desired input output selection will be complete. Simply remember that in case of TRIS REGISTER 1 gives INPUT and 0 gives OUTPUT.

Enter below TRISA = 00101 to see which INPUT of PORTA will be OUTPUT.

BIT Number 4 3 2 1 0

PORTA Pin RA4 RA3 RA2 RA1 RA0

TRISA value 0 0 1 0 1

Pin status Output Output Input Output Input

W register: W register is called working register, you can write or read any data directly in this register. If you want to write or read in another register, you have to use W, because data cannot be written directly in another register, if you want to write, you can first fill in w register and move to the desired register.

As a first program, we will turn on and off five LEDs in the PORTA of the micro controller. For this, first we will select bank1 by setting the RP0 bit of the status register. I have already said that set means 1 and clear means 0. bank1 must be selected because the location of the TRISA register is in bank1. Then all the bits of TRISA register have to be 0 to select all the pins of PORTA as OUTPUT. Then we come back to bank0. If you do this, the PORTA pins will be selected as output.

Let's write the necessary code for now.

BSF STATUS, RP0

Here BSF means Bit Set F i.e. assembler has been asked to set RP0 bit of STATUS register. Now we are at bank1. Now I will send 0 inside TRISA Register. But since the data can not be written directly to the register other than the W register, so we will fill in the W register and forward the W register inside the TRISA Register.



MOVLW b'00000 '

MOVWF TRISA

MOVLW means Move Literal Value into W. Next line MOVWF means “Move the content of W into the register that follows”. Now it's time to go back to bank0.

BCF STATUS, RP0

Here BCF means Bit Clear F which means with this command we can clear any bit or 0. Now if we write all the lines together,

BSF STATUS, RP0

MOVLW b'00000 '

MOVWF TRISA

BCF STATUS, RP0

Now let's send some data to PORTA. The first time all 1, the next time all 0, the led will burn once and extinguish once. Here you have to take the help of W register.

MOVLW b'11111 '

MOVWF PORTA

MOVLW b'00000 '

MOVWF PORTA

In the program we have written above, the leds will light up once and then go out and will not burn. If you want to burn repeatedly, you have to run the upper part inside a loop. When the microcontroller executes the LED extinguishing line, it is sent back to the LED lighting line. We will do this using the GOTO command. Before that, let's give a name to the line I will send back. I named this line START here. Always keep in mind that it is recommended to have a gap of 1 TAB between START i.e. lebel and normal commands like MOVLW, BSF, BCF etc. Otherwise error may occur.

START MOVLW b'11111 '

                                MOVWF PORTA

                                MOVLW b'00000 '

                                MOVWF PORTA

                                GOTO START

Now I write the whole thing at once.

                             BSF STATUS, RP0; Select Bank1

                             MOVLW b’00000 ’; put 00000 into W register

                             MOVWF TRISA; Move 00000 into TRISA

                             BCF STATUS, RP0; Select Bank0

START MOVLW b’11111 ’; put 11111 into W register

                             MOVWF PORTA; move 11111 into PORTA register

                             MOVLW b’00000 ’; put 00000 into W register

                             MOVWF PORTA; move 00000 into PORTA

                             GOTO START; Go back to START line

Notice that I wrote the comment with a semicolon next to each line of the above program. Because if you don't write a comment, after two days you will forget why you wrote a line. Write as many comments as you like with semicolons. We will talk about PIC simulator.

I