; ; ; 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 ; . ;; The purpose of this program is to test gpsim's ability to ;; simulate a pic 16F1823. ;; Specifically, basic port operation, eerom, interrupts, ;; a2d, dac, SR latch, capacitor sense, and enhanced instructions list p=16f1823 ; list directive to define processor include ; processor specific variable definitions include ; Grab some useful macros __CONFIG _CONFIG1, _CP_OFF & _WDTE_ON & _FOSC_INTOSC & _PWRTE_ON & _BOREN_OFF & _MCLRE_OFF & _CLKOUTEN_OFF __CONFIG _CONFIG2, _STVREN_ON ; & _WRT_BOOT ;------------------------------------------------------------------------ ; gpsim command .command macro x .direct "C", x endm ;---------------------------------------------------------------------- GPR_DATA UDATA_SHR cmif_cnt RES 1 tmr0_cnt RES 1 tmr1_cnt RES 1 eerom_cnt RES 1 adr_cnt RES 1 data_cnt RES 1 inte_cnt RES 1 iocaf_val RES 1 GLOBAL inte_cnt, iocaf_val ;---------------------------------------------------------------------- ; ********************* 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 .sim "module library libgpsim_modules" ; Use a pullup resistor as a voltage source .sim "module load pullup V1" .sim "V1.resistance = 10000.0" .sim "V1.capacitance = 20e-12" .sim "V1.voltage=1.0" .sim "node n1" .sim "attach n1 porta0 porta3" .sim "node n2" .sim "attach n2 porta1 porta4" .sim "node n3" .sim "attach n3 porta2 porta5" .sim "node n4" .sim "attach n4 portc0 V1.pin" .sim "p16f1823.xpos = 72" .sim "p16f1823.ypos = 72" .sim "V1.xpos = 216" .sim "V1.ypos = 120" ;------------------------------------------------------------------------ ; ; Interrupt Vector ; ;------------------------------------------------------------------------ INT_VECTOR CODE 0x004 ; interrupt vector location ; many of the core registers now saved and restored automatically clrf BSR ; set bank 0 btfsc PIR2,EEIF goto ee_int btfsc INTCON,T0IF goto tmr0_int btfsc INTCON,IOCIF goto inte_int .assert "'***FAILED p16f1823 unexpected interrupt'" nop ; Interrupt from TMR0 tmr0_int incf tmr0_cnt,F bcf INTCON,T0IF goto exit_int ; Interrupt from eerom ee_int incf eerom_cnt,F bcf PIR2,EEIF goto exit_int ; Interrupt from INT pin inte_int incf inte_cnt,F bcf INTCON,GIE ; stop interrupts goto exit_int exit_int: retfie ;---------------------------------------------------------------------- ; ******************* MAIN CODE START LOCATION ****************** ;---------------------------------------------------------------------- MAIN CODE start .assert "p16f1823.frequency == 500000., 'FALIED 16F1823 POR clock 500kHz'" nop BANKSEL OSCCON bsf OSCCON,6 ;set clock to 16 MHz btfss OSCSTAT,HFIOFL goto $-1 .assert "(oscstat & 0x1f) == 0x19, '*** FAILED 16f1823 HFIO bit error'" nop .assert "p16f1823.frequency == 16000000., 'FALIED 16F1823 RC clock 16MHz'" nop call cap_sense BANKSEL FVRCON ; Enable Core Temp, high range, FVR AD 2.048v movlw (1<= 21 && tmr0 < 25), '*** FAILED 16f1823 CPSCON TMR1 Counting'" nop ; set tmr0 for RA4/T0CKI, but CPS not feeding clock BANKSEL OPTION_REG bsf OPTION_REG,TMR0CS BANKSEL TMR0 movlw 0x00 movwf TMR0 ; DAC non-idle output (0.16V) BANKSEL DACCON0 movlw (1< 0x39 && tmr1l < 0x42 && tmr1h == 3,'*** FAILED p16f1823 CPS with 25pF'" nop ; Add 5pF cap period should increase (frequency decrease) by ratio 30/25 .command "V1.capacitance = 25e-12" nop clrf TMR1L clrf TMR1H bcf INTCON,T0IF btfss INTCON,T0IF goto $-1 .assert "tmr1l == 0x00 && tmr1h == 4,'*** FAILED p16f1823 capacitance shift'" nop clrf CPSCON0 clrf T1CON BANKSEL FVRCON clrf FVRCON clrf DACCON0 return test_dac: BANKSEL ADCON1 movlw 0xf0 ;right justify, Frc, Vdd ref movwf ADCON1 BANKSEL TRISC ; bsf TRISC,0 ;Set RC0 to input BANKSEL ANSELC ; bsf ANSELC,0 ;Set RC0 to analog BANKSEL ADCON0 ; movlw (0x1e<<2)|(1<