PIC18F45K20-E/P Microchip Technology, PIC18F45K20-E/P Datasheet - Page 40

32KB, Flash, 1536bytes-RAM, 36I/O, 8-bit Family,nanowatt XLP 40 PDIP .600in TUBE

PIC18F45K20-E/P

Manufacturer Part Number
PIC18F45K20-E/P
Description
32KB, Flash, 1536bytes-RAM, 36I/O, 8-bit Family,nanowatt XLP 40 PDIP .600in TUBE
Manufacturer
Microchip Technology
Series
PIC® XLP™ 18Fr

Specifications of PIC18F45K20-E/P

Core Processor
PIC
Core Size
8-Bit
Speed
48MHz
Connectivity
I²C, SPI, UART/USART
Peripherals
Brown-out Detect/Reset, HLVD, POR, PWM, WDT
Number Of I /o
35
Program Memory Size
32KB (16K x 16)
Program Memory Type
FLASH
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 ~ 125°C
Package / Case
40-DIP (0.600", 15.24mm)
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 PIC18F4XK20
Lead Free Status / RoHS Status
Lead free / RoHS Compliant

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
PIC18F45K20-E/PT
Manufacturer:
Microchip Technology
Quantity:
10 000
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-E/P