1 |
2 |
MichaelA |
;*******************************************************************************
|
2 |
|
|
; M16C5x_Tst2.ASM
|
3 |
|
|
;
|
4 |
|
|
; This is the source for the test program used to develop the PIC16C5x proce-
|
5 |
|
|
; core. It has also been used to test the P16C5x version of the PIC16C5x core.
|
6 |
|
|
;
|
7 |
|
|
; The first instruction of the program is expected to be placed in location 0.
|
8 |
|
|
;
|
9 |
|
|
; The program tests most instructions, but not is a self-checking manner. In-
|
10 |
|
|
; spection of the registers is the method used to verify that the cores are
|
11 |
|
|
; operating correctly.
|
12 |
|
|
;
|
13 |
|
|
;*******************************************************************************
|
14 |
|
|
|
15 |
|
|
LIST P=16F59, R=DEC
|
16 |
|
|
|
17 |
|
|
;-------------------------------------------------------------------------------
|
18 |
|
|
; Set ScratchPadRam here. If you are using a PIC16C5X device, use:
|
19 |
|
|
;ScratchPadRam EQU 0x10
|
20 |
|
|
; Otherwise, use:
|
21 |
|
|
;ScratchPadRam EQU 0x20
|
22 |
|
|
;-------------------------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
ScratchPadRam EQU 0x0A
|
25 |
|
|
|
26 |
|
|
;-------------------------------------------------------------------------------
|
27 |
|
|
; Variables
|
28 |
|
|
;-------------------------------------------------------------------------------
|
29 |
|
|
|
30 |
|
|
INDF EQU 0 ; Indirect Register File Access Location
|
31 |
|
|
Tmr0 EQU 1 ; Timer 0
|
32 |
|
|
PCL EQU 2 ; Low Byte Program Counter
|
33 |
|
|
Status EQU 3 ; Processor Status Register
|
34 |
|
|
FSR EQU 4 ; File Select Register
|
35 |
|
|
PortA EQU 5 ; I/O Port A Address
|
36 |
|
|
PortB EQU 6 ; I/O Port B Address
|
37 |
|
|
PortC EQU 7 ; I/O Port C Address
|
38 |
|
|
|
39 |
|
|
Cntr EQU ScratchPadRam+0
|
40 |
|
|
MemStart EQU ScratchPadRam+1
|
41 |
|
|
Count EQU 32-MemStart
|
42 |
|
|
|
43 |
|
|
DelayLoop EQU ScratchPadRam+0
|
44 |
|
|
|
45 |
|
|
;-------------------------------------------------------------------------------
|
46 |
|
|
; Set Reset/WDT Vector
|
47 |
|
|
;-------------------------------------------------------------------------------
|
48 |
|
|
|
49 |
|
|
ORG H'7FF'
|
50 |
|
|
|
51 |
|
|
GOTO Start
|
52 |
|
|
|
53 |
|
|
;-------------------------------------------------------------------------------
|
54 |
|
|
; Main Program
|
55 |
|
|
;-------------------------------------------------------------------------------
|
56 |
|
|
|
57 |
|
|
ORG H'000'
|
58 |
|
|
|
59 |
|
|
;-------------------------------------------------------------------------------
|
60 |
|
|
Start BTFSS Status,3 ;; Test PD (STATUS.3), if 1, ~SLEEP restart
|
61 |
|
|
GOTO SleepRestart ;; SLEEP restart, continue test program
|
62 |
|
|
MOVLW 0x07 ;; load OPTION
|
63 |
|
|
OPTION
|
64 |
|
|
CLRW ;; clear working register
|
65 |
|
|
TRIS PortA ;; load W into port control registers
|
66 |
|
|
TRIS PortB
|
67 |
|
|
TRIS PortC
|
68 |
|
|
;
|
69 |
|
|
; GOTO Next ;; Test GOTO
|
70 |
|
|
;
|
71 |
|
|
GOTO Next
|
72 |
|
|
;
|
73 |
|
|
MOVLW 0xFF ;; instruction should be skipped
|
74 |
|
|
;
|
75 |
|
|
Next CALL Subroutine ;; Test CALL
|
76 |
|
|
|
77 |
|
|
MOVWF PCL ;; Test Computed GOTO, Load PCL with W
|
78 |
|
|
NOP ;; No Operation
|
79 |
|
|
|
80 |
|
|
Subroutine RETLW Subroutine + 1 ;; Test RETLW, return 0x0E in W
|
81 |
|
|
|
82 |
|
|
MOVLW MemStart ;; starting RAM + 1
|
83 |
|
|
MOVWF FSR ;; indirect address register (FSR)
|
84 |
|
|
;-------------------------------------------------------------------------------
|
85 |
|
|
MOVLW Count ;; internal RAM count - 1
|
86 |
|
|
MOVWF Cntr ;; loop counter
|
87 |
|
|
MOVLW 0xAA ;; zero working register
|
88 |
|
|
;
|
89 |
|
|
Loop1 MOVWF INDF ;; clear RAM indirectly
|
90 |
|
|
INCF FSR,1 ;; increment FSR
|
91 |
|
|
DECFSZ Cntr,1 ;; decrement loop counter
|
92 |
|
|
GOTO Loop1 ;; loop until loop counter == 0
|
93 |
|
|
;
|
94 |
|
|
MOVLW MemStart ;; starting RAM + 1
|
95 |
|
|
MOVWF FSR ;; reload FSR
|
96 |
|
|
MOVLW (256 - Count) ;; set loop counter to 256 - 23
|
97 |
|
|
MOVWF Cntr
|
98 |
|
|
;
|
99 |
|
|
Loop2 COMF INDF,1 ;; Complement Memory Pattern from Loop 1
|
100 |
|
|
INCF FSR,1 ;; Increment Indirect Pointer to Memory
|
101 |
|
|
INCFSZ Cntr,1 ;; increment counter loop until 0
|
102 |
|
|
GOTO Loop2 ;; loop
|
103 |
|
|
;
|
104 |
|
|
CLRF Cntr ;; Clear Memory Location 0x08
|
105 |
|
|
;-------------------------------------------------------------------------------
|
106 |
|
|
DECF Cntr,1 ;; Decrement Memory Location 0x08
|
107 |
|
|
ADDWF Cntr,0 ;; Add Memory Location 0x08 to W, Store in W
|
108 |
|
|
SUBWF Cntr,1 ;; Subtract Memory Location 0x08
|
109 |
|
|
RLF Cntr,1 ;; Rotate Memory Location 0x08
|
110 |
|
|
RRF Cntr,1 ;; Rotate Memory Location
|
111 |
|
|
MOVLW 0x69 ;; Load W with test pattern: W <= 0x69
|
112 |
|
|
MOVWF (MemStart - 1) ;; Initialize Memory with test pattern
|
113 |
|
|
SWAPF Cntr,1 ;; Test SWAPF: (0x08) <= 0x96
|
114 |
|
|
IORWF Cntr,1 ;; Test IORWF: (0x08) <= 0x69 | 0x96
|
115 |
|
|
ANDWF Cntr,1 ;; Test ANDWF: (0x08) <= 0x69 & 0xFF
|
116 |
|
|
XORWF Cntr,1 ;; Test XORWF: (0x08) <= 0x69 ^ 0x69
|
117 |
|
|
COMF Cntr ;; Test COMF: (0x08) <= ~0x00
|
118 |
|
|
IORLW 0x96 ;; Test IORLW: W <= 0x69 | 0x96
|
119 |
|
|
ANDLW 0x69 ;; Test ANDLW: W <= 0xFF & 0x69
|
120 |
|
|
XORLW 0x69 ;; Test XORLW: W <= 0x69 ^ 0x69
|
121 |
|
|
; SLEEP ;; Stop Execution of test program: HALT
|
122 |
|
|
GOTO PortTst
|
123 |
|
|
;-------------------------------------------------------------------------------
|
124 |
|
|
SleepRestart CLRWDT ;; Detected SLEEP restart, Clr WDT to reset PD
|
125 |
|
|
BTFSC Status,3 ;; Check STATUS.3, skip if ~PD clear
|
126 |
|
|
GOTO Continue ;; ~PD is set, CLRWDT cleared PD
|
127 |
|
|
ErrorLoop GOTO ErrorLoop ;; ERROR: hold here on error
|
128 |
|
|
;
|
129 |
|
|
Continue MOVLW 0x10 ;; Load FSR with non-banked RAM address
|
130 |
|
|
MOVWF FSR ;; Initialize FSR for Bit Processor Tests
|
131 |
|
|
CLRF INDF ;; Clear non-banked RAM location using INDF
|
132 |
|
|
BSF Status,0 ;; Set STATUS.0 (C) bit
|
133 |
|
|
BCF Status,1 ;; Clear STATUS.1 (DC) bit
|
134 |
|
|
BCF Status,2 ;; Clear STATUS.2 (Z) bit
|
135 |
|
|
MOVF Status,0 ;; Load W with STATUS
|
136 |
|
|
RRF INDF,0 ;; Rotate Right RAM location: C <= 0, W <= 0x80
|
137 |
|
|
RLF INDF,0 ;; Rotate Left RAM location: C <= 0, (INDF) <= 0x00
|
138 |
|
|
MOVWF INDF ;; Write result back to RAM: (INDF) <= 0x80
|
139 |
|
|
MOVWF Tmr0 ;; Write to TMR0, clear Prescaler
|
140 |
|
|
GOTO Start ;; Restart Program
|
141 |
|
|
;-------------------------------------------------------------------------------
|
142 |
|
|
;PortTst
|
143 |
|
|
;
|
144 |
|
|
; MOVLW 0xAA ;; Load W with 0xAA
|
145 |
|
|
; MOVWF PortA ;; WE_PortA
|
146 |
|
|
; MOVWF PortB ;; WE_PortB
|
147 |
|
|
; MOVWF PortC ;; WE_PortC
|
148 |
|
|
; MOVF PortA,0 ;; RE_PortA
|
149 |
|
|
; MOVF PortB,0 ;; RE_PortB
|
150 |
|
|
; MOVF PortC,0 ;; RE_PortC
|
151 |
|
|
; COMF PortA,1 ;; Complement PortA
|
152 |
|
|
; COMF PortB,1 ;; Complement PortB
|
153 |
|
|
; COMF PortC,1 ;; Complement PortC
|
154 |
|
|
; CLRF PortA ;; Clear PortA
|
155 |
|
|
; CLRF PortB ;; Clear PortB
|
156 |
|
|
; CLRF PortC ;; Clear PortC
|
157 |
|
|
; CLRW ;; zero working register
|
158 |
|
|
;
|
159 |
|
|
;
|
160 |
|
|
PortTst DECF 0x0C,1
|
161 |
|
|
MOVF 0x0C,0
|
162 |
|
|
MOVWF PortA
|
163 |
|
|
;
|
164 |
|
|
CALL Delay
|
165 |
|
|
;
|
166 |
|
|
GOTO PortTst
|
167 |
|
|
|
168 |
|
|
;
|
169 |
|
|
; Delay Subroutine
|
170 |
|
|
;
|
171 |
|
|
Delay NOP
|
172 |
|
|
;
|
173 |
|
|
MOVLW 0xEE
|
174 |
|
|
MOVWF 0x0A
|
175 |
|
|
MOVLW 0x01
|
176 |
|
|
MOVWF 0x0B
|
177 |
|
|
;
|
178 |
|
|
DelayLp DECFSZ 0x0A,1 ;; Decrement Delay Low
|
179 |
|
|
GOTO DelayLp
|
180 |
|
|
CLRWDT ;; Tickle WDT
|
181 |
|
|
DECFSZ 0x0B,1 ;; Decrement Delay High
|
182 |
|
|
GOTO DelayLp
|
183 |
|
|
;
|
184 |
|
|
RETLW 0x00
|
185 |
|
|
;-------------------------------------------------------------------------------
|
186 |
|
|
END
|
187 |
|
|
|