1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
;; Logic test
;;
;; The purpose of this program is to verify that gpsim's
;; Logic modules function.
;;
;;
;;
list p=16f873 ; list directive to define processor
include <p16f873.inc> ; processor specific variable definitions
include <coff.inc> ; Grab some useful macros
__CONFIG (_CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _HS_OSC & _WRT_ENABLE_ON & _LVP_OFF & _CPD_OFF)
errorlevel -302
;----------------------------------------------------------------------
;----------------------------------------------------------------------
GPR_DATA UDATA
var1 RES 1
var2 RES 1
var3 RES 1
failures RES 1
GLOBAL var1,var2,var3,failures
GLOBAL done
;----------------------------------------------------------------------
; ********************* RESET VECTOR LOCATION ********************
;----------------------------------------------------------------------
RESET_VECTOR CODE 0x000 ; processor reset vector
movlw high start ; load upper byte of 'start' label
movwf PCLATH ; initialize PCLATH
goto start ; go to beginning of program
;----------------------------------------------------------------------
; ******************* MAIN CODE START LOCATION ******************
;----------------------------------------------------------------------
MAIN CODE
start
clrf var1
clrf var2
clrf var3
bsf STATUS,RP0
clrf TRISA^0x80 ;Port A is an output
clrf TRISB^0x80 ;Port B is an output
movlw 0xff
movwf TRISC^0x80 ;Port C is an input
; Turn off the A2D converter and make PORTA's I/O's digital:
movlw (1<<PCFG1) | (1<<PCFG2)
movwf ADCON1
bcf STATUS,RP0
; Don't let the simulation run forever.
.sim "break c 0x10000"
; assume we failed
movlw 1
movwf failures
; Create a script to define the schematic
; Note, the .sim directives are only "executed" once.
; First, instantiate the gates:
.sim "module library libgpsim_modules"
.sim "module load xor2 U1_xor"
.sim "module load xor2 U2_xor"
.sim "module load and2 U3_and"
.sim "module load and2 U4_and"
.sim "module load or2 U5_or"
.sim "module load or2 U6_or"
.sim "module load not U7_not"
.sim "module load not U8_not"
.sim "module load not U9_not"
; Or Gate check.
; U5_or
; porta0 ---)-\ U6_or
; )+ )----)-\
; porta1 ---)-/ )+ )---+
; +--)-/ |
; porta2 --------+ |
; |
; portc0 ------------------+
;
.sim "node na0"
.sim "attach na0 U5_or.in0 porta0"
.sim "node na1"
.sim "attach na1 U5_or.in1 porta1"
.sim "node n5_6"
.sim "attach n5_6 U5_or.out U6_or.in0"
.sim "node na2"
.sim "attach na2 U6_or.in1 porta2"
.sim "node nc0"
.sim "attach nc0 U6_or.out portc0"
.sim "scope.ch0 = \"porta0\""
.sim "scope.ch1 = \"porta1\""
.sim "scope.ch2 = \"porta2\""
.sim "scope.ch3 = \"portc0\""
clrf PORTA
clrf PORTB
.assert "(portc&7) == 0"
nop ;for the assert
; Loop through the 8 states:
L_OrCheck:
incf PORTA,F
.assert "(portc & 1) == ( ((porta>>2) | (porta>>1) | porta) & 1)"
btfss PORTA,3
goto L_OrCheck
; AND Gate check.
; U3_or
; portb3 ---|-+ U4_or
; |& )----|-+
; portb4 ---|-+ |& )---+
; +--|-+ |
; portb5 --------+ |
; |
; portc1 ------------------+
;
.sim "node nb3"
.sim "attach nb3 U3_and.in0 portb3"
.sim "node nb4"
.sim "attach nb4 U3_and.in1 portb4"
.sim "node n3_4"
.sim "attach n3_4 U3_and.out U4_and.in0"
.sim "node nb5"
.sim "attach nb5 U4_and.in1 portb5"
.sim "node nc1"
.sim "attach nc1 U4_and.out portc1"
; Loop through the 8 states:
L_AndCheck
movlw 1<<3
addwf PORTB,F
.assert "((portc>>1) & 1) == ( ((portb>>5) & (portb>>4) & (portb>>3)) & 1)"
movf PORTB,W
andlw b'111000'
skpz
goto L_AndCheck
; xor Gate check.
; U1_xor
; portb0 ---))-\ U2_xor
; ))^ )---))-\
; portb1 ---))-/ ))^ )--+
; +--))-/ |
; portb2 --------+ |
; |
; portc2 ------------------+
;
.sim "node nb0"
.sim "attach nb0 U1_xor.in0 portb0"
.sim "node nb1"
.sim "attach nb1 U1_xor.in1 portb1"
.sim "node n1_2"
.sim "attach n1_2 U1_xor.out U2_xor.in0"
.sim "node nb2"
.sim "attach nb2 U2_xor.in1 portb2"
.sim "node nc2"
.sim "attach nc2 U2_xor.out portc2"
; Loop through the 8 states:
L_XorCheck:
incf PORTB,F
.assert "((portc>>2) & 1) == ( ((portb>>2) ^ (portb>>1) ^ portb) & 1)"
btfss PORTB,3
goto L_XorCheck
; Not Gate test
; U7_not
; |\
; portb6 ---| O-----+
; |/ |
; portc3 -----------+
;
; U8_not U9_not
; |\ |\
; portb7 ---| O-----| O---+
; |/ |/ |
; portc4 -----------------+
;
.sim "node nb6"
.sim "attach nb6 U7_not.in0 portb6"
.sim "node nc3"
.sim "attach nc3 U7_not.out portc3"
bsf PORTB, 6 ;(don't need to do this...)
.assert "((portc>>3) & 1) == ( ((portb>>6) & 1)^1)"
bcf PORTB, 6
.assert "((portc>>3) & 1) == ( ((portb>>6) & 1)^1)"
nop
.sim "node nb7"
.sim "attach nb7 U8_not.in0 portb7"
.sim "node n7_8"
.sim "attach n7_8 U8_not.out U9_not.in0"
.sim "node nc4"
.sim "attach nc4 U9_not.out portc4"
bsf PORTB, 7 ;(don't need to do this...)
.assert "((portc>>4) & 1) == ( ((portb>>7) & 1))"
bcf PORTB, 7
.assert "((portc>>4) & 1) == ( ((portb>>7) & 1))"
nop
passed:
clrf failures
done:
; If no expression is specified, then break unconditionally
#define UNRELEASED_GPASM
ifdef UNRELEASED_GPASM
.assert "\"*** PASSED Logic Module test\""
else
.assert ""
endif
goto done
nop
end
end
|