Chapter 9PIC18F Hardware and Interfacing Using C: Part 2

In this chapter we describe the second part of hardware aspects of the PIC18F4321. Topics include PIC18F4321's on-chip timers, LCD displays, analog interfaces (ADC and DAC), serial I/O, and CCP (Capture/Compare/Pulse Width Modulation). Several C-programs are written to illustrate these concepts.

9.1 PIC18F Timers

The PIC18F4321 microcontroller includes four timers, namely, Timer0 (8-bit or 16-bit), Timer1 (16-bit), Timer2 (8-bit), and Timer3 (16-bit). These timers can be used to generate time delays using on-chip hardware. Because these timers are on-chip hardware devices, they accurately keep time in the background while other functions are performed by the PIC18F4321.

The basic hardware inside each of these timers is a register that can be incremented or decremented at the rising or falling edge of a clock. The register can be loaded with a count for a specific time delay. Time delay is computed by subtracting the initial starting count from the final count in the register, and then multiplying the subtraction result by the clock frequency.

These timers can also be used as event counters. Note that an event counter is basically a register with the clock replaced by an event such as a switch. The counter is incremented or decremented whenever the switch is activated. Thus the number of times the switch is activated (occurrence of the event) can be determined.

Timer0 can operate as an 8-bit timer or a 16-bit timer. Timer0 ...

Get Fundamentals of Digital Logic and Microcontrollers, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.