a) 23 b) 128 c) 255 d) 1023
e) 120 f) 32000 g) 160 h) 250
15. Convert the following binary numbers into decimal:
a) 1111 b) 0110 c) 11110000
d) 00001111 e) 10101010 f) 10000000
16. Convert the following octal numbers into decimal:
a) 177 b) 762 c) 777 d) 123
e) 1777 f) 655 g) 177777 h) 207
17. Convert the following decimal numbers into octal:
a) 255 b) 1024 c) 129 d) 2450
e) 4096 f) 256 g) 180 h) 4096
18. Convert the following hexadecimal numbers into decimal:
a) AA b) EF c) 1FF d) FFFF
e) 1AA f) FEF g) F0 h) CC
19. Convert the following binary numbers into hexadecimal:
a) 0101 b) 11111111 c) 1111 d) 1010
e) 1110 f) 10011111 g) 1001 h) 1100
20. Convert the following binary numbers into octal:
a) 111000 b) 000111 c) 1111111 d) 010111
e) 110001 f) 11111111 g) 1000001 h) 110000
21. Convert the following octal numbers into binary:
a) 177 b) 7777 c) 555 d) 111
e) 1777777 f) 55571 g) 171 h) 1777
22. Convert the following hexadecimal numbers into octal:
a) AA b) FF c) FFFF d) 1AC
e) CC f) EE g) EEFF h) AB
23. Convert the following octal numbers into hexadecimal:
a) 177 b) 777 c) 123 d) 23
e) 1111 f) 17777777 g) 349 h) 17
24. Convert the following decimal numbers into floating point:
a) 23.45 b) 1.25 c) 45.86 d) 0.56
25. Convert the following decimal numbers into floating point and then calculate their sum:
0.255 and 1.75
26. Convert the following decimal numbers into floating point and then calculate their product:
2.125 and 3.75
27. Convert the following decimal numbers into BCD:
a) 128 b) 970 c) 900 d) 125
CHAPTER 2
PIC18F Microcontroller Series
PIC16-series microcontrollers have been around for many years. Although these are excellent general purpose microcontrollers, they have certain limitations. For example, the program and data memory capacities are limited, the stack is small, and the interrupt structure is primitive, all interrupt sources sharing the same interrupt vector. PIC16-series microcontrollers also do not provide direct support for advanced peripheral interfaces such as USB, CAN bus, etc., and interfacing with such devices is not easy. The instruction set for these microcontrollers is also limited. For example, there are no multiplication or division instructions, and branching is rather simple, being a combination of skip and goto instructions.
Microchip Inc. has developed the PIC18 series of microcontrollers for use in high-pincount, high-density, and complex applications. The PIC18F microcontrollers offer cost-efficient solutions for general purpose applications written in C that use a real-time operating system (RTOS) and require a complex communication protocol stack such as TCP/IP, CAN, USB, or ZigBee. PIC18F devices provide flash program memory in sizes from 8 to 128Kbytes and data memory from 256 to 4Kbytes, operating at a range of 2.0 to 5.0 volts, at speeds from DC to 40MHz.
The basic features of PIC18F-series microcontrollers are:
• 77 instructions
• PIC16 source code compatible
• Program memory addressing up to 2 Mbytes
• Data memory addressing up to 4 Kbytes
• DC to 40MHz operation
• 8×8 hardware multiplier
• Interrupt priority levels
• 16-bit-wide instructions, 8-bit-wide data path
• Up to two 8-bit timers/counters
• Up to three 16-bit timers/counters
• Up to four external interrupts
• High current (25mA) sink/source capability
• Up to five capture/compare/PWM modules
• Master synchronous serial port module (SPI and I²C modes)
• Up to two USART modules
• Parallel slave port (PSP)
• Fast 10-bit analog-to-digital converter
• Programmable low-voltage detection (LVD) module
• Power-on reset (POR), power-up timer (PWRT), and oscillator start-up timer (OST)
• Watchdog timer (WDT) with on-chip RC oscillator
• In-circuit programming
In addition, some microcontrollers in the PIC18F family offer the following special features:
• Direct CAN 2.0 bus interface
• Direct USB 2.0 bus interface
• Direct LCD control interface
• TCP/IP interface
• ZigBee interface
• Direct motor control interface
Most devices in the PIC18F family are source compatible with each other. Table 2.1 gives the characteristics of some of the popular devices in this family. This chapter offers a detailed study of the PIC18FXX2 microcontrollers. The architectures of most of the other microcontrollers in the PIC18F family are similar.
Table 2.1: The 18FXX2 microcontroller family
Feature |
PIC18F242 |
PIC18F252 |
PIC18F442 |
PIC18F452 |
Program memory (Bytes) |
16K |
32K |
16K |
32K |
Data memory (Bytes) |
768 |
1536 |
768 |
1536 |
EEPROM (Bytes) |
256 |
256 |
256 |
256 |
I/O Ports |
A,B,C |
A,B,C |
A,B,C,D,E |
A,B,C,D,E |
Timers |
4 |
4 |
4 |
4 |
Interrupt sources |
17 |
17 |
18 |
18 |
Capture/compare/PWM |
2 |
2 |
2 |
2 |
Serial communication |
MSSP USART |
MSSP USART |
MSSP USART |
MSSP USART |
A/D converter (10-bit) |
5 channels |
5 channels |
8 channels |
8 channels |
Low-voltage detect |
yes |
yes |
yes |
yes |
Brown-out reset |
yes |
yes |
yes |
yes |
Packages |
28-pin DIP 28-pin SOIC |
28-pin DIP 28-pin SOIC |
40-pin DIP 44-pin PLCC 44-pin TQFP |
40-pin DIP 44-pin PLCC 44-pin TQFP |
The reader may be familiar with the programming and applications of the PIC16F series. Before going into the details of the PIC18F series, it is worthwhile to compare the features of the PIC18F series with those of the PIC16F series.
The following are similarities between PIC16F and PIC18F:
• Similar packages and pinouts
• Similar special function register (SFR) names and functions
• Similar peripheral devices
• Subset of PIC18F instruction set
• Similar development tools
The following are new with the PIC18F series:
• Number of instructions doubled
• 16-bit instruction word
• Hardware 8×8 multiplier
• More external interrupts
• Priority-based interrupts
• Enhanced status register
• Increased program and data memory size
• Bigger stack
• Phase-locked loop (PLL) clock generator
• Enhanced input-output port architecture
• Set of configuration registers
• Higher speed of operation
• Lower power operation
2.1 PIC18FXX2 Architecture
As shown in Table 2.1, the PIC18FXX2 series consists of four devices. PIC18F2X2 microcontrollers are 28-pin devices, while PIC18F4X2 microcontrollers are 40-pin devices. The architectures of the two groups are almost identical except that the larger devices have more input-output ports and more A/D converter channels. In this section we shall be looking at the architecture of the PIC18F452 microcontroller in detail. The architectures of other standard PIC18F-series microcontrollers are similar, and the knowledge gained in this section should be enough to understand the operation of other PIC18F-series microcontrollers.
The pin configuration of the PIC18F452 microcontroller (DIP package) is shown in Figure 2.1. This is a 40-pin microcontroller housed in a DIL package, with a pin configuration similar to the popular PIC16F877.
Читать дальше