; ; ; Copyright (c) 2013 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=16f1705 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 16F1705. ;; 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 int_cm4 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, int_cm4 ;---------------------------------------------------------------------- ; ********************* 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 "p16f1705.xpos = 72" .sim "p16f1705.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" ; CxIN1- .sim "node na3" .sim "attach na3 V2.pin porta1" ; CxIN0- .sim "node na4" .sim "attach na4 porta5 porta3" BANKSEL ANSELA movlw 0x03 movwf ANSELA ; select AN0, AN1 movwf ANSELC ; select AN4, AN5 BANKSEL TRISA movlw 0x0B movwf TRISA movlw 0x03 movwf TRISC ; portc0 (AN4) portc1(AN5) input, portc4 output ; T1 GATE PIN PORTA3 BANKSEL T1GPPS movwf T1GPPS bsf INTCON,GIE ;Global interrupts bsf INTCON,PEIE ;Peripheral interrupts BANKSEL PIE2 bsf PIE2,C1IE ;CM1 interrupts bsf PIE2,C2IE ;CM2 interrupts call test_pin_SPMH_Tog call test_compar call test_tot1 ; can C2 increment TMR1 .assert "'*** PASSED 16F1705 comparator test'" nop goto $-1 ; ; Test Comparator2 gate control of Timer 1 ; test_tot1: BANKSEL FVRCON movlw 0x8c movwf FVRCON ; Comp Vref=4.096 BANKSEL T1CON ; bsf T1GCON,TMR1GE movlw (1<