PIC18F45K20-I/ML Microchip Technology, PIC18F45K20-I/ML Datasheet - Page 40

IC PIC MCU FLASH 16KX16 44QFN

PIC18F45K20-I/ML

Manufacturer Part Number
PIC18F45K20-I/ML
Description
IC PIC MCU FLASH 16KX16 44QFN
Manufacturer
Microchip Technology
Series
PIC® XLP™ 18Fr

Specifications of PIC18F45K20-I/ML

Program Memory Type
FLASH
Program Memory Size
32KB (16K x 16)
Package / Case
44-QFN
Core Processor
PIC
Core Size
8-Bit
Speed
64MHz
Connectivity
I²C, SPI, UART/USART
Peripherals
Brown-out Detect/Reset, HLVD, POR, PWM, WDT
Number Of I /o
35
Eeprom Size
256 x 8
Ram Size
1.5K x 8
Voltage - Supply (vcc/vdd)
1.8 V ~ 3.6 V
Data Converters
A/D 14x10b
Oscillator Type
Internal
Operating Temperature
-40°C ~ 85°C
Processor Series
PIC18F
Core
PIC
Data Bus Width
8 bit
Data Ram Size
1.5 KB
Interface Type
CCP/ECCP/EUSART/I2C/MSSP/SPI
Maximum Clock Frequency
64 MHz
Number Of Programmable I/os
36
Number Of Timers
4
Maximum Operating Temperature
+ 85 C
Mounting Style
SMD/SMT
3rd Party Development Tools
52715-96, 52716-328, 52717-734, 52712-325, EWPIC18
Development Tools By Supplier
PG164130, DV164035, DV244005, DV164005, PG164120, DV164136
Minimum Operating Temperature
- 40 C
On-chip Adc
14-ch x 10-bit
Package
44QFN EP
Device Core
PIC
Family Name
PIC18
Maximum Speed
64 MHz
Operating Supply Voltage
2.5|3.3 V
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With
DM240313 - BOARD DEMO 8BIT XLPAC164112 - VOLTAGE LIMITER MPLAB ICD2 VPPDM164124 - KIT STARTER FOR PIC18F4XK20AC164322 - MODULE SOCKET MPLAB PM3 28/44QFN
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
PICkit™ 3 Debug Express
DS41370C-page 36
Line 5 sets bit 7, TMR0ON, of the T0CON register to turn on the timer so it begins
incrementing. Using one of the SFR unions to access bits, like T0CONbits.TMR0ON,
can change bits without affecting the other bits.
In the while(1) loop, the LED_Display global variable is updated to rotate the ‘1’ bit
based on the Direction variable value, and then LATD is updated.
The do{…}while() loop then polls the switch looking for a switch press while it waits
for the timer to overflow and set the TMR0IF flag bit. This is a simplistic example of how
using a timer allows the microcontroller to do work while waiting on a time delay,
instead of wasting processing time counting cycles in an instruction loop.
Once the switch it pressed, the Direction variable value is reversed. Follow the
if – else if logic flow in the do{…}while() loop to see how once the switch is
pressed, the direction is reversed only once until it is released and pressed again.
Lastly, once Timer0 overflows and sets the TMR0IF flag the do{…}while() loop is
exited. TMR0IF is then cleared in the software program so the next timer overflow can
be detected.
3.5.3
Build and program the Lesson 5 project. The LEDs will rotate, and pressing the Demo
Board button will reverse them.
3.5.4
Now we’ll go back to that commented-out line of code in the Timer0 setup statements.
Comment out the T0CON assignment statement, and un-comment the other statement
so the Timer0 setup code looks like this:
will rotate more slowly, 4 times slower to be exact, than before.
Rebuild and reprogram the Lesson 5 project with change in the source code. The LEDs
Take a look at what this changes:
T0PS2:T0PS0 = 001
PSA = 0
Note:
INTCONbits.TMR0IF
//T0CON
T0CON
TMR0H
TMR0L
T0CONbits.TMR0ON
This value sets the prescale value to 1:4, which means Timer0 will now increment
once every 4 instruction cycles instead of once every instruction cycle. It now takes
4 times as long for it to count up to 65536 – just over 1 second!
The prescaler is now assigned to Timer0, and the values of T0PSx will set the
prescaler clock divider ratio.
Build and Program the Lesson 5 Code
Assigning the Timer0 Prescaler
Be aware that some cases using an SFR union to access a bit may affect
other bits. What actually happens during this instruction execution is the
register is read, the bit is modified, and the entire register is re-written. This
operation is called Read-Modify-Write. If a bit reads a different value than
what it was last set as, this operation may affect register bits other than the
intended one. Check the SFR bit definitions carefully. In the case of
T0CON, all bits are Read/Write and all are set by software only; the hard-
ware will not affect any bit setting.
=
=
=
=
0b00000001;
0;
0;
0b00001000;
=
=
1;
0;
© 2009 Microchip Technology Inc.

Related parts for PIC18F45K20-I/ML