; ; ; Copyright (c) 2015 Roy Rankin ; ; This file is part of the gpsim regression tests ; ; This library is free software; you can redistribute it and/or ; modify it under the terms of the GNU Lesser General Public ; License as published by the Free Software Foundation; either ; version 2.1 of the License, or (at your option) any later version. ; ; This library is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ; Lesser General Public License for more details. ; ; You should have received a copy of the GNU Lesser General Public ; License along with this library; if not, see ; . list p=16f1823 include include __CONFIG _CONFIG1, _CP_OFF & _WDTE_OFF & _FOSC_INTOSC & _LVP_OFF & _MCLRE_OFF __CONFIG _CONFIG2, _PLLEN_OFF ;; The purpose of this program is to test gpsim's ability to ;; simulate a pic 16F1823. ;; Specifically, the comparator and gate function of Tmr1 is tested. errorlevel -302 ; Printf Command .command macro x .direct "C", x endm ;---------------------------------------------------------------------- ;---------------------------------------------------------------------- GPR_DATA UDATA_SHR int_cm1 RES 1 int_cm2 RES 1 x RES 1 t1 RES 1 t2 RES 1 avg_lo RES 1 avg_hi RES 1 w_temp RES 1 status_temp RES 1 GLOBAL int_cm1, int_cm2 ;---------------------------------------------------------------------- ; ********************* RESET VECTOR LOCATION ******************** ;---------------------------------------------------------------------- RESET_VECTOR CODE 0x000 ; processor reset vector movlp high start ; load upper byte of 'start' label goto start ; go to beginning of program ;; ;; Interrupt ;; INTERRUPT_VECTOR CODE 0X004 goto interrupt ;---------------------------------------------------------------------- ; ******************* MAIN CODE START LOCATION ****************** ;---------------------------------------------------------------------- MAIN CODE start: .sim "p16f1823.xpos = 72" .sim "p16f1823.ypos = 72" .sim "module library libgpsim_modules" ; Use a pullup resistor as a voltage source .sim "module load pullup V1" .sim "V1.resistance = 100.0" .sim "V1.xpos = 240" .sim "V1.ypos = 72" .sim "V1.voltage = 2.0" .sim "module load pullup V2" .sim "V2.resistance = 100.0" .sim "V2.xpos = 84" .sim "V2.ypos = 24" .sim "V2.voltage = 2.5" .sim "module load pullup V3" .sim "V3.resistance = 100.0" .sim "V3.xpos = 240" .sim "V3.ypos = 120" .sim "V3.voltage = 4.5" .sim "node na0" .sim "attach na0 V3.pin porta0 portc0" ; C1IN+, C2IN+ .sim "node na1" .sim "attach na1 V1.pin portc1" ; C12IN1- .sim "node na3" .sim "attach na3 V2.pin porta1" ; C12IN0- movlw 0x03 BANKSEL ANSELA clrf ANSELA clrf ANSELC movwf ANSELA ; select AN0, AN1 movwf ANSELC ; select AN4, AN5 BANKSEL TRISA movwf TRISA ; movlw 0x02 movwf TRISC ; portc0 (AN4) portc1(AN5) input, portc4 output bsf INTCON,GIE ;Global interrupts bsf INTCON,PEIE ;Peripheral interrupts BANKSEL PIE2 bsf PIE2,C1IE ;CM1 interrupts bsf PIE2,C2IE ;CM2 interrupts call test_compar call test_tot1 ; can C2 increment TMR1 call test_sr ; can CM control SR latch .assert "'*** PASSED 16F1823 comparator test'" nop goto $-1 ; ; Test Comparator driving SR latch ; Assumes called with C1OUT = C2OUT = 0 and ; C1POL = 0, C2POL = 1 ; test_sr: BANKSEL SRCON0 ; turn on Q output pin movlw (1<