1
2   ;;  Resistor test
3   ;;
4   ;;  The purpose of this program is to verify that gpsim's
5   ;; resistor modules function.
6   ;;
7   ;;
8   ;;
9
10
11	list    p=16f873                ; list directive to define processor
12	include <p16f873.inc>           ; processor specific variable definitions
13        include <coff.inc>              ; Grab some useful macros
14
15        __CONFIG (_CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _HS_OSC & _WRT_ENABLE_ON & _LVP_OFF & _CPD_OFF)
16
17        errorlevel -302
18
19;----------------------------------------------------------------------
20;   ********************* RESET VECTOR LOCATION  ********************
21;----------------------------------------------------------------------
22RESET_VECTOR  CODE    0x000              ; processor reset vector
23
24        movlw  high  start              ; load upper byte of 'start' label
25        movwf  PCLATH                   ; initialize PCLATH
26        goto   start                    ; go to beginning of program
27
28INT_VECTOR   CODE    0x004               ; interrupt vector location
29	nop
30
31;----------------------------------------------------------------------
32;   ******************* MAIN CODE START LOCATION  ******************
33;----------------------------------------------------------------------
34MAIN    CODE
35start
36
37   .sim "module library libgpsim_modules"
38   .sim "module load pu pu1"
39   .sim "pu1.xpos = 220."
40   .sim "pu1.ypos = 40."
41   .sim "module load pd pd1"
42   .sim "pd1.xpos = 72."
43   .sim "pd1.ypos = 300."
44;   .sim "pu1.resistance=1000."
45   .sim "pd1.resistance=3900."
46   .sim "node A"
47   .sim "attach A porta0 porta1 pu1.pin"
48   .sim "node B"
49   .sim "attach B porta2 portb0 pd1.pin"
50;
51;	the following test for a core dump bug
52;
53   .sim "node C"
54   .sim "attach C pd1"
55
56
57        nop
58  ; Turn off the A2D converter and make PORTA's I/O's digital:
59
60        bsf     STATUS,RP0
61	movlw	(1<<PCFG1) | (1<<PCFG2)
62	movwf	ADCON1
63
64        bcf     STATUS,RP0
65;
66;	pull-up should set input ports high
67    .assert "(porta&1) == 1, '*** FAILED - Pullup doesn't give high state'"
68	nop
69;
70
71        bsf     STATUS,RP0
72	bcf	OPTION_REG,NOT_RBPU	; turn on portb pullups
73;
74;	 the pull-down resistor should pull down the weak B port pull-up
75    .assert "(portb&1) == 0, '*** FAILED weak pull-up vs. pull down'"
76	nop
77;
78        movlw   0x81		;Port A 0 in others out
79	movwf	TRISA
80	bcf	OPTION_REG,NOT_RBPU	; turn on portb pullups
81
82        bcf     STATUS,RP0
83
84
85	clrf	PORTA
86;
87;	low output porta1 should drive pull-up resistor low
88    .assert "(porta&3) == 0, '*** FAILED low output driving pull-up'"
89	nop
90;
91
92;
93;	low output porta2 should drive portb0 and pull-down resistor low
94    .assert "(portb&1) == 0, '*** FAILED low output propagation'"
95	nop
96;
97
98	bsf	PORTA,1
99;
100;	high output porta1 high should drive porta0 and pull-up high
101    .assert "(porta&1) == 1, '*** FAILED high output with pull-up'"
102	nop
103;
104	bsf	PORTA,2
105;
106;	high output porta2 should drive portb0 and pull-down resistor high
107    .assert "(portb&1) == 1, '*** FAILED high output driving pull-down'"
108	nop
109;
110
111	bcf	PORTA,1
112;
113;	low output porta1 should drive porta0 and pull-up low
114    .assert "(porta&3) == 0, '*** FAILED low output driving pull-up'"
115	nop
116;
117	bcf	PORTA,2
118;
119;	low output porta2 should drive portb0 and pull-down resistor low
120    .assert "(portb&1) == 0, '*** FAILED low output propagation'"
121;
122	nop
123;	bit operation on porta should not change porta1
124    .assert "(porta&3) == 0,   '*** FAILED - PIC output drive too weak'"
125
126	nop
127
128
129passed:
130
131done:
132  ; If no expression is specified, then break unconditionally
133
134#define UNRELEASED_GPASM
135
136 ifdef UNRELEASED_GPASM
137  .assert  "'*** PASSED Resistor Module test'"
138 else
139  .assert  ""
140 endif
141        goto    done
142
143
144        nop
145  end
146
147end
148