Файл: Microcontroller Programming. Thi Micro Chip PIC (Julio Sanchez, 2007).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 14.06.2025
Просмотров: 8680
Скачиваний: 0
Supplementary Programs |
747 |
;=========================
;end of keypad? ;=========================
;Test for last key row (maximum count is 4)
decfsz rowCount,f ; Decrement counter goto keyLoop
;=========================
;display scan code ;=========================
;At this point all keys have been tested
;variable scanCode holds scan code
movf |
scanCode,w |
||
movwf |
PORTD |
||
call |
long_delay |
; |
Debounce |
goto |
keyScan |
; |
Continue |
;==========================
;calculate scan code ;==========================
;The column position is added to the row code (stored
;in rowCode register). Sum is the scan code
col0:
movf |
rowCode,w |
; Row code to w |
||
addlw |
0x00 |
; Add 0 (clearly not necessary) |
||
movwf |
scanCode ; Final value |
|||
return |
||||
col1:m |
||||
movf |
rowCode,w |
; Row code to w |
||
addlw |
0x01 |
; Add 1 |
||
movwf |
scanCode |
|||
return |
||||
col2: |
||||
movf |
rowCode,w |
; Row code to w |
||
addlw |
0x02 |
; Add 2 |
||
movwf |
scanCode |
|||
return |
||||
col3: |
||||
movf |
rowCode,w |
; Row code to w |
||
addlw |
0x03 |
; Add 3 |
||
movwf |
scanCode |
|||
return |
||||
;============================= |
||||
; |
long delay sub-routine |
|||
;============================= |
||||
748 |
Appendix D |
|||
long_delay |
||||
movlw |
D'200' |
; w delay count |
||
movwf |
J |
; J = w |
||
jloop: |
movwf |
K |
; K = w |
|
kloop: |
decfsz |
K,f |
; K = K-1, skip next if zero |
|
goto |
kloop |
|||
decfsz |
J,f |
; J = J-1, skip next if zero |
||
goto |
jloop |
|||
return |
||||
End |
||||
Supplementary Programs |
749 |
;File name: RamDemo.asm
;Last revision: May 27, 2006
;Author: Julio Sanchez
;PIC: 16F877
;Description:
;Program to demonstrate access to General Purpose Register
;located in different banks. 16F877 GPR space is as
;follows:
; BANK 0 |
BANK 1 |
BANK 2 |
BANK 3 |
||
; |
0x20 |
0xa0 |
0x110 |
0x190 |
| |
; |
-- |
-- |
-- |
-- |
| bank |
; |
-- |
-- |
-- |
-- |
| related |
; |
-- |
0xef |
0x16f |
0x1ef | |
|
; |
-- |
0xf0 |
0x170 |
0x1f0 | |
|
; |
0x70 |
<== access registers at 0x70-0x7f |
|||
; |
0x7f |
these GPRs are common to all banks |
|||
; |
|||||
;Program is designed to be used with a debugger so that
;access to different registers can be tested
;GPR registers are named according to the following format:
; |
REGx_yyy |
||||
; |
| |
||| |
|||
; |
| |
|||_________ |
hex address |
(up to 3 |
digits) |
; |
|_____________ |
bank number |
(0 to 3) |
||
; |
|||||
;CONCLUSIONS:
;GPRs located between 0x70 and 0x7f can be accessed from
;any bank. GPRs at other addresses require previous bank
;selection
;
;===========================
;16F877 switches ;===========================
;Switches used in __config directive:
; |
_CP_ON |
Code protection ON/OFF |
|
; * |
_CP_OFF |
||
; |
* |
_PWRTE_ON |
Power-up timer ON/OFF |
;_PWRTE_OFF
; |
_BODEN_ON |
Brown-out reset enable ON/OFF |
|
; * |
_BODEN_OFF |
||
; |
* |
_PWRTE_ON |
Power-up timer enable ON/OFF |
;_PWRTE_OFF
; |
_WDT_ON |
Watchdog timer |
ON/OFF |
; * _WDT_OFF |
|||
; |
_LPV_ON |
Low voltage IC |
programming enable ON/OFF |
; * _LPV_OFF |
|||
Supplementary Programs |
751 |
||
reg0_50 |
equ |
0x50 |
|
reg0_7e |
equ |
0x7e |
|
reg1_a0 |
equ |
0xa0 |
|
;============================================================ |
|||
; |
P R O G R A M |
||
;============================================================ |
|||
org |
0 |
; start at address |
|
goto |
main |
||
; Space for interrupt handlers |
|||
org |
0x08 |
||
main: |
|||
Bank0 |
|||
nop |
|||
movlw |
0xee |
; Test value |
|
movwf |
reg0_20 |
||
movwf |
reg0_7e |
||
; |
|||
Bank1 |
|||
; Register at address 0x20 in bank 0 cannot be accessed
nop |
|
movf |
reg0_20,w |
nop |
; However, the register at 0x7e CAN be accessed
movf |
reg0_7e,w |
nop |
|
Bank0 |
|
movlw |
0x0 |
movf |
reg0_7e,w |
nop |
|
; How about from bank 3 |
|
Bank3 |
|
movlw |
0x0 |
movf |
reg0_7e,w |
nop |
|
loopHere: |
|
goto |
loopHere |
;============================================================
end ; END OF PROGRAM
;============================================================