list p=16c71 include include __CONFIG _WDT_OFF ;; The purpose of this program is to test gpsim's ability to simulate a pic 16c71. ;; Specifically, the a/d converter is tested. errorlevel -302 ; Printf Command .command macro x .direct "C", x endm ;---------------------------------------------------------------------- ;---------------------------------------------------------------------- GPR_DATA UDATA 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 ;---------------------------------------------------------------------- ; ********************* 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 ;; ;; Interrupt ;; movwf w_temp swapf STATUS,W movwf status_temp bcf STATUS,RP0 ;adcon0 is in bank 0 btfsc INTCON,ADIE btfsc ADCON0,ADIF goto a2dint .assert "\"p16c71 FAIL unexpected interrupt\"" nop ;; An A/D interrupt has occurred a2dint: bsf t1,0 ;Set a flag to indicate we got the int. bcf ADCON0,ADIF ;Clear the a/d interrupt swapf status_temp,w movwf STATUS swapf w_temp,F swapf w_temp,W retfie ;---------------------------------------------------------------------- ; ******************* MAIN CODE START LOCATION ****************** ;---------------------------------------------------------------------- MAIN CODE start: .sim "module library libgpsim_modules" ; Use a pullup resistor as a voltage source .sim "module load pullup V1" .sim "V1.resistance = 100.0" .sim "module load pullup V2" .sim "V2.voltage=2.0" .sim "V2.resistance = 100.0" .sim "node na0" .sim "attach na0 V1.pin porta0" .sim "node na1" .sim "attach na1 V2.pin porta3" ;; Let's use the ADC's interrupt clrf INTCON #define FAST_CONVERSION ((1<