Lesson 2 - explanation of the program

EXPLANATION OF THE PROGRAM

_RC_OSC EQU H’3FFF’

_WDT_OFF EQU H’3FFB’

STATUS EQU 03h

TRISA EQU 85h

PORTA EQU 05h

TRISB EQU 86h

PORTB EQU 06h

__CONFIG _WDT_OFF & _RC_OSC

Org 00h

Bsf STATUS, 5

Movlw 1Fh

Movwf TRISA

Movlw 00h

Movwf TRISB

Bcf STATUS, 5

Start

Btfsc PORTA, 0

Call F1

Btfsc PORTA, 1

Call F2

Btfsc PORTA, 2

Call F3

Btfsc PORTA, 3

Call F4

Btfsc PORTA, 4

Call F5

Btfsc PORTA, 5

Call F6

Btfsc PORTA, 6

Call F7

Btfsc PORTA, 7

Call F8

Goto Start

F1

Movlw b’11111111’

Movwf PORTB

Goto Start

F2

Movlw b’10101010’

Movwf PORTB



Goto Start


F3

Movlw b’01010101’

Movwf PORTB

Goto Start

F4

Movlw b’11001100’

Movwf PORTB


Goto Start

F5

Movlw b’00110011’

Movwf PORTB


F6

Movlw b’11110000’

Movwf PORTB

F7

Movlw b’00001111’

Movwf PORTB

F8

Movlw b’11000111’

Movwf PORTB

Goto Start

End

; Resistor, capacitor oscillator memory location address H’3FFF’

; Watch dog off memory location address

; STATUS memory location address

; TRISA memory location address

; PORTA memory location address

; TRISB memory location address

; PORTB memory location address

; configure the fuses

; memory starts at origin 00h

; go to Bank 1

; store 1Fh at W register, this mean from Ra0 to Ra4 will become input because 1Fh means 11111 in binary, if I give 1 that will move soon into TRISA I command that the port will become an input

; from W register move it into TRISA

;store 00h at W register (note the previous data stored in W register will be overwrite ) this mean from Rb0 to Rb7 will become output because 00h means 00000000 in binary, if I give 0 that will move soon into TRISB I command that the port will become an output

;From W register move the data into TRISB

;go back into Bank0

; this is only a variable

;BTSFSC means Bit Test register F, and Skip if it is Clear. Test the PORTA at Bit 0. why bit 0 because the Ra0 is at the bit 0. if the sample get a 0 signal the it escape the instruction but if it is 1 it will continue to the next instruction.

; if the input at ra0 is 1 then got to F1

; BTSFSC means Bit Test register F, and Skip if it is Clear. Test the PORTA at Bit 1. why bit 1 because the Ra1 is at the bit 1. if the sample get a 0 signal the it escape the instruction but if it is 1 it will continue to the next instruction.

; if the input at ra1 is 1 then got to F2

; BTSFSC means Bit Test register F, and Skip if it is Clear. Test the PORTA at Bit 2. why bit 2, because the Ra2 is at the bit 2. if the sample get a 0 signal the it escape the instruction but if it is 1 it will continue to the next instruction.

; if the input at ra2 is 1 then got to F3

; BTSFSC means Bit Test register F, and Skip if it is Clear. Test the PORTA at Bit 3. why bit 3, because the Ra3 is at the bit 3. if the sample get a 0 signal the it escape the instruction but if it is 1 it will continue to the next instruction.

; if the input at ra3 is 1 then got to F4

; BTSFSC means Bit Test register F, and Skip if it is Clear. Test the PORTA at Bit 4. why bit 4, because the Ra4 is at the bit 4. if the sample get a 0 signal the it escape the instruction but if it is 1 it will continue to the next instruction.

; if the input at ra4 is 1 then got to F5

; BTSFSC means Bit Test register F, and Skip if it is Clear. Test the PORTA at Bit 5. why bit 5, because the Ra5 is at the bit 5. if the sample get a 0 signal the it escape the instruction but if it is 1 it will continue to the next instruction.

; if the input at ra5 is 1 then got to F6

; BTSFSC means Bit Test register F, and Skip if it is Clear. Test the PORTA at Bit 6. why bit 6, because the Ra6 is at the bit 6. if the sample get a 0 signal the it escape the instruction but if it is 1 it will continue to the next instruction.

; if the input at ra6 is 1 then got to F7

; BTSFSC means Bit Test register F, and Skip if it is Clear. Test the PORTA at Bit 7. why bit 7, because the Ra7 is at the bit 7. if the sample get a 0 signal the it escape the instruction but if it is 1 it will continue to the next instruction.

; if the input at ra7 is 1 then got to F8

; if all input is 0 then repeat the test got to Start again

; if F1 is called then go to the next instruction.

; store this data at W register

: from W register move the data into PortB, this instruction will turn ON all the LED

:then back to Start

; if F2 is called then go to the next instruction.

; store this data at W register

: from W register move the data into PortB, this instruction only 4 LED will turn ON.

:then back to Start

; if F3 is called then go to the next instruction.

; store this data at W register

: from W register move the data into PortB, this instruction only 4 LED but it is counter part of the above instruction will turn ON.

:then back to Start

; if F4 is called then go to the next instruction.

; store this data at W register

: from W register move the data into PortB, this instruction only 4 LED will turn ON.

:then back to Start

; if F5 is called then go to the next instruction.

; store this data at W register

: from W register move the data into PortB, this instruction only 4 LED will turn ON.

:then back to Start

; end of the program

;Note: F1 to F8 is not a part of PIC program but this is only a variable

Lesson 2 - Program

PROGRAM

_RC_OSC EQU H’3FFF’

_WDT_OFF EQU H’3FFB’

STATUS EQU 03h

TRISA EQU 85h

PORTA EQU 05h

TRISB EQU 86h

PORTB EQU 06h

__CONFIG _WDT_OFF & _RC_OSC

Org 00h

Bsf STATUS, 5

Movlw 1Fh

Movwf TRISA

Movlw 00h

Movwf TRISB

Bcf STATUS, 5

Start

Btfsc PORTA, 0

Call F1

Btfsc PORTA, 1

Call F2

Btfsc PORTA, 2

Call F3

Btfsc PORTA, 3

Call F4

Btfsc PORTA, 4

Call F5

Btfsc PORTA, 5

Call F6

Btfsc PORTA, 6

Call F7

Btfsc PORTA, 7

Call F8

Goto Start

F1

Movlw b’11111111’

Movwf PORTB

Goto Start

F2

Movlw b’10101010’

Movwf PORTB

Goto Start

F3

Movlw b’01010101’

Movwf PORTB

Goto Start

F4

Movlw b’11001100’

Movwf PORTB

Goto Start

F5

Movlw b’00110011’

Movwf PORTB

F6

Movlw b’11110000’

Movwf PORTB

F7

Movlw b’00001111’

Movwf PORTB

F8

Movlw b’11000111’

Movwf PORTB

Goto Start

End

Lesson 2 - Material & Diagram

Materials

Computer

PIC16PRO-7406 PIC programmer

PIC16F84A PIC IC

LED 8pcs for indicator

330KW ¼ W Resistor 1pc.

1KW ¼ W Resistor 2pc.

10KW ¼ W Resistor 1pc.

220nF ceramic capacitor part number 224

switch 5pc

bread board

Diagram


LESSON 2

INPUT

In this lesson, I will show to you how to receive signal on each pins

OBJECTIVE

PPORTA is an input and PORTB is an out which the input will interact with PORTB

PORTB

PORTB

RA

4

3

2

1

0

RB

7

6

5

4

3

2

1

0

0

0

0

0

1

=

1

1

1

1

1

1

1

1

0

0

0

1

0

=

1

0

1

0

1

0

1

0

0

0

1

0

0

=

0

1

0

1

0

1

0

1

0

1

0

0

0

=

1

1

0

0

1

1

0

0

1

0

0

0

0

=

0

0

1

1

0

0

1

1

Home

PIC Microcontroller
by: Engr. Amador Enrique Rosario III

Personal Profile (Soon)

EXPLANATION OF THE PROGRAM

_RC_OSC EQU H’3FFF’

RC is the Resistor and Capacitor for Oscillator, which is the circuit I used in this lesson, sees the Diagram and it is located at the part of memory of H’3FFF’




_WDT_OFF EQU H’3FFB’

The Watchdog Timer is a free running On-Chip RC Oscillator which does not require any external components. This RC oscillator is separate from the RC oscillator of the OSC1/CLKIN pin. That means that the WDT will run even if the clock on the OSC1/CLKIN and OSC2/CLKOUT pins of the device has been stopped, for example, by execution of a SLEEP instruction. During normal operation, a WDT time-out generates a device RESET. If the device is in SLEEP mode, a WDT wake-up causes the device to wake-up and continue with normal operation. The WDT can be permanently disabled by programming configuration bit WDTE as a '0

STATUS EQU 03h
TRISA EQU 85h
PORTA EQU 05h
TRISB EQU 86h
PORTB EQU 06h

This are the register file map see the table 2 at page 7

__CONFIG _WDT_OFF & _RC_OSC

I configure the fuses as the watchdog is off and I used the Resistor /capacitor as the Oscillator. Take note: that there are 2 underscore ( _ ) before CONFIG

Org 00h

PIC starts here on power-up and reset, It means that I started at 00h of memory and stack or it is at the vector see the table 1 at page 6



Bsf STATUS, 5
Movlw 00h
Movwf TRISA
Movlw 00h
Movwf TRISB
Bcf STATUS, 5

BSF means Bit Set F.
The F means that we are going to use a memory location, or register.
STATUS is a register address where it is located at 03h (see the table at 2 at page 7)
And 5 means I use this bit for direct addressing

bit 5 RP0: Register Bank Select bits (used for direct addressing)
01 = Bank 1 (80h - FFh)
00 = Bank 0 (00h - 7Fh)

Movlw b’01010’

Store the 010101 in binary data into W resgister

Movwf PORTA

From W register move the data into PORTA

Movlw b’01010101’

Store the 01010101 in binary data into W register. (Note the first value stored in W register it will be overwrite )

Movwf PORTB

From W register move the data into PORTA

Start
Goto Start

End

PROCEDURE

1. go to the programming procedure
2. after your program is successful then build the circuit diagram

PROGRAM

_RC_OSC EQU H’3FFF’
_WDT_OFF EQU H’3FFB’

STATUS EQU 03h
TRISA EQU 85h
PORTA EQU 05h
TRISB EQU 86h
PORTB EQU 06h

__CONFIG _WDT_OFF & _RC_OSC

Org 00h

Bsf STATUS, 5
Movlw 00h
Movwf TRISA
Movlw 00h
Movwf TRISB
Bcf STATUS, 5

Movlw b’01010’
Movwf PORTA
Movlw b’01010101’
Movwf PORTB
Start
Goto Start

End

lession 1 - Material and Diagram

MATERIALS

Computer
PIC16PRO-7406 PIC programmer
PIC16F84A PIC IC
LED 13pcs for indicator
330KW ¼ W Resistor 1pc.
1KW ¼ W Resistor 2pc.
220nF ceramic capacitor part number 224
Breadboard

DIAGRAM

LESSON I

OUTPUT

In this lesson, I will show to you how to give signal on each pins and showing the very basic steps in programming PIC16F84A

OBJECTIVES

The objective is to give 1 (one) or ON signal at IC Pin No. 18, 2, 6, 8, 10 and 12 and 0 (zero) or OFF signal to Pin No.

Pin No. 3 2 1 18 17
Ra 4 3 2 1 0
In Binary 0 1 0 1 0

Pin No. 13 12 11 10 9 8 7 6
Rb 7 6 5 4 3 2 1 0
In binary 0 1 0 1 0 1 0 1

Basic diagram of PIC

The Register

A register is a place inside the PIC that can be written to, read from or both. The figure below shows the register file map inside the PIC16F84A.
Register file map



table 1

if you notice that the table are split into two the first table is Bank0 and the second is the bank1. the Bank1 is use to control the actual operation of the PIC and bank 0 is use to manipulate the data. For example I want the Ra0 to Ra4 as an output then the code is

Bsf STATUS, RPO ; this means that I have to go to bank1 because the default setting of the PIC is at the Bank 0, I have to go to bank1 because the next instruction are only found at the Bank1 (the TRISA).
Movlw 00h
Movwf TRISA

Bcf STATUS, RPO ; this means that I have to go back into bank0 for the next instruction such as to manipulate the data

Special function file summary


Legend: x = unknown, u = unchanged. - = unimplemented, read as '0', q = value depends on condition
Note
1: The upper byte of the program counter is not directly accessible. PCLATH is a slave register for PC<12:8>. The contents
of PCLATH can be transferred to the upper byte of the program counter, but the contents of PC<12:8> are never transferred
to PCLATH.
2: The TO and PD status bits in the STATUS register are not affected by a MCLR Reset.
3: Other (non power-up) RESETS include: external RESET through MCLR and the Watchdog Timer Reset.
4: On any device RESET, these pins are configured as inputs.
5: This is the value that will be in the port output latch.

Program memory map and stack


Program memory map and stack

Other Pins

Vss and Vdd

Power supply pins, Vdd is positive supply and Vss is the ground, where the maximum voltage supply is 6V and the minimum voltage is 2V but the average voltage is 5V so therefore I am using the 7805 voltage regulator IC for the supply.

Osc1 /clk in and osc2 / clk out

This pins are the oscillator connection for external timing

MCLR

Memory clear, this pin is use to erase memory location inside the PIC16F84A

Rb0 to Rb7

Rb0 to Rb7

Is a secondary bi-directional port, which is exactly the same way as Ra0 to Ra4 except the declaration of TRISA that it must be TRISB and it has 8 pins

Example

Bsf STATUS, RPO
Movlw 55h
Movwf TRISB
Bcf STATUS, RPO

Where 55h is an hexa number that arrange into

Rb7 Rb6 Rb5 Rb4 Rb3 Rb2 Rb1 Rb0
0 1 0 1 0 1 0 1

The 55h is equal 01010101 in binary

And the direction of current in Rb0 to Rb7 will be like this



Figure. 4

Ra0 to Ra4

Ra0 to Ra4
Is a bi-directional port where it can be configure as an input or an output that depend on program declaration.

Example.
Bsf STATUS, RPO
Movlw 00h
Movwf TRISA
Bcf STATUS, RPO

Which means that I am declaring the port Ra0 to Ra4 to be an output so the direction of the current in port Ra0 to Ra4 will be like this



Figure. 2

but the question is, how I declare that the Ra0 to Ra4 will become an output; from the example I write the

Movlw 00h
Movwf TRISA

Where 00h is an hexa number that arrange into

Ra4 Ra3 Ra2 Ra1 Ra0
0 0 0 0 0

The 00h is equal 00000 in binary, so if I declare 0 (zero) binary signal to each port which means the port will become an output and if I declare 1 (one) binary signal to the port then it will become an input

Example

Bsf STATUS, RPO
Movlw 05h
Movwf TRISA
Bcf STATUS, RPO

And the direction of the current will become like this



Figure. 3

Where 05h is an hexa number that arrange into

Ra4 Ra3 Ra2 Ra1 Ra0
0 0 1 0 1

The 00h is equal 00101 in binary

Introduction

Introduction

The MICROCHIP manufacturer of PICXXXX where the cheapest microcontroller, in this blog I am going to concentrate to the PIC16F84A, and I am going to use assembly language for programming although there are several ways of programming PIC such as BASIC and C language.

The pins

Figure. 1

The above picture shows the pin configuration of PIC16F84A