Timer0 interrupt 16F877A [Assembly]

Thread Starter

azhari24

Joined Dec 5, 2011
7
hey friend, I need some help. I have program in PIC16F877A for use 3 channel ADC to send parallel. I use TMR0 interrupt for send data. I setting TMR0 active every 8ms, prescaler 1:32. but when program run interrupt active after channel 1 ADC start conversion. can you helpme?

This is my program.
Rich (BB code):
    ORG     0000H
    GOTO    MULAI            ; JUMP TO MAIN PROGRAM        
    ORG        0004H            ; INTERRUPT VECTOR AREA
    GOTO    INT_SERVICE

MULAI:                        ; BEGINNING OF THE MAIN PROGRAM
    BSF        STATUS,5        ; INITIALIZATION PORT B
    MOVLW    B'11111100'        ; SET THE FIRST TWO BITS OF PORT C AS OUTPUT
    MOVWF    TRISC
    BSF        TRISB,0            ; SET THE BIT 0 OF PORT B AS INPUT
    BCF        OPTION_REG,INTEDG ; SET RISING EDGE
    BCF        INTCON,INTF        ; RESET INTERUPT FLAG OF INT
    BSF     INTCON,INTE        ; SET IEBIT OF INT
    BSF     INTCON,GIE        ; SET GLOBAT INT ENABLE

; INITIALIZATION OF TIMER0
    MOVLW    0X04
    MOVWF    OPTION_REG        ; T0 PRESCALE, TIMER, 1:32

; initialization of ADC
    MOVLW    0XC2    ; only first channel is being activated
            ; IT WAS 8E FOR CH.0
    MOVWF    ADCON1

    MOVLW     B'00001010' ; set port RA0 and RA1 as input
    MOVWF     TRISA
    BCF        STATUS,5        ; SET BANK 0
    BCF        PORTC,0
    BCF        PORTC,1

    MOVLW    D'6'                ;SET COUNTFOR 6
    MOVWF    TMR0            
    MOVLW    0xA0                ; ENABLE T0 AND GLOBAL INTS
    MOVWF    INTCON    
    CLRF    FLAGS

; set sent port
    CALL    SET_PORT_BE
    CALL    SET_PORTD_IN

    BSF        PORTE,1            ; set the rd and wr control signal inactive
    BCF        PORTE,0
    
    MOVLW    01H                ; set the first control byte 1;
    MOVWF    RDorWR

MAINLOOP:
;------------------------------------------------------------------------------------------------------
; adc part 1
    MOVLW    0x81    ; f osc/32, adon, not started yet
    MOVWF    ADCON0

; operate the ADC first
MAIN2:    
    BCF        PIR1,ADIF
    BSF        ADCON0,GO
    CLRWDT
TEST:
    BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
                    ;BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    GOTO    TEST

    MOVFW    ADRESH
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAout3

    BSF        STATUS,5    ; bank 1
    MOVFW    ADRESL
    BCF        STATUS,5    ; bank 0
    MOVWF    TEMPE
    
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAout

    RRF        TEMPE,F
    RRF        TEMPE,F
    RRF        TEMPE,F
    RRF        TEMPE,F
    MOVFW    TEMPE
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAout2

;-------------------------------------------------------------------------------------------------------    
; adc part 2
    MOVLW    0x89    ; f osc/32, adon, not started yet
    MOVWF    ADCON0

; operate the ADC SECOUND
    BCF        PIR1,ADIF
    BSF        ADCON0,GO
    CLRWDT
TEST1:
    BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
                    ;BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    GOTO    TEST1

    MOVFW    ADRESH
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutC

    BSF        STATUS,5    ; bank 1
    MOVFW    ADRESL
    BCF        STATUS,5    ; bank 0
    MOVWF    TEMPA
    
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutA

  RRF        TEMPA,F
    RRF        TEMPA,F
   RRF        TEMPA,F
    RRF        TEMPA,F
    MOVFW    TEMPA
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutB
;-------------------------------------------------------------------------------------------------------    
; adc part 2
    MOVLW    0x91    ; f osc/32, adon, not started yet
    MOVWF    ADCON0

; operate the ADC SECOUND
    BCF        PIR1,ADIF
    BSF        ADCON0,GO
    CLRWDT
TEST2:
    BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
                    ;BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    GOTO    TEST2

    MOVFW    ADRESH
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutZ

    BSF        STATUS,5    ; bank 1
    MOVFW    ADRESL
    BCF        STATUS,5    ; bank 0
    MOVWF    TEMPB
    
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutX

  RRF        TEMPB,F
    RRF        TEMPB,F
   RRF        TEMPB,F
    RRF        TEMPB,F
    MOVFW    TEMPB
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutY

; SENDING THE DATA TO USB MODULE
;--------------------------------------------------------------------------------------------------------------------
;CHANNEL 1
    CALL    SEND_DATA_CH1      ;SEND DATA
;-----------------------------------------------------------------------------------------------------------------------
;CHANNEL 2
    CALL    SEND_DATA_CH2      ;SEND DATA
;-----------------------------------------------------------------------------------------------------------------------
;CHANNEL 3
    CALL    SEND_DATA_CH3      ;SEND DATA

    MOVWF    RDorWR

    GOTO    MAINLOOP




INT_SERVICE:
    MOVWF    W_TEMP        ; SAVE  W AND STATUS REGISTERS
    SWAPF    STATUS,W
    MOVWF    STATUS_T

;    BSF        PORTC,0        ; AS AN INDICATOR OF PROCESS
;    BCF        PORTC,0

    MOVLW    D'6'            ; RESET COUNT FOR 6
    MOVWF    TMR0        
        BCF        INTCON,T0IF        ; RESET T0 INT FLAGS
    BSF        FLAGS,0            ; SET USER FLAG; INT OCCURS

    ;CALL    SEND_USB
    MOVLW    00H
    MOVWF    RDorWR

isr_end
    BCF        INTCON,INTF
    SWAPF    STATUS_T,W    ; RESTORE W AND STATUS REGISTERS
    MOVWF    STATUS
    SWAPF    W_TEMP,F
    SWAPF    W_TEMP,W

    RETFIE
thank you....
 

Markd77

Joined Sep 7, 2009
2,806
I can't see anything obvious, can we see the variable declarations and the subroutines please?
eg
SET_PORT_BE
SET_PORTD_IN
GET_CHAR_CODE
Also these are easier to check if they are written in the binary form.
MOVLW 0xA0 ; ENABLE T0 AND GLOBAL INTS
MOVWF INTCON
There's also an earlier part where you change individual bits of INTCON which is unnecessary.
 

joeyd999

Joined Jun 6, 2011
4,268
I don't have time to dig through all your code, but here is a suggestion:

Don't preform the actual data transmission during the interrupt. Instead, use a bit in your FLAGS register to signal the main program that it is time to send data.

Even better, I would do this:

1. use tmr0 interrupt to trigger the a/d

2. use a/d interrupt to capture converted values and update MUX in round-robin fasion. Set a flag when 3 conversions have been captured (1 for each channel).

3. poll the flag in the main program. When it is set, transmit the data.

And for further improvement, I would operate the A/D even faster than 1/3 the transmission rate, and oversample (average) the channels.
 

Thread Starter

azhari24

Joined Dec 5, 2011
7
I can't see anything obvious, can we see the variable declarations and the subroutines please?
is unnecessary.
I am sorry, I not include all program because manage attachments can't run. I will try to include all my program.

thank you your suggestion..
 

Thread Starter

azhari24

Joined Dec 5, 2011
7
this is all my code

Rich (BB code):
LIST P=16F877A
#INCLUDE "P16F877A.INC"

STATUS        EQU    03H
TRISB        EQU 86H
TRISC        EQU    87H
PORTB        EQU 06H    
PORTC        EQU    07H
COUNT0        EQU    0CH    
COUNT1        EQU    0DH    
READ        EQU 1H
WRITE        EQU 0H
TXE            EQU 4H
RXF         EQU 5H
W_TEMP        EQU    0X70
STATUS_T    EQU    0X71
FLAGS        EQU    0X20

    __CONFIG 3F32H
    cblock 0X20
    TEMPE
    TEMPA
    TEMPB
    TIME        
    TIME1
    TIME2
    RDorWR
    DATAin
    DATAout3
    DATAout2
    DATAout
    DATAoutA
    DATAoutB
    DATAoutC
    DATAoutX
    DATAoutY
    DATAoutZ
cnt_t0
    endc


    ORG     0000H
    GOTO    MULAI            ; JUMP TO MAIN PROGRAM        
    ORG        0004H            ; INTERRUPT VECTOR AREA
    GOTO    INT_SERVICE


MULAI:                        ; BEGINNING OF THE MAIN PROGRAM
    BSF        STATUS,5        ; INITIALIZATION PORT B
    MOVLW    B'11111100'        ; SET THE FIRST TWO BITS OF PORT C AS OUTPUT
    MOVWF    TRISC

    BSF        TRISB,0            ; SET THE BIT 0 OF PORT B AS INPUT
    BCF        OPTION_REG,INTEDG ; SET RISING EDGE
    BCF        INTCON,INTF        ; RESET INTERUPT FLAG OF INT
    BSF     INTCON,INTE        ; SET IEBIT OF INT
    BSF     INTCON,GIE        ; SET GLOBAT INT ENABLE

; INITIALIZATION OF TIMER0
    MOVLW    0X04
    MOVWF    OPTION_REG        ; T0 PRESCALE, TIMER, 1:32
; initialization of ADC
    MOVLW    0XC2    ; only first channel is being activated
                    ; IT WAS 8E FOR CH.0
    MOVWF    ADCON1
    MOVLW     B'00001010' ; set port RA0 and RA1 as input
    MOVWF     TRISA
    BCF        STATUS,5        ; SET BANK 0
    BCF        PORTC,0
    BCF        PORTC,1

    MOVLW    D'6'            ;SET COUNTFOR 156
    MOVWF    TMR0            
    MOVLW    0xA0                ; ENABLE T0 AND GLOBAL INTS
    MOVWF    INTCON
    CLRF    FLAGS

; set sent port
    CALL    SET_PORT_BE
    CALL    SET_PORTD_IN

    BSF        PORTE,1            ; set the rd and wr control signal inactive
    BCF        PORTE,0
    
    MOVLW    01H                ; set the first control byte 1;
    MOVWF    RDorWR

MAINLOOP:
    BTFSS    RDorWR,0        ; CHECK WHETHER STATUS IS O OR 1
    GOTO    CHECK_SEND        ; 1 CHECK IS DATA IS AVAILABLE TO READ

    BTFSC    PORTB,5            ; IS DATA RECEIVED
    GOTO    MAINLOOP        ; NO, GOTO MAINLOOP
    CALL    SET_PORTD_IN    ; YES, SET PORT DATA BUS IS
    BCF        PORTE,READ        ; SEND READ SIGNAL
    CALL    DELAY_200_US    ; DELAY
    MOVFW    PORTD            ; READ DATA BUS
    MOVWF    DATAin            ; SAVE DATA TO VARIABLE
    BSF        PORTE,READ        ; DEACTIVE THE READ SIGNAL
    CALL    PROCESS_RECEIVED_DATA    ; PROCESS THE RECEIVED DATA
    GOTO    MAINLOOP        ; GOTO MAINLOOP

CHECK_SEND:
    BTFSC    PORTB,TXE        ; DATA TO BE SENT IS EMPTY?
    GOTO    MAINLOOP        ; NO, GOTO MAIN LOOP
    CALL    SET_PORTD_OUT    ; YES, SET PORT OUTPUT
;------------------------------------------------------------------------------------------------------
; adc part 1
    MOVLW    0x81    ; f osc/32, adon, not started yet
    MOVWF    ADCON0

; operate the ADC first
MAIN2:    
    BCF        PIR1,ADIF
    BSF        ADCON0,GO
    CLRWDT
TEST:
    BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
                        ;    BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    GOTO    TEST

    MOVFW    ADRESH
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAout3

    BSF        STATUS,5        ; bank 1
    MOVFW    ADRESL
    BCF        STATUS,5    ; bank 0
    MOVWF    TEMPE
    
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAout

    RRF        TEMPE,F
    RRF        TEMPE,F
    RRF        TEMPE,F
    RRF        TEMPE,F
    MOVFW    TEMPE
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAout2

;-------------------------------------------------------------------------------------------------------    
; adc part 2
    MOVLW    0x89    ; f osc/32, adon, not started yet
    MOVWF    ADCON0

; operate the ADC SECOUND
    BCF        PIR1,ADIF
    BSF        ADCON0,GO
    CLRWDT
TEST1:
    BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
                        ;    BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    GOTO    TEST1

    MOVFW    ADRESH
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutC

    BSF        STATUS,5        ; bank 1
    MOVFW    ADRESL
    BCF        STATUS,5    ; bank 0
    MOVWF    TEMPA
    
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutA

  RRF        TEMPA,F
    RRF        TEMPA,F
   RRF        TEMPA,F
    RRF        TEMPA,F
    MOVFW    TEMPA
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutB
;-------------------------------------------------------------------------------------------------------    
; adc part 2
    MOVLW    0x91    ; f osc/32, adon, not started yet
    MOVWF    ADCON0

; operate the ADC SECOUND
    BCF        PIR1,ADIF
    BSF        ADCON0,GO
    CLRWDT
TEST2:
    BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
                        ;    BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    GOTO    TEST2

    MOVFW    ADRESH
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutZ

    BSF        STATUS,5        ; bank 1
    MOVFW    ADRESL
    BCF        STATUS,5    ; bank 0
    MOVWF    TEMPB
    
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutX

  RRF        TEMPB,F
    RRF        TEMPB,F
   RRF        TEMPB,F
    RRF        TEMPB,F
    MOVFW    TEMPB
    ANDLW    0X0F
    CALL    GET_CHAR_CODE
    MOVWF    DATAoutY
;*******************************************************************************************************************
; SENDING THE DATA TO USB MODULE
;--------------------------------------------------------------------------------------------------------------------
;CHANNEL 1
    MOVLW    0X2A            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL

    MOVFW    DATAout3            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL

    MOVFW    DATAout2            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL

    MOVFW    DATAout            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL

;-----------------------------------------------------------------------------------------------------------------------
;CHANNEL 2

    MOVLW    0X2B            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL

    MOVFW    DATAoutC            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL

    MOVFW    DATAoutB            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL

    MOVFW    DATAoutA            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
;-----------------------------------------------------------------------------------------------------------------------
;CHANNEL 3

    MOVLW    0X2C            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL

    MOVFW    DATAoutZ            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL

    MOVFW    DATAoutY            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL

    MOVFW    DATAoutX            ; READ DATA TO BE SENT
    MOVWF    PORTD            ; PLACE THE DATA TO BUS
    BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    CALL    DELAY_50_US    ; DELAY
    BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    ; SET THE STATUS THAT WRITING IS DONE
    MOVWF    RDorWR

    GOTO    MAINLOOP
 

Thread Starter

azhari24

Joined Dec 5, 2011
7
Rich (BB code):
SEND_USB:
    BTFSC    PORTB,TXE
    GOTO    SEL1
    CALL    SET_PORTD_OUT
    MOVFW    DATAout
    MOVWF    PORTD
    BSF        PORTE,WRITE
    CALL    DELAY_200_US
    BCF        PORTE,WRITE
    MOVLW    01H
    MOVWF    RDorWR
SEL1:
    RETURN


PROCESS_RECEIVED_DATA:
    MOVFW    DATAin
    ADDLW    01H
    MOVWF    DATAout
    CLRF    RDorWR        ; SET RECEIVED HAS BEEN DONE
    RETURN

SET_PORT_BE:
    BSF        STATUS,5    ;INISIASI PORT
    CLRF    PORTB
    MOVLW     03FH    ; bit 0-5 are for input
    MOVWF    TRISB    ; bit 4 and 5 is for TxE and RxF    
    MOVLW    0FCH    ; the only first two bits are output
    MOVWF    TRISE    ; bit 0 and 1 are for WR and RD
    BCF        STATUS,5
    RETURN

SET_PORTD_IN:
    BSF        STATUS,5    ;INISIASI PORT
    MOVLW     0FFH    ; set port.D as input first
    MOVWF     TRISD
    BCF        TRISE,4
    BCF        STATUS,5
    RETURN

SET_PORTD_OUT:
    BSF        STATUS,5    ;INISIASI PORT
    MOVLW     00H            ; set port.D as input first
    MOVWF     TRISD
    BCF        TRISE,4
    BCF        STATUS,5
    RETURN

DELAY_50_US
    MOVLW    D'250'
    MOVWF    TIME
LOOP_50_US:
    NOP
    DECFSZ    TIME,F
    GOTO     LOOP_50_US
    RETURN

DELAY_200_US
    MOVLW    D'250'
    MOVWF    TIME
LOOP_200_US:
    NOP
    DECFSZ    TIME,F
    GOTO     LOOP_200_US
    RETURN

DELAY_50_MS:
    MOVLW    D'250'
    MOVWF    TIME1
LOOP_50_MS:
    CALL    DELAY_200_US
    DECFSZ    TIME1,F
    GOTO    LOOP_50_MS
    RETURN

DELAY_ONE_SEC:
    MOVLW    D'15'
    MOVWF    TIME2
LOOP_ONE_SEC:
    CALL    DELAY_50_MS
    DECFSZ    TIME2,F
    GOTO    LOOP_ONE_SEC
    RETURN

INT_SERVICE:
    MOVWF    W_TEMP        ; SAVE  W AND STATUS REGISTERS
    SWAPF    STATUS,W
    MOVWF    STATUS_T

    MOVLW    D'61'            ; RESET COUNT FOR 156
    MOVWF    TMR0        
    
    BCF        INTCON,T0IF        ; RESET T0 INT FLAGS
    BSF        FLAGS,0            ; SET USER FLAG; INT OCCURS

    ;CALL    SEND_USB
    MOVLW    00H
    MOVWF    RDorWR

isr_end
    BCF        INTCON,INTF
    SWAPF    STATUS_T,W    ; RESTORE W AND STATUS REGISTERS
    MOVWF    STATUS
    SWAPF    W_TEMP,F
    SWAPF    W_TEMP,W

    RETFIE    


; LOOK UP TABLE
GET_CHAR_CODE:
    ADDWF    PCL,F
    RETLW    0X30    ; 0
    RETLW    0X31    ; 1    
    RETLW    0X32    ; 2
    RETLW    0X33    ; 3
    RETLW    0X34    ; 4
    RETLW    0X35    ; 5
    RETLW    0X36    ; 6
    RETLW    0X37    ; 7
    RETLW    0X38    ; 8
    RETLW    0X39    ; 9
    RETLW    0X41    ; A
    RETLW    0X42    ; B
    RETLW    0X43    ; C
    RETLW    0X44    ; D
    RETLW    0X45    ; E
    RETLW    0X46    ; F
    END
 

Markd77

Joined Sep 7, 2009
2,806
A few things I noticed, not sure they will fix the problem:
There's no need to define STATUS, PORTA, etc.
You have defined in the EQU section things that will not work, for example COUNT0, COUNT1 and FLAGS are set to the same as FSRs and another user variable. Put all user variables in the CBLOCK section to avoid these problems.
<ed>You can leave W_TEMP AND STATUS_T in the EQU section or put them in another CBLOCK 0x70. They need to be kept in the area which is available in all banks. </ed>
<ed2>After saving STATUS and W in INTSERVICE, change to BANK 0, because it could be in any bank when the interrupt happens. </ed2>
In set_port_be it is in the wrong bank for PORTB.
Hopefully these will get it closer to working.
 
Last edited:

thatoneguy

Joined Feb 19, 2009
6,359
I'd suggest testing the GO/!DONE bit rather than the interrupt bit to signal the conversion is complete.

Since you aren't using interrupts for the ADC conversion, you should ignore the interrupt flags related to ADC, as the code gets confusing when both are seen.
 

Thread Starter

azhari24

Joined Dec 5, 2011
7
I'd suggest testing the GO/!DONE bit rather than the interrupt bit to signal the conversion is complete.

Since you aren't using interrupts for the ADC conversion, you should ignore the interrupt flags related to ADC, as the code gets confusing when both are seen.
okay. thank you about your formula...
 
Top