; * ; Filename: L_mtr.asm * ; Date: * ; File Version: Log Scale * ; * ; Author: jr7dut * ; Company: * ; * ; * ;********************************************************************** ; * ; Files Required: P16F818.INC * ; * ;********************************************************************** ; * ; Notes: * ; * ;********************************************************************** list p=16f818 ; list directive to define processor #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _DEBUG_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See data sheet for additional information on configuration word settings. ;***** VARIABLE DEFINITIONS w_temp EQU 0x07E ; variable used for context saving status_temp EQU 0x07F ; variable used for context saving nAcq EQU 0x020 ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt ;================================================================================ main clrf PORTA clrf PORTB ; INTOSC set bcf STATUS,RP1 bsf STATUS,RP0 ;Select Bank1 movlw b'01110000' ;8MHz clock movwf OSCCON ;Initialize TMR0 ;TMR0 for abt 0.125*4*256us=0.128ms (abt 0.1ms) timer movlw b'11010111' ;Set OPTION_REG ; RBPU Pull up Disable=1 bit7 ; INTEDG inc or dec...no concern bit6 ; TMR0 Clock source 0 = Internal Clock bit5 ; TMR0 edge inc or dec...no concern bit4 ; PSA=0 Prescaler to TMR0 bit3 ; PS2-0=1,1,1 Prescaler 1:256 bit2-0 movwf OPTION_REG clrf TRISB ; Set PORTB to output bcf TRISA,6 ; Set PORTA<6,7> to output bcf TRISA,7 ; Initialize AD converter movlw b'10001110' ; movwf ADCON1 ; ADCON1 ; bit<7>=1 ADRESH2bits/ADRESL8bits (Right justified) ; bit<6>=0 Tad=2,8or32*Fosc ; bit<5,4> vacant ; bit<3,0>=<1110> ; RA0 to Analog Input ; RA1,RA2,RA3,RA4 to Digital Input ; Vref+:Vdd, Vref-:Vss bcf STATUS,RP0 ; select Bank0 ;Initialize TMR1 ; TMR1 for AD conversion interval (abt 20ms) clrf T1CON ; T1CON ; bit<7,6> vacant ; bit<5,4>=<0,0> Set Prescalor 1/1 ; bit<3>=0 Oscrator shut-off (T1OSCEN) ; bit<2>=0 ignored where TMRCS=0 (!T1SYNC) ; bit<1>=0 Select Internal clock as clock source (TMRCS) ; bit<0>=0 Stop TMR1 (TMR1ON) movlw b'10000001' ; movwf ADCON0 ; ADCON0 ; bit<7,6>=<0,1> Set Conversion clock to Fosc/32 (4us) ; bit<5,3>=<0,0,0> Slect channel '0' ; bit<2>=0 AD-conversion Stop "GO" ; bit<1> vacant ; bit<0>=0 AD-module Stop ; bsf ADCON0,ADON ; wait for acquisition time loop call wAcq ; AD conversion bsf ADCON0,GO ; Start AD conversion w_cnv btfsc ADCON0,GO goto w_cnv ; bcf ADCON0,ADON ; LED display b9 btfss ADRESH,1 goto b8 bsf PORTA,7 bsf PORTA,6 movlw b'11111111' movwf PORTB goto b_out b8 btfss ADRESH,0 goto b7 bcf PORTA,7 bsf PORTA,6 movlw b'11111111' movwf PORTB goto b_out b7 bsf STATUS,RP0 ; Select Bank1 btfss ADRESL,7 goto b6 bcf STATUS,RP0 ; Select Bank0 bcf PORTA,7 bcf PORTA,6 movlw b'11111111' movwf PORTB goto b_out b6 btfss ADRESL,6 ; Still in Bank1 goto b5 bcf STATUS,RP0 ; Select Bank0 bcf PORTA,7 bcf PORTA,6 movlw b'01111111' movwf PORTB goto b_out b5 btfss ADRESL,5 goto b4 bcf STATUS,RP0 ; Select Bank0 bcf PORTA,7 bcf PORTA,6 movlw b'00111111' movwf PORTB goto b_out b4 btfss ADRESL,4 goto b3 bcf STATUS,RP0 ; Select Bank0 bcf PORTA,7 bcf PORTA,6 movlw b'00011111' movwf PORTB goto b_out b3 btfss ADRESL,3 goto b2 bcf STATUS,RP0 ; Select Bank0 bcf PORTA,7 bcf PORTA,6 movlw b'00001111' movwf PORTB goto b_out b2 btfss ADRESL,2 goto b1 bcf STATUS,RP0 ; Select Bank0 bcf PORTA,7 bcf PORTA,6 movlw b'00000111' movwf PORTB goto b_out b1 btfss ADRESL,1 goto b0 bcf STATUS,RP0 ; Select Bank0 bcf PORTA,7 bcf PORTA,6 movlw b'00000011' movwf PORTB goto b_out b0 btfss ADRESL,0 goto b_null bcf STATUS,RP0 ; Select Bank0 bcf PORTA,7 bcf PORTA,6 movlw b'00000001' movwf PORTB goto b_out b_null bcf STATUS,RP0 ; Select Bank0 bcf PORTA,7 bcf PORTA,6 clrf PORTB b_out ; Disp finished ; wait next conversion clrf TMR1L movlw d'100' movwf TMR1H bcf PIR1,TMR1IF bsf T1CON,TMR1ON w_int btfss PIR1,TMR1IF ; Wait interval goto w_int bcf T1CON,TMR1ON goto loop ;;;;;Subroutine;;;;;; ; for AD con********************************************************************************************* ; wait acquitition time wAcq movlw d'30' ; 0.4*2*30=24micro_sec(about) movwf nAcq w_lp decfsz nAcq,F goto w_lp return END ; directive 'end of program'