The pic16F84 Microcontroller Part 3 Timer


Program 4.2 directly implements this strategy


Download 305.41 Kb.
bet6/7
Sana15.06.2023
Hajmi305.41 Kb.
#1477874
1   2   3   4   5   6   7
Bog'liq
The PIC16F84 Microcontroller Part 3

Program 4.2 directly implements this strategy. The full Carry flag is tested three times.
1. Directly after the addition – for example, 99h + 99h = 1 32h.
2. After the first correction where six is added to the lower digit – for example, 77h + 88h = FFh; FFh + 06h = 1 05h.
3. After the second correction where six is added to the upper digit – for example, 70h + 80h = F0h; F0h + 60h = 1 40h.
If the flag is set at any point then the hundreds digit will be one; the maximum value in this case is 99 + 99 = 198.
A nybble is tested for over nine by subtracting ten. If a carry (half or full depending on which digit is being tested) is not generated then the original nybble must have been ten or greater. I have actually implemented the subtract ten operation by adding -10; that is addlw -10. This is because the sublw instruction actually takes the value in the Working register away from the literal and not the other way around.
Program 4.2 Adding two packed BCD numbers.

Self-assessment questions


4.1 The PIC16F877 mid-range MCU has a 8 kbyte Program store, which can hold up to 8192 14-bit instructions located in the range 0000 -1FFFh. As part of a certain program, execution has to be transferred from the bottom quarter of this map to 1000h. Given that the goto instruction can only directly access 11-bit addresses (0000 – 07FFh), how could you engineer a jump to this address, i.e. goto 1000h?
4.2 Write a routine to decrement a packed BCD quantity, as in Example 4.3. Hint: Devise a simple test to activate the relevant carry flag if the digit is Fh.
4.3 Write a routine to add ten onto a packed BCD byte located in File 20h. Hint: This is similar to Example 4.3 but only the tens digit is augmented.
4.4 Where microprocessors are used in a general-purpose computing environment, the program is normally loaded into and run from read/write RAM memory. This means that the system can run a word-processor one minute and a spreadsheet program the next. Of course this means of operation is not applicable to embedded applications, where the program is stored in some variety of non-volatile read-only memory. Discuss why this is so and the virtues of ROM, EPROM and EEPROM implementations of non-volatile storage.

Download 305.41 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling