Файл: Microcontroller Programming. Thi Micro Chip PIC (Julio Sanchez, 2007).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 14.06.2025
Просмотров: 8665
Скачиваний: 0
676 |
Appendix D |
retlw 'n' retlw 'n' retlw 'e' retlw 's' retlw 'o' retlw 't' retlw 'a' retlw 0
;=================================
;second text string procedure ;================================= storeUniv:
;Processing identical to procedure StoreMSU
movwf |
index |
; |
Store w in index |
; Store base address of text buffer in fsr |
|||
movf |
pic_ad,0 ; |
first display RAM address to W |
|
addwf |
index,0 |
; |
Add offset to address |
movwf |
fsr |
; |
W to FSR |
; Initialize index for text string access |
|||
movlw |
0 |
; |
Start at 0 |
movwf |
index |
; |
Store index in variable |
; w still = 0 |
|||
get_msg_char2: |
|||
call |
msg2 |
; |
Get character from table |
; Test for zero terminator |
|||
andlw |
0x0ff |
||
btfsc |
status,z ; |
Test zero flag |
|
goto |
endstr2 |
; |
End of string |
;ASSERT: valid string character in w
;store character in text buffer (by fsr)
movwf |
indf |
; Store in buffer by fsr |
|
incf |
fsr,f |
; Increment buffer pointer |
|
; Restore table character counter from variable |
|||
movf |
index,w |
; Get value into w |
|
addlw |
1 |
; Bump to next character |
|
movwf |
index |
; Store table index in variable |
|
goto |
get_msg_char2 |
; Continue |
|
endstr2: |
|||
return |
|||
; Routine for returning message stored in program area msg2:
addwf |
PCL,f |
; Access table |
retlw |
'S' |
|
retlw |
't' |
|
retlw |
'a' |
|
retlw |
't' |
678 |
Appendix D |
;File: TestDemo1.asm
;Date: June 2, 2006
;Author: Julio Sanchez
;Processor: 16F84A
;Description:
;Program to exercise the demonstration circuit and board
;number 1
;===========================
;switches ;===========================
;Switches used in __config directive:
; |
_CP_ON |
Code protection ON/OFF |
|
; * |
_CP_OFF |
||
; |
* |
_PWRTE_ON |
Power-up timer ON/OFF |
;_PWRTE_OFF
; |
_WDT_ON |
Watchdog timer ON/OFF |
||
; * _WDT_OFF |
||||
; |
_LP_OSC |
Low power crystal |
occilator |
|
; * _XT_OSC |
External parallel |
resonator/crystal |
||
; |
oscillator |
|||
; |
_HS_OSC |
High speed crystal resonator (8 to |
10 MHz) |
|
; |
Resonator: Murate |
Erie CSA8.00MG = |
8 MHz |
|
; |
_RC_OSC |
Resistor/capacitor oscillator |
||
;|
;|_____ * indicates setup values
processor |
16f84A |
include |
<p16f84A.inc> |
__config |
_XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF |
;=====================================================
; constants
;====================================================
;#define dummy |
100 |
;=====================================================
; variables in PIC RAM
;=====================================================
; with local variables |
|||
cblock 0x0c |
; Start of block |
||
; |
hexDig |
; Hex digit |
counter |
count1 |
; Counter # |
1 |
|
j |
; counter J |
||
k |
; counter K |
||
endc |
|||
;=======================================================
; P R O G R A M
Supplementary Programs |
679 |
||
;======================================================= |
|||
org |
0 |
; start at address 0 |
|
goto |
main |
||
; |
|||
; Space for interrupt handlers |
|||
org |
0x08 |
||
main: |
|||
; Port A (5 lob) for input |
|||
movlw |
B'00011111' |
; w := 00001111 binary |
|
tris |
PORTA |
; port A (lines 0 to 4) to |
|
input |
|||
; Port bit (8 lines) for output |
|||
movlw |
B'00000000' |
; w := 00000000 binary |
|
tris |
PORTB |
; port B to output |
|
;==============================
;Pushbutton switch processing ;============================== pbutton:
;Push button switch on demo board is wired to RA4
;Switch logic is active low
btfss |
PORTA,4 |
; Test and skip if bit is set |
goto |
buzzit |
; Buzz if switch ON |
; At this point port A bit 4 is set (switch is off) |
||
call |
buzoff |
; Buzzer off |
goto |
readdip |
; Read DIP switches |
buzzit: |
||
call |
buzon |
; Turn on buzzer |
goto |
pbutton |
|
;==============================
;DIP switch processing ;==============================
;Read all bits of port A readdip:
movf |
PORTA,w |
; Port A bits to w |
;If board uses active low then all switch bits must be negated
;This is done by XORing with 1-bits
xorlw |
b'11111111' |
; Invert all bits in w |
; Eliminate all 4 high order bits (just in case) |
||
andlw |
b'00001111' |
; And with mask |
; Get digit into w |
||
call |
segment |
; get digit code |
movwf |
PORTB |
; Display digit |
call |
delay |
; Give time |
; Update digit and loop counter |
||
goto |
pbutton |
|
;******************************* ; 7-segment table of hex codes
680 |
Appendix D |
|
;******************************* |
||
segment: |
||
addwf |
PCL,f |
; PCL is program counter latch |
retlw |
0x3f |
; 0 code |
retlw |
0x06 |
; 1 |
retlw |
0x5b |
; 2 |
retlw |
0x4f |
; 3 |
retlw |
0x66 |
; 4 |
retlw |
0x6d |
; 5 |
retlw |
0x7d |
; 6 |
retlw |
0x07 |
; 7 |
retlw |
0x7f |
; 8 |
retlw |
0x6f |
; 9 |
retlw |
0x77 |
; A |
retlw |
0x7c |
; B |
retlw |
0x39 |
; C |
retlw |
0x5b |
; D |
retlw |
0x79 |
; E |
retlw |
0x71 |
; F |
retlw |
0x7f |
; Just in case all on |
;****************************
;piezo buzzer ON ;****************************
;Routine to turn on piezo buzzer on port B bit 7 buzon:
bsf |
PORTB,7 |
; Tune on bit 7, port B |
return |
;****************************
;piezo buzzer OFF ;****************************
;Routine to turn off piezo buzzer on port B bit 7 buzoff:
bcf |
PORTB,7 |
; Bit |
7 port b clear |
|
return |
||||
;================================ |
||||
; |
delay sub-routine |
|||
;================================ |
||||
delay: |
||||
movlw |
.200 |
; w = 200 decimal |
||
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 |
|
682 |
Appendix D |
;File: Timer0.ASM
;Date: April 27, 2006
;Author: Julio Sanchez
;Processor: a6F84A
;Description:
;Program to demonstrate programming of the 16F84A
;TIMER0 module. Program flashes eight LEDs in sequence
;counting from 0 to 0xff. Timer0 is used to delay
;the count.
;===========================
;switches ;===========================
;Switches used in __config directive:
; |
_CP_ON |
Code protection ON/OFF |
|
; * |
_CP_OFF |
||
; |
* |
_PWRTE_ON |
Power-up timer ON/OFF |
;_PWRTE_OFF
; |
_WDT_ON |
Watchdog timer ON/OFF |
||
; * _WDT_OFF |
||||
; |
_LP_OSC |
Low power crystal |
occilator |
|
; * _XT_OSC |
External parallel |
resonator/crystal oscillator |
||
; |
_HS_OSC |
High speed crystal resonator (8 to |
10 MHz) |
|
; |
Resonator: Murate |
Erie CSA8.00MG = |
8 MHz |
|
; |
_RC_OSC |
Resistor/capacitor oscillator (simplest, 20% |
||
error)
;|
;|_____ * indicates setup values
processor |
16f84A |
|
include |
<p16f84A.inc> |
|
__config |
_XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF |
|
;===================================================== |
||
; |
variables in PIC RAM |
|
;===================================================== ; None in this application
;
;========================================================
; m a i n p r o g r a m
;========================================================
org |
0 |
; start at address 0 |
goto |
main |
;
;=============================
; interrupt handler
;=============================
org |
0x08 |