;; 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 ; processor specific variable definitions include ; 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<>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