Professional Documents
Culture Documents
Introduction to Microcontroller:
In our project, the microcontroller is used to interface with GPS receiver and GSM
mobile phone. It collects data from the receiver and transmits to the GSM phone
CMOS technology with 4K bytes Flash memory, 192 bytes data memory and 22 I/O
timers/counters, two 8-bit, one 16-bit. It also includes two serial communication ports,
and cost-effective solution to many embedded control applications. Some of the features
• All single cycle instructions except for program branches which are two-cycle
• Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation
Peripheral Features:
• Timer1: 16-bit timer/counter with prescaler, can be incremented during SLEEP via
external crystal/clock
• Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler
ΤΜ
• Synchronous Serial Port (SSP) with SPI (Master mode) and I2CTM (Slave)
CMOS Technology:
Pin Diagram:
PIC16f73 PINOUT DESCRIPTION
There are 28 pins on PIC16F73. Most of them can be used as an IO pin. Others are
already for specific functions. These are the pin functions.
1. MCLR – to reset the PIC
2. RA0 – port A pin 0
3. RA1 – port A pin 1
4. RA2 – port A pin 2
5. RA3 – port A pin 3
6. RA4 – port A pin 4
7. RA5 – port A pin 5
8. VSS – ground
9. OSC1 – connect to oscillator
10. OSC2 – connect to oscillator
11. RC0 – port C pin 0 VDD – power supply
12. RC1 – port C pin 1
13. RC2 – port C pin 2
14. RC3 – port C pin 3
15. RC4 - port C pin 4
16. RC5 - port C pin 5
17. RC6 - port C pin 6
18. RC7 - port C pin 7
19. VSS - ground
20. VDD – power supply
21. RB0 - port B pin 0
22. RB1 - port B pin 1
23. RB2 - port B pin 2
24. RB3 - port B pin 3
25. RB4 - port B pin 4
26. RB5 - port B pin 5
27. RB6 - port B pin 6
28. RB7 - port B pin 7
Description of controller:
The reset logic is used to place the device into a known state. The source
of the reset can be determined by using the device status bits. The reset logic is designed
with features that reduce system cost and increase system reliability.
The on-chip parity bits that can be used to verify the contents of program
memory.Most registers are not affected by a WDT wake-up, since this is viewed as the
resumption of normal operation. Status bits TO, PD, POR and BOR.are set or cleared
differently in different reset situations. These bits are used in software to determine the
nature of the reset.All new devices will have a noise filter in the MCLR reset path to
detect and ignore small pulses.
A Power-on Reset pulse is generated on-chip when VDD rise is detected. To take
advantage of the POR, just tie the MCLR pin directly (or through a resistor) to VDD.
This will eliminate external RC components usually needed to create a Power-on Reset.
A minimum rise time for VDD is required.
When the device exits the reset condition (begins normal operation), the
device operating parameters (voltage, frequency, temperature, etc.) must be within their
operating ranges, otherwise the device will not function correctly. Ensure the delay is
long enough to get
Power-up Timer (PWRT)
configuration bit can enable/disable the Power-up Timer. The Power-up Timer should
always be enabled when Brown-out Reset is enabled. The polarity of the Power-up Timer
configuration bit is now PWRTE = 0 for enabled, while the initial definition of the bit
was PWRTE = 1 for enabled.Since all new devices will use the PWRTE = 0 for enabled,
the text will describe the operation for such devices.The power-up time delay will vary
from device to device due to VDD, temperature, and process variations.
The OST counts the oscillator pulses on the OSC1/CLKIN pin. The
counter only starts incrementing after the amplitude of the signal reaches the oscillator
input thresholds. This delay allows the crystal oscillator or resonator to stabilize before
the device exits the OST delay. The length of the time-out is a function of the
crystal/resonator frequency.
Figure 2.4 shows the operation of the OST circuit in conjunction with the
power-up timer. For low frequency crystals this start-up time can become quite long.
That is because the time it takes the low frequency oscillator to start oscillating is longer
than the power-up timer's delay. So the time from when the power-up timer times-out, to
when the oscillator starts to oscillate is a dead time.There is no minimum or maximum
time for this dead time (TDEADTIME).
Tosc1 = time for the crystal oscillator to react to an oscillation level detectable by the
TOST = 1024TOSC.
On-chip Brown-out Reset circuitry places the device into reset when the
device voltage falls below a trip point (BVDD). This ensures that the device does not
continue program execution outsidethe valid operation range of the device. Brown-out
resets are typically used in AC line applicationsor large battery applications where large
loads may be switched in (such as automotive),and cause the device voltage to
temporarily fall below the specified operating minimum.
During normal operation, a WDT time-out generates a device RESET. If the device
is in SLEEP mode, a WDT time-out causes the device to wake-up and continue with
normal operation, this is known as a WDT wake-up. The WDT can be permanently
disabled by clearing the WDTE configuration bit.The postscaler assignment is fully under
software control, i.e., it can be changed "on the fly" during program execution.
WDT Period: The WDT has a nominal time-out period of 18 ms, (with no postscaler).
The time-out period varies with temperature, VDD and process variations from part to
part. If longer time-outs are desired, a postscaler with a division ratio of up to 1:128 can
be assigned to the WDT, under software control, by writing to the OPTION_REG
register. Thus, time-out periods of up to 2.3 seconds can be realized.
The CLRWDT and SLEEP instructions clear the WDT and the postscaler (if
assigned to the WDT) and prevent it from timing out and generating a device RESET.
The TO bit in the STATUS register will be cleared upon a Watchdog Timer time-out
(WDT Reset and WDT wake-up).
Memory Organization
There are two memory blocks in each of these PICmicro® MCUs. The
Program Memory and Data Memory have separate buses so that concurrent access can
occur .The Program Memory can be read internally by user code.
The Data Memory is partitioned into multiple banks,which contain the General Purpose
Registers and the Special Function Registers. Bits RP1 (STATUS<6>) and RP0
(STATUS<5>) are the bank select bits:
Each bank extends up to 7Fh (128 bytes). The lower locations of each bank are reserved
for the Special Function Registers. Above the Special Function Registers are General
Purpose Registers, implemented as static RAM. All implemented banks contain Special
Function Registers. Some frequently used Special Function Registers from one bank may
be mirrored in another bank for code reduction and quicker access.
STATUS Register
The STATUS register contains the arithmetic status of the ALU, the
RESET status and the bank select bits for data memory.
For example, CLRF STATUS will clear the upper three bits and set
the Z bit. This leaves the STATUS register as 000u u1uu (where u = unchanged). It is
recommended, therefore, that only BCF, BSF,SWAPF and MOVWF instructions are
used to alter the STATUS register, because these instructions do not affect the Z, C, or
DC bits from the STATUS register. For other instructions not affecting any status bits,
see the "Instruction Set Summary."
bit 7 IRP: Register Bank Select bit (used for indirect addressing)
bit 6-5 RP1:RP0: Register Bank Select bits (used for direct addressing)
bit 1 DC: Digit carry/borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions)
1 = A carry-out from the 4th low order bit of the result occurred
I/O Ports
Some pins for these I/O ports are multiplexed with an alternate function
for the peripheral features on the device. In general, when a peripheral is enabled, that pin
may not be used as a general purpose I/O pin.
Reading the PORTA register reads the status of the pins, whereas
writing to it will write to the port latch. All write operations are read-modify-write
operations.Therefore, a write to a port implies that the port pins are read, the value is
modified and then written to the port data latch.
Pin RA4 is multiplexed with the Timer0 module clock input to become
the RA4/T0CKI pin. The RA4/T0CKI pin is a Schmitt Trigger input and an open drain
output.All other PORTA pins have TTL input levels and full CMOS output drivers.
Other PORTA pins are multiplexed with analog inputs and analog VREF
input. The operation of each pin is selected by clearing/setting the control bits in the
ADCON1 register (A/D Control Register1).
The TRISA register controls the direction of the RA pins, even when
they are being used as analog inputs.The user must ensure the bits in the TRISA register
are maintained set, when using them as analog inputs.
This interrupt can wake the device from SLEEP. The user, in the
Interrupt Service Routine, can clear the interrupt in the following manner:
a) Any read or write of PORTB. This will end the mismatch condition.
output, while other peripherals override the TRIS bit to make a pin an input. Since the
TRIS bit override is in effect while the peripheral is enabled,read-modify-write
instructions (BSF, BCF, XORWF) with TRISC as destination should be avoided.
Timer0 Module
• 8-bit timer/counter
(OPTION_REG<4>). Clearing bit T0SE selects the rising edge.The prescaler is mutually
exclusively shared between the Timer0 module and the Watchdog Timer. The prescaler is
not readable or writable.
Timer1 Module
• As a timer
• As a counter
modules as the special event trigger.When the Timer1 oscillator is enabled (T1OSCEN is
set), the RC1/T1OSI/CCP2 and RC0/T1OSO/T1CKI pins become inputs. That is, the
TRISC<1:0> value is ignored and these pins read as '0'.
Timer2 Module
Timer2 is an 8-bit timer with a prescaler and a postscaler. It can be
used as the PWM time-base for the PWM mode of the CCP module(s). The TMR2
register is readable and writable, and is cleared on any device RESET.The input clock
(FOSC/4) has a prescale option of 1:1,1:4 or 1:16, selected by control bits
T2CKPS1:T2CKPS0 (T2CON<1:0>).The Timer2 module has an 8-bit period register,
PR2.Timer2 increments from 00h until it matches PR2 and then resets to 00h on the next
increment cycle. PR2 is a readable and writable register. The PR2 register is initialized to
FFh upon RESET. The match output of TMR2 goes through a 4-bit postscaler (which
gives a 1:1 to 1:16 scaling inclusive) to generate a TMR2 interrupt (latched in flag bit
CAPTURE/COMPARE/PWM MODULES(CCP):
Both the CCP1 and CCP2 modules are identical in operation, with the
exception being the operation of the special event trigger.In the following sections, the
operation of a CCP module is described with respect to CCP1. CCP2 operates the same
as CCP1, except where noted.
CCP1 Module
Capture/Compare/PWM Register1 (CCPR1) is comprised of two 8-bit
registers: CCPR1L (low byte) and CCPR1H (high byte). The CCP1CON register controls
the operation of CCP1. The special event trigger is generated by a compare match and
will clear both TMR1H and TMR1L registers.
CCP2 Module
SSP Module
SPI Mode
to be specified:
SCK)
SSP I2 C Operation
functions, except general call support, and provides interrupts on START and STOP bits
in hardware to facilitate firmware implementations of the master functions. The SSP
module implements the standard mode specifications as well as 7-bit and 10-bit
addressing.Two pins are used for data transfer. These are the RC3/SCK/SCL pin, which
is the clock (SCL), and the RC4/SDI/SDA pin, which is the data (SDA). The user must
• I2C Slave mode (7-bit address), with START and STOP bit interrupts enabled to
• I2C Slave mode (10-bit address), with START and STOP bit interrupts enabled to
support Firmware Master mode
• I2C START and STOP bit interrupts enabled to support Firmware Master mode, Slave
is IDLE Selection of any I2C mode with the SSPEN bit set, forces the SCL and SDA pins
to be open drain, provide these pins are programmed to inputs by setting the appropriate
TRISC bits. Pull-up resistors must be provided externally to the SCL and SDA pins for
proper operation of the I2C module.
receives the LSb first. The USART's transmitter and receiver are functionally
independent, but use the same data format and baud rate. The baud rate generator
produces a clock, either x16 or x64 of the bit shift rate, depending on bit BRGH
(TXSTA<2>). Parity is not supported by the hardware, but can be implemented in
software (and stored as the ninth data bit). Asynchronous mode is stopped during SLEEP.
• Sampling Circuit
• Asynchronous Transmitter
• Asynchronous Receiver
USART Synchronous Master Mode:
master clock on the CK line. The Master mode is entered by setting bit
CSRC(TXSTA<7>).
Synchronous Slave mode differs from the Master mode, in that the shift
clock is supplied externally at the RC6/TX/CK pin (instead of being supplied internally
in Master mode). This allows the device to transfer or receive data while in SLEEP mode.
Slave mode is entered by clearing bit CSRC (TXSTA<7>).
The 8-bit analog-to-digital (A/D) converter module has five inputs for
the PIC16f73.The A/D allows conversion of an analog input signal to a corresponding 8-
bit digital number.The output of the sample and hold is the input into the converter,
which generates the result via successive approximation.The analog reference voltage is
software selectable to either the device's positive supply voltage (VDD), or the voltage
level on the RA3/AN3/VREF pin.The A/D converter has a unique feature of being able to
operate while the device is in SLEEP mode. To operate in SLEEP, the A/D conversion
clock must be derived from the A/D's internal RC oscillator. The A/D module has three
registers. These registers are:
The ADCON0 register controls the operation of the A/D module. The ADCON1 register,
configures the functions of the port pins. The port pins can be configured as analog inputs
(RA3 can also be a voltage reference), or as digital I/O.
Instruction Set:
• Byte-oriented operations
• Bit-oriented operations
For example, a "clrf PORTB" instruction will read PORTB, clear all the
data bits, then write the result back to PORTB. This example would have the unintended
result that the condition that sets the RBIF flag would be cleared for pins configured as
inputs and using the PORTB interrupt-on-change feature