ADC asm code

This isn't for that PIC, but for the 16f818

Rich (BB code):
;*********************************************************

; EQUATES SECTION

TMR0            EQU         1           ;means TMR0 is file 1.  
STATUS          EQU         3           ;means STATUS is file 3.        
PORTA           EQU         5              ;means PORTA  is file 5.        
PORTB           EQU         6           ;means PORTB is file 6. 
ZEROBIT         EQU         2           ;means ZEROBIT is bit 2.        
ADCON0          EQU         1FH           ;A/D Configuration reg.0
ADCON1          EQU         9FH           ;A/D Configuration reg.1
ADRES           EQU         1EH         ;A/D Result register.
CARRY           EQU         0           ;CARRY IS BIT 0.
TRISA            EQU            85H            ;PORTA Configuration Register
TRISB            EQU            86H            ;PORTB Configuration Register 
OPTION_R         EQU            81H            ;Option Register
OSCCON            EQU            8FH            ;Oscillator control register.
CCPR1L            EQU            15H
CCPR1H            EQU            16H
CCP1CON            EQU            17H
PR2                EQU            92H
T2CON            EQU            12H
;USER FILES ARE BELOW
COUNT           EQU         20H         ;COUNT a register to count events.
COUNTERA        EQU            21H
COUNTERB        EQU            22H               
ADCSTO            EQU            23H    
;*********************************************************

    LIST        P=16F818             ;we are using the 16F818.
    ORG         0                   ;the start address in memory is 0
    GOTO          START               ;goto start!

;*********************************************************
; Configuration Bits

__CONFIG H'3F10'       ;sets INTRC-A6 is port I/O, WDT off, PUT ;on, MCLR tied to VDD A5 is I/O 
;BOD off, LVP disabled, EE protect disabled, ;Flash Program Write disabled, 
;Background Debugger Mode disabled, CCP ;function on B2, Code Protection disabled.

;*****************************************************

;SUBROUTINE SECTION.

;PIC Time Delay = 0.00171300 s with Osc = 4000000 Hz
STARTB    movlw    D'3'
        movwf    COUNTERB
        movlw    D'56'
        movwf    COUNTERA
STTLOOP    decfsz    COUNTERA,1
        goto    STTLOOP
        decfsz    COUNTERB,1
        goto    STTLOOP
        RETLW    0

;PIC Time Delay = 0.00131800 s with Osc = 4000000 Hz (50 38KHz cycles)
TLOG1    movlw    .2
        movwf    COUNTERB
        movlw    .181
        movwf    COUNTERA
L1LOOP    decfsz    COUNTERA,1
        goto    L1LOOP
        decfsz    COUNTERB,1
        goto    L1LOOP
        RETLW    0


;PIC Time Delay = 0.00079000 s with Osc = 4000000 Hz
TLOG0    movlw    D'2'
        movwf    COUNTERB
        movlw    D'5'
        movwf    COUNTERA
L0LOOP    decfsz    COUNTERA,1
        goto    L0LOOP
        decfsz    COUNTERB,1
        goto    L0LOOP
        RETLW    0

;PIC Time Delay = 0.00210600 s with Osc = 4000000 Hz (80 38KHz cycles)
TOFF    movlw    .3
        movwf    COUNTERB
        movlw    .187
        movwf    COUNTERA
OFFLOOP decfsz    COUNTERA,1
        goto    OFFLOOP
        decfsz    COUNTERB,1
        goto    OFFLOOP
        RETLW    0

P38KON    MOVLW    B'00001100'            ;SET PWM
        MOVWF    CCPR1L                
        BSF        CCP1CON,5
        BSF        CCP1CON,4
        RETLW    0
    
P38KOFF    CLRF    CCPR1L                ;set PWM to zero
        BCF        CCP1CON,5
        BCF        CCP1CON,4
        RETLW    0

STRTBIT    CALL    P38KON
        CALL    STARTB
        CALL    P38KOFF
        CALL    TOFF
        RETLW    0

        ;Transmit a LOGIC 1
TRANS1    CALL    P38KON
        CALL    TLOG1                ;CALL A 1.31ms delay for logic 1 transmission
        CALL    P38KOFF
        CALL    TOFF                ;CALL A 2.106ms delay for a space 
        RETLW    0

        ;Tramsit a LOGIC 0
TRANS0    CALL    P38KON
        CALL    TLOG0
        CALL    P38KOFF
        CALL    TOFF
        RETLW    0

;*********************************************************

;Configuration Section

START      BSF     STATUS,5            ;Turns to Bank1.

        MOVLW   B'11111111'         ;8 bits of PORTA are I/P
        MOVWF    TRISA

        MOVLW      B'00001111'         ;AN0 IS ANALOG, AN1 IS DIGITAL, AN2 VREF+,AN3 VREF-,AN4 DIGITAL
        MOVWF    ADCON1
          
        MOVLW   B'00000000'                     
        MOVWF    TRISB               ;PORTB is OUTPUT

        MOVLW   B'01100000'                     
        MOVWF    OSCCON               ;oscillator 4MHz

        MOVLW   B'00000111'         ;Prescaler is /256
        MOVWF    OPTION_R            ;TIMER is 1/32 secs.

        MOVLW    B'00011001'            ;SET UP PWM PERIOD
        MOVWF    PR2

        BCF     STATUS,5            ;Return to Bank0.

        MOVLW    B'00000100'            ;PRESCALE VALUE OF 1:1, TURN ON TMR2
        MOVWF    T2CON                

        MOVLW    B'00111100'
        MOVWF    CCP1CON

        MOVLW    B'00001100'
        MOVWF    CCPR1L        

        ;NEED TO SEE CONFIGURATION FOR WHAT PIN IS PWM O/P

        BSF        ADCON0,0            ;Turn OFF A/D

        CLRF        PORTA           ;Clears PortA.
        CLRF        PORTB           ;Clears PortB.

;*********************************************************
;Program starts now.


BEGIN    BTFSC    PORTA,1        ;was lazy and didnt debounce here
        GOTO    BEGIN
        
TEST    BSF        ADCON0,2      ;Take measurement, set GO/DONE
WAIT    BTFSC    ADCON0,2    ;Wait until GO/DONE is clear
        GOTO    WAIT

,,,,

,,,,

,,,,
more
,,,,,,
code,,,,,,,,

end
 
Top