0% found this document useful (0 votes)
20 views53 pages

MCU 04 Unlocked

Uploaded by

Sude Öztürk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views53 pages

MCU 04 Unlocked

Uploaded by

Sude Öztürk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

Microprocessors and Programming

Dr. Kadir Erkan

YILDIZ TEKNİK ÜNİVERSİTESİ


Recap (Week-3)

Simplified internal block diagram of


PIC 16FXXX mC;

2
Recap (Week-3)

3
Lecture Contents of Week 4

 Core and Peripheral SFR Registers


 Reseting Mechanisms
 Ports
 Assembly Code

4
Microprocessors and Programming

 Core and Peripheral SFR Registers


Core SFRs for PIC 16FXXX Microcontroller

Features and Function

The special function registers can be classified into two categories:

Core (CPU) registers - control and monitor operation and processes in the
central processor. Even though there are only a few of them, the operation of
the whole microcontroller depends on their contents.

Peripheral SFRs- control the operation of peripheral units (serial


communication module, A/D converter etc.). Each of these registers is mainly
specialized for one circuit and for that reason they will be described along with
the circuit they are in control of.
Since their bits control several different circuits within the chip, it is not possible
to classify them into some special group. These bits are described along with
the processes they control.
Core SFRs for PIC 16FXXX Microcontroller

Core (CPU) registers

Peripheral SFRs-

11/9/2024
Core SFRs for PIC 16FXXX Microcontroller

11/9/2024
Recap (Week-3) and Warm Up

Status Register

The STATUS register contains: the arithmetic status of the W register, the
RESET status and the bank select bits for data memory. One should be
careful when writing a value to this register because if you do it wrong, the
results may be different than expected.

For example, if you try to clear all bits using the CLRF STATUS instruction,
the result in the register will be 000xx1xx instead of the expected
00000000. Such errors occur because some of the bits of this register are
set or cleared according to the hardware as well as because the bits 3 and
4 are readable only. For these reasons, if it is required to change its content
(for example, to change active bank), it is recommended to use only
instructions which do not affect any Status bits (C, DC and Z). Refer to
“Instruction Set Summary”.

9
Core SFRs for PIC 16FXXX Microcontroller
Core SFRs for PIC 16FXXX Microcontroller
Core SFRs for PIC 16FXXX Microcontroller

12
Core SFRs for PIC 16FXXX Microcontroller

the weak pull-ups on PORTB.

13
Microprocessors and Programming

 Ports

14
PORTs

One of the most important feature of the microcontroller is a number of input/output


pins used for connection with peripherals. In this case, there are in total of thirty-five
general purpose I/O pins available, which is quite enough for the most applications.

In order pins’ operation can match internal 8-bit organization, all of them are, similar
to registers, grouped into five so called ports denoted by A, B, C, D and E. They all
have several features in common:

For practical reasons, many I/O pins have two or three functions. If a pin is used as
any other function, it may not be used as a general purpose input/output pin; and
Every port has its “satellite”, i.e. the corresponding TRIS register: TRISA, TRISB,
TRISC etc. which determines performance, but not the contents of the port bits.

By clearing some bit of the TRIS register (bit=0), the corresponding port pin is
configured as output. Similarly, by setting some bit of the TRIS register (bit=1), the
corresponding port pin is configured as input. This rule is easy to remember 0 =
Output, 1 = Input.
15
16
PORTs

Two Bits of a Possible Digital Output Port Two Bits of a Possible Digital Input Port

17
PORTs

18
PORTs

19
I/O Ports Sink and Source Currents
Sink and Source Currents – PIC16F877
Microprocessors and Programming

 PortA
 PortB
Microprocessors and Programming

PORT B

PORT A
23
PORT – A
PORT – B
PORT – A

26
PORT – A

27
PORT – A

A Schmitt trigger is a certain type of logic gate input which is designed to


“clean up” a corrupted logic signal.

It has two input thresholds, with the positive-going higher than the negative-going.

A signal starting from a low value has to pass the negative-going threshold (at which
point nothing happens) and then cross the positive-going threshold, at which point
the output changes state.

The output will not reverse until the input (now negative-going) has got right back
down to the negative-going threshold. Thus, small fluctuations that recross a
threshold just crossed do not cause any change in output.
PORT – A

29

Schmitt Trigger Characteristics:


(a) Buffer with Schmitt Trigger Input and
(b) Input/Output Characteristic

29
PORT – A
EXAMPLE
Port A
7 6 5 4 3 2 1 0
BSF STATUS,5 ;Select Bank3

BSF STATUS,6
OUTPUT
INPUT
CLRF ANSEL ;PortA Digital I/O

BCF STATUS,5 ;Select Bank0


BCF STATUS,6

CLRF PORTA ;Clear output Data latches

BSF STATUS, 5 ;Select Bank1

;Set RA <3:0> Input


1100 1111»» 0xCF MOVLW 0xCF ; RA <5:4> Output
MOVWF TRISA ; RA <6:7> Input

30
PORT – A
EXAMPLE
Port A
7 6 5 4 3 2 1 0
BSF STATUS,5 ;Select Bank3

BSF STATUS,6
OUTPUT
INPUT
CLRF ANSEL ;PortA Digital I/O

BCF STATUS,5 ;Select Bank0


BCF STATUS,6

CLRF PORTA ;Clear output Data latches

BSF STATUS, 5 ;Select Bank1

;Set RA <3:0> Input


1100 1111»» 0xCF MOVLW b’11001111’ ; RA <5:4> Output
MOVWF TRISA ; RA <6:7> Input

31
Microprocessors and Programming

 Assembly Code

32
Programming Tutorial: Directives

ORG:The origin directive is used to place the instruction which exactly


comes after it at the location it specifies.

END: The END should always be the last statement in your program

EQU: The equate directive is used to assign labels to numeric values. They are
used to DEFINE CONSTANTS or to ASSIGN NAMES TO MEMORY
ADDRESSES OR INDIVIDUAL BITS IN A REGISTER and then use the name
instead of the numeric address.

INCLUDE:The include directive calls a file which has all the equate statements
defined for you and ready to use,

Example: include “P16F877A.inc”

33
INSTRUCTION SET

f Register file address (0x00 to 0x7F)


W Working register (accumulator)
b Bit address within an 8-bit file register
PIC16F87X Data Sheet k Literal field, constant data or label
https://ww1.microchip.com/downloads/en/DeviceDoc/30292c.pdf d Destination select; d = 0: store result in W, d = 1: store result in file register f.
INSTRUCTION SET

f Register file address (0x00 to 0x7F)


W Working register (accumulator)
b Bit address within an 8-bit file register
k Literal field, constant data or label
d Destination select; d = 0: store result in W, d = 1: store result in file register f.

35
INSTRUCTION SET

f Register file address (0x00 to 0x7F)


W Working register (accumulator)
b Bit address within an 8-bit file register
k Literal field, constant data or label 36
d Destination select; d = 0: store result in W, d = 1: store result in file register f.
Microprocessors and Programming

Assembly Code Instructions


INSTRUCTION SET

A machine code program consists of a list of binary codes stored in the


microcontroller memory. They are decoded in sequence by the processor element,
which generates control signals that set up the microcontroller to carry out the
instruction.

Assembly language allows the program to be written using mnemonic (‘designed to


aid the memory’) code words.

Each processor has its own set of instruction codes and corresponding
mnemonics.

38
General Format for Instructions

39
Single Register Operations

The processor operates on data stored in registers, which typically contain 8 bits.
The data can originate in three ways:
1. A literal (numerical value) provided in the program;
2. An input via a port data register;
3. The result of a previous operation.

40
Register Pair Operations

41
Decision Making by Assembly Instructions

42
Decision Making by Assembly Instructions

TEST_PORTA TEST_PORTA
BTFSC PORTA,1
GOTO TEST_PORTA
BSF PORTB,0

43
Loop Programming by Assembly Instructions

BTFSS

44
Loop Programming by Assembly Instructions

45
Microprocessors and Programming

 Reseting Mechanisms

46
Reseting Mechanisms

The PIC16F87XA differentiates between various kinds of Reset:


• Power-on Reset (POR)
• MCLR Reset during normal operation
• MCLR Reset during Sleep
• WDT Reset (during normal operation) http://ww1.microchip.com/downl
oads/en/devicedoc/31003a.pdf
• WDT Wake-up (during Sleep)
• Brown-out Reset (BOR) 47
Reseting Mechanisms

Reset condition causes the microcontroller to immediately stop


operation and clear its registers. A reset signal may be generated
externally at any moment (low logic level on the MCLR pin). If needed,
it can also be generated by internal control logic.

48
Reseting Mechanisms

A logic zero (0) on the MCLR pin causes an immediate and regular reset.

49
Reseting Mechanisms

Power-on always causes reset. Since there are many transitional events
taking place when power supply is turned on (switch contact flashing and
sparkling, slow voltage rise, gradual clock frequency stabilization etc.), it is
necessary to provide a certain time delay for the microcontroller before it
starts to operate.

Two internal timers- PWRT and OST are in charge of that. The first one can
be enabled or disabled during the process of writing a program. Let’s take a
look what happens then:

50
Reseting Mechanisms

Black-out reset takes place when the power supply normally goes off. The
microcontroller then has no time to do anything unpredictable simply because the
voltage drops very fast beneath its minimum value. In other words the light goes off,
curtain falls down and the show is over!

51
Reseting Mechanisms

When the power supply voltage drops slowly (typical example is battery discharge,
although the microcontroller experiences far faster voltage drops as slow
processes), the internal electronics gradually stops to operate and the so called
Brown-out reset occurs. Here, before the microcontroller completely stops the
operation there is a real danger that circuits which operate at higher voltages start
to perform unpredictably. Brown-out reset can also cause fatal changes in the
program because it is saved in on-chip flash memory.

52
Reseting Mechanisms

A special type of Brown-out reset occurs in industrial environment when the power
supply voltage 'blinks' for a moment and drops beneath minimum level. Even short,
such noise in power line may considerably affect the operation of the device.

53

You might also like