Выбрать главу
Example 1.38

Write the decimal number 295 as a BCD number.

Solution 1.38

Write the 4-bit binary equivalent of each digit:

2 = 00102 9 = 10012 5 = 01012

The BCD number is 0010 1001 01012.

Example 1.39

Write the decimal equivalent of BCD number 1001 1001 0110 00012.

Solution 1.39

Writing the decimal equivalent of each group of 4-bit yields the decimal number: 9961

1.24 Summary

Chapter 1 has provided an introduction to the microprocessor and microcontroller systems. The basic building blocks of microcontrollers were described briefly. The chapter also provided an introduction to various number systems, and described how to convert a given number from one base into another. The important topics of floating point numbers and floating point arithmetic were also described with examples.

1.25 Exercises

1. What is a microcontroller? What is a microprocessor? Explain the main difference between a microprocessor and a microcontroller.

2. Identify some applications of microcontrollers around you.

3. Where would you use an EPROM memory?

4. Where would you use a RAM memory?

5. Explain the types of memory usually used in microcontrollers.

6. What is an input-output port?

7. What is an analog-to-digital converter? Give an example of how this converter is used.

8. Explain why a watchdog timer could be useful in a real-time system.

9. What is serial input-output? Where would you use serial communication?

10. Why is the current sink/source capability important in the specification of an output port pin?

11. What is an interrupt? Explain what happens when an interrupt is recognized by a microcontroller?

12. Why is brown-out detection important in real-time systems?

13. Explain the difference between an RISC-based microcontroller and a CISC-based microcontroller. What type of microcontroller is PIC?

14. Convert the following decimal numbers into binary:

 a) 23 b) 128 c) 255 d) 1023

 e) 120 f) 32000 g) 160 h) 250

15. Convert the following binary numbers into decimaclass="underline"

 a) 1111 b) 0110 c) 11110000

 d) 00001111 e) 10101010 f) 10000000

16. Convert the following octal numbers into decimaclass="underline"

 a) 177 b) 762 c) 777 d) 123

 e) 1777 f) 655 g) 177777 h) 207

17. Convert the following decimal numbers into octaclass="underline"

 a) 255 b) 1024 c) 129 d) 2450

 e) 4096 f) 256 g) 180 h) 4096

18. Convert the following hexadecimal numbers into decimaclass="underline"

 a) AA b) EF c) 1FF d) FFFF

 e) 1AA f) FEF g) F0 h) CC

19. Convert the following binary numbers into hexadecimaclass="underline"

 a) 0101 b) 11111111 c) 1111 d) 1010

 e) 1110 f) 10011111 g) 1001 h) 1100

20. Convert the following binary numbers into octaclass="underline"

 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 octaclass="underline"

 a) AA b) FF c) FFFF d) 1AC

 e) CC f) EE g) EEFF h) AB

23. Convert the following octal numbers into hexadecimaclass="underline"

 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