Timer0 interrupt 16F877A [Assembly]

Discussion in 'Embedded Systems and Microcontrollers' started by azhari24, Dec 5, 2011.

  1. azhari24

    Thread Starter New Member

    Dec 5, 2011
    7
    0
    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.
    Code ( (Unknown Language)):
    1.  
    2.     ORG     0000H
    3.     GOTO    MULAI            ; JUMP TO MAIN PROGRAM        
    4.     ORG        0004H            ; INTERRUPT VECTOR AREA
    5.     GOTO    INT_SERVICE
    6.  
    7. MULAI:                        ; BEGINNING OF THE MAIN PROGRAM
    8.     BSF        STATUS,5        ; INITIALIZATION PORT B
    9.     MOVLW    B'11111100'        ; SET THE FIRST TWO BITS OF PORT C AS OUTPUT
    10.     MOVWF    TRISC
    11.     BSF        TRISB,0            ; SET THE BIT 0 OF PORT B AS INPUT
    12.     BCF        OPTION_REG,INTEDG ; SET RISING EDGE
    13.     BCF        INTCON,INTF        ; RESET INTERUPT FLAG OF INT
    14.     BSF     INTCON,INTE        ; SET IEBIT OF INT
    15.     BSF     INTCON,GIE        ; SET GLOBAT INT ENABLE
    16.  
    17. ; INITIALIZATION OF TIMER0
    18.     MOVLW    0X04
    19.     MOVWF    OPTION_REG        ; T0 PRESCALE, TIMER, 1:32
    20.  
    21. ; initialization of ADC
    22.     MOVLW    0XC2    ; only first channel is being activated
    23.             ; IT WAS 8E FOR CH.0
    24.     MOVWF    ADCON1
    25.  
    26.     MOVLW     B'00001010' ; set port RA0 and RA1 as input
    27.     MOVWF     TRISA
    28.     BCF        STATUS,5        ; SET BANK 0
    29.     BCF        PORTC,0
    30.     BCF        PORTC,1
    31.  
    32.     MOVLW    D'6'                ;SET COUNTFOR 6
    33.     MOVWF    TMR0            
    34.     MOVLW    0xA0                ; ENABLE T0 AND GLOBAL INTS
    35.     MOVWF    INTCON    
    36.     CLRF    FLAGS
    37.  
    38. ; set sent port
    39.     CALL    SET_PORT_BE
    40.     CALL    SET_PORTD_IN
    41.  
    42.     BSF        PORTE,1            ; set the rd and wr control signal inactive
    43.     BCF        PORTE,0
    44.    
    45.     MOVLW    01H                ; set the first control byte 1;
    46.     MOVWF    RDorWR
    47.  
    48. MAINLOOP:
    49. ;------------------------------------------------------------------------------------------------------
    50. ; adc part 1
    51.     MOVLW    0x81    ; f osc/32, adon, not started yet
    52.     MOVWF    ADCON0
    53.  
    54. ; operate the ADC first
    55. MAIN2:    
    56.     BCF        PIR1,ADIF
    57.     BSF        ADCON0,GO
    58.     CLRWDT
    59. TEST:
    60.     BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
    61.                     ;BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    62.     GOTO    TEST
    63.  
    64.     MOVFW    ADRESH
    65.     ANDLW    0X0F
    66.     CALL    GET_CHAR_CODE
    67.     MOVWF    DATAout3
    68.  
    69.     BSF        STATUS,5    ; bank 1
    70.     MOVFW    ADRESL
    71.     BCF        STATUS,5    ; bank 0
    72.     MOVWF    TEMPE
    73.    
    74.     ANDLW    0X0F
    75.     CALL    GET_CHAR_CODE
    76.     MOVWF    DATAout
    77.  
    78.     RRF        TEMPE,F
    79.     RRF        TEMPE,F
    80.     RRF        TEMPE,F
    81.     RRF        TEMPE,F
    82.     MOVFW    TEMPE
    83.     ANDLW    0X0F
    84.     CALL    GET_CHAR_CODE
    85.     MOVWF    DATAout2
    86.  
    87. ;-------------------------------------------------------------------------------------------------------    
    88. ; adc part 2
    89.     MOVLW    0x89    ; f osc/32, adon, not started yet
    90.     MOVWF    ADCON0
    91.  
    92. ; operate the ADC SECOUND
    93.     BCF        PIR1,ADIF
    94.     BSF        ADCON0,GO
    95.     CLRWDT
    96. TEST1:
    97.     BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
    98.                     ;BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    99.     GOTO    TEST1
    100.  
    101.     MOVFW    ADRESH
    102.     ANDLW    0X0F
    103.     CALL    GET_CHAR_CODE
    104.     MOVWF    DATAoutC
    105.  
    106.     BSF        STATUS,5    ; bank 1
    107.     MOVFW    ADRESL
    108.     BCF        STATUS,5    ; bank 0
    109.     MOVWF    TEMPA
    110.    
    111.     ANDLW    0X0F
    112.     CALL    GET_CHAR_CODE
    113.     MOVWF    DATAoutA
    114.  
    115.   RRF        TEMPA,F
    116.     RRF        TEMPA,F
    117.    RRF        TEMPA,F
    118.     RRF        TEMPA,F
    119.     MOVFW    TEMPA
    120.     ANDLW    0X0F
    121.     CALL    GET_CHAR_CODE
    122.     MOVWF    DATAoutB
    123. ;-------------------------------------------------------------------------------------------------------    
    124. ; adc part 2
    125.     MOVLW    0x91    ; f osc/32, adon, not started yet
    126.     MOVWF    ADCON0
    127.  
    128. ; operate the ADC SECOUND
    129.     BCF        PIR1,ADIF
    130.     BSF        ADCON0,GO
    131.     CLRWDT
    132. TEST2:
    133.     BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
    134.                     ;BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    135.     GOTO    TEST2
    136.  
    137.     MOVFW    ADRESH
    138.     ANDLW    0X0F
    139.     CALL    GET_CHAR_CODE
    140.     MOVWF    DATAoutZ
    141.  
    142.     BSF        STATUS,5    ; bank 1
    143.     MOVFW    ADRESL
    144.     BCF        STATUS,5    ; bank 0
    145.     MOVWF    TEMPB
    146.    
    147.     ANDLW    0X0F
    148.     CALL    GET_CHAR_CODE
    149.     MOVWF    DATAoutX
    150.  
    151.   RRF        TEMPB,F
    152.     RRF        TEMPB,F
    153.    RRF        TEMPB,F
    154.     RRF        TEMPB,F
    155.     MOVFW    TEMPB
    156.     ANDLW    0X0F
    157.     CALL    GET_CHAR_CODE
    158.     MOVWF    DATAoutY
    159.  
    160. ; SENDING THE DATA TO USB MODULE
    161. ;--------------------------------------------------------------------------------------------------------------------
    162. ;CHANNEL 1
    163.     CALL    SEND_DATA_CH1      ;SEND DATA
    164. ;-----------------------------------------------------------------------------------------------------------------------
    165. ;CHANNEL 2
    166.     CALL    SEND_DATA_CH2      ;SEND DATA
    167. ;-----------------------------------------------------------------------------------------------------------------------
    168. ;CHANNEL 3
    169.     CALL    SEND_DATA_CH3      ;SEND DATA
    170.  
    171.     MOVWF    RDorWR
    172.  
    173.     GOTO    MAINLOOP
    174.  
    175.  
    176.  
    177.  
    178. INT_SERVICE:
    179.     MOVWF    W_TEMP        ; SAVE  W AND STATUS REGISTERS
    180.     SWAPF    STATUS,W
    181.     MOVWF    STATUS_T
    182.  
    183. ;    BSF        PORTC,0        ; AS AN INDICATOR OF PROCESS
    184. ;    BCF        PORTC,0
    185.  
    186.     MOVLW    D'6'            ; RESET COUNT FOR 6
    187.     MOVWF    TMR0        
    188.         BCF        INTCON,T0IF        ; RESET T0 INT FLAGS
    189.     BSF        FLAGS,0            ; SET USER FLAG; INT OCCURS
    190.  
    191.     ;CALL    SEND_USB
    192.     MOVLW    00H
    193.     MOVWF    RDorWR
    194.  
    195. isr_end
    196.     BCF        INTCON,INTF
    197.     SWAPF    STATUS_T,W    ; RESTORE W AND STATUS REGISTERS
    198.     MOVWF    STATUS
    199.     SWAPF    W_TEMP,F
    200.     SWAPF    W_TEMP,W
    201.  
    202.     RETFIE    
    203.  
    thank you....
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  3. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,678
    2,737
    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.
     
  4. azhari24

    Thread Starter New Member

    Dec 5, 2011
    7
    0
    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..
     
  5. azhari24

    Thread Starter New Member

    Dec 5, 2011
    7
    0
    thank you your suggestion...
     
  6. azhari24

    Thread Starter New Member

    Dec 5, 2011
    7
    0
    this is all my code

    Code ( (Unknown Language)):
    1. LIST P=16F877A
    2. #INCLUDE "P16F877A.INC"
    3.  
    4. STATUS        EQU    03H
    5. TRISB        EQU 86H
    6. TRISC        EQU    87H
    7. PORTB        EQU 06H    
    8. PORTC        EQU    07H
    9. COUNT0        EQU    0CH    
    10. COUNT1        EQU    0DH    
    11. READ        EQU 1H
    12. WRITE        EQU 0H
    13. TXE            EQU 4H
    14. RXF         EQU 5H
    15. W_TEMP        EQU    0X70
    16. STATUS_T    EQU    0X71
    17. FLAGS        EQU    0X20
    18.  
    19.     __CONFIG 3F32H
    20.     cblock 0X20
    21.     TEMPE
    22.     TEMPA
    23.     TEMPB
    24.     TIME        
    25.     TIME1
    26.     TIME2
    27.     RDorWR
    28.     DATAin
    29.     DATAout3
    30.     DATAout2
    31.     DATAout
    32.     DATAoutA
    33.     DATAoutB
    34.     DATAoutC
    35.     DATAoutX
    36.     DATAoutY
    37.     DATAoutZ
    38. cnt_t0
    39.     endc
    40.  
    41.  
    42.     ORG     0000H
    43.     GOTO    MULAI            ; JUMP TO MAIN PROGRAM        
    44.     ORG        0004H            ; INTERRUPT VECTOR AREA
    45.     GOTO    INT_SERVICE
    46.  
    47.  
    48. MULAI:                        ; BEGINNING OF THE MAIN PROGRAM
    49.     BSF        STATUS,5        ; INITIALIZATION PORT B
    50.     MOVLW    B'11111100'        ; SET THE FIRST TWO BITS OF PORT C AS OUTPUT
    51.     MOVWF    TRISC
    52.  
    53.     BSF        TRISB,0            ; SET THE BIT 0 OF PORT B AS INPUT
    54.     BCF        OPTION_REG,INTEDG ; SET RISING EDGE
    55.     BCF        INTCON,INTF        ; RESET INTERUPT FLAG OF INT
    56.     BSF     INTCON,INTE        ; SET IEBIT OF INT
    57.     BSF     INTCON,GIE        ; SET GLOBAT INT ENABLE
    58.  
    59. ; INITIALIZATION OF TIMER0
    60.     MOVLW    0X04
    61.     MOVWF    OPTION_REG        ; T0 PRESCALE, TIMER, 1:32
    62. ; initialization of ADC
    63.     MOVLW    0XC2    ; only first channel is being activated
    64.                     ; IT WAS 8E FOR CH.0
    65.     MOVWF    ADCON1
    66.     MOVLW     B'00001010' ; set port RA0 and RA1 as input
    67.     MOVWF     TRISA
    68.     BCF        STATUS,5        ; SET BANK 0
    69.     BCF        PORTC,0
    70.     BCF        PORTC,1
    71.  
    72.     MOVLW    D'6'            ;SET COUNTFOR 156
    73.     MOVWF    TMR0            
    74.     MOVLW    0xA0                ; ENABLE T0 AND GLOBAL INTS
    75.     MOVWF    INTCON
    76.     CLRF    FLAGS
    77.  
    78. ; set sent port
    79.     CALL    SET_PORT_BE
    80.     CALL    SET_PORTD_IN
    81.  
    82.     BSF        PORTE,1            ; set the rd and wr control signal inactive
    83.     BCF        PORTE,0
    84.    
    85.     MOVLW    01H                ; set the first control byte 1;
    86.     MOVWF    RDorWR
    87.  
    88. MAINLOOP:
    89.     BTFSS    RDorWR,0        ; CHECK WHETHER STATUS IS O OR 1
    90.     GOTO    CHECK_SEND        ; 1 CHECK IS DATA IS AVAILABLE TO READ
    91.  
    92.     BTFSC    PORTB,5            ; IS DATA RECEIVED
    93.     GOTO    MAINLOOP        ; NO, GOTO MAINLOOP
    94.     CALL    SET_PORTD_IN    ; YES, SET PORT DATA BUS IS
    95.     BCF        PORTE,READ        ; SEND READ SIGNAL
    96.     CALL    DELAY_200_US    ; DELAY
    97.     MOVFW    PORTD            ; READ DATA BUS
    98.     MOVWF    DATAin            ; SAVE DATA TO VARIABLE
    99.     BSF        PORTE,READ        ; DEACTIVE THE READ SIGNAL
    100.     CALL    PROCESS_RECEIVED_DATA    ; PROCESS THE RECEIVED DATA
    101.     GOTO    MAINLOOP        ; GOTO MAINLOOP
    102.  
    103. CHECK_SEND:
    104.     BTFSC    PORTB,TXE        ; DATA TO BE SENT IS EMPTY?
    105.     GOTO    MAINLOOP        ; NO, GOTO MAIN LOOP
    106.     CALL    SET_PORTD_OUT    ; YES, SET PORT OUTPUT
    107. ;------------------------------------------------------------------------------------------------------
    108. ; adc part 1
    109.     MOVLW    0x81    ; f osc/32, adon, not started yet
    110.     MOVWF    ADCON0
    111.  
    112. ; operate the ADC first
    113. MAIN2:    
    114.     BCF        PIR1,ADIF
    115.     BSF        ADCON0,GO
    116.     CLRWDT
    117. TEST:
    118.     BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
    119.                         ;    BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    120.     GOTO    TEST
    121.  
    122.     MOVFW    ADRESH
    123.     ANDLW    0X0F
    124.     CALL    GET_CHAR_CODE
    125.     MOVWF    DATAout3
    126.  
    127.     BSF        STATUS,5        ; bank 1
    128.     MOVFW    ADRESL
    129.     BCF        STATUS,5    ; bank 0
    130.     MOVWF    TEMPE
    131.    
    132.     ANDLW    0X0F
    133.     CALL    GET_CHAR_CODE
    134.     MOVWF    DATAout
    135.  
    136.     RRF        TEMPE,F
    137.     RRF        TEMPE,F
    138.     RRF        TEMPE,F
    139.     RRF        TEMPE,F
    140.     MOVFW    TEMPE
    141.     ANDLW    0X0F
    142.     CALL    GET_CHAR_CODE
    143.     MOVWF    DATAout2
    144.  
    145. ;-------------------------------------------------------------------------------------------------------    
    146. ; adc part 2
    147.     MOVLW    0x89    ; f osc/32, adon, not started yet
    148.     MOVWF    ADCON0
    149.  
    150. ; operate the ADC SECOUND
    151.     BCF        PIR1,ADIF
    152.     BSF        ADCON0,GO
    153.     CLRWDT
    154. TEST1:
    155.     BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
    156.                         ;    BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    157.     GOTO    TEST1
    158.  
    159.     MOVFW    ADRESH
    160.     ANDLW    0X0F
    161.     CALL    GET_CHAR_CODE
    162.     MOVWF    DATAoutC
    163.  
    164.     BSF        STATUS,5        ; bank 1
    165.     MOVFW    ADRESL
    166.     BCF        STATUS,5    ; bank 0
    167.     MOVWF    TEMPA
    168.    
    169.     ANDLW    0X0F
    170.     CALL    GET_CHAR_CODE
    171.     MOVWF    DATAoutA
    172.  
    173.   RRF        TEMPA,F
    174.     RRF        TEMPA,F
    175.    RRF        TEMPA,F
    176.     RRF        TEMPA,F
    177.     MOVFW    TEMPA
    178.     ANDLW    0X0F
    179.     CALL    GET_CHAR_CODE
    180.     MOVWF    DATAoutB
    181. ;-------------------------------------------------------------------------------------------------------    
    182. ; adc part 2
    183.     MOVLW    0x91    ; f osc/32, adon, not started yet
    184.     MOVWF    ADCON0
    185.  
    186. ; operate the ADC SECOUND
    187.     BCF        PIR1,ADIF
    188.     BSF        ADCON0,GO
    189.     CLRWDT
    190. TEST2:
    191.     BTFSS    PIR1,ADIF  ;first way to detect conversion is finished
    192.                         ;    BTFSC    ADCON0,GO  ; second method to detect wether it is finished or not
    193.     GOTO    TEST2
    194.  
    195.     MOVFW    ADRESH
    196.     ANDLW    0X0F
    197.     CALL    GET_CHAR_CODE
    198.     MOVWF    DATAoutZ
    199.  
    200.     BSF        STATUS,5        ; bank 1
    201.     MOVFW    ADRESL
    202.     BCF        STATUS,5    ; bank 0
    203.     MOVWF    TEMPB
    204.    
    205.     ANDLW    0X0F
    206.     CALL    GET_CHAR_CODE
    207.     MOVWF    DATAoutX
    208.  
    209.   RRF        TEMPB,F
    210.     RRF        TEMPB,F
    211.    RRF        TEMPB,F
    212.     RRF        TEMPB,F
    213.     MOVFW    TEMPB
    214.     ANDLW    0X0F
    215.     CALL    GET_CHAR_CODE
    216.     MOVWF    DATAoutY
    217. ;*******************************************************************************************************************
    218. ; SENDING THE DATA TO USB MODULE
    219. ;--------------------------------------------------------------------------------------------------------------------
    220. ;CHANNEL 1
    221.     MOVLW    0X2A            ; READ DATA TO BE SENT
    222.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    223.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    224.     CALL    DELAY_50_US    ; DELAY
    225.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    226.  
    227.     MOVFW    DATAout3            ; READ DATA TO BE SENT
    228.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    229.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    230.     CALL    DELAY_50_US    ; DELAY
    231.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    232.  
    233.     MOVFW    DATAout2            ; READ DATA TO BE SENT
    234.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    235.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    236.     CALL    DELAY_50_US    ; DELAY
    237.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    238.  
    239.     MOVFW    DATAout            ; READ DATA TO BE SENT
    240.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    241.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    242.     CALL    DELAY_50_US    ; DELAY
    243.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    244.  
    245. ;-----------------------------------------------------------------------------------------------------------------------
    246. ;CHANNEL 2
    247.  
    248.     MOVLW    0X2B            ; READ DATA TO BE SENT
    249.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    250.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    251.     CALL    DELAY_50_US    ; DELAY
    252.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    253.  
    254.     MOVFW    DATAoutC            ; READ DATA TO BE SENT
    255.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    256.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    257.     CALL    DELAY_50_US    ; DELAY
    258.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    259.  
    260.     MOVFW    DATAoutB            ; READ DATA TO BE SENT
    261.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    262.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    263.     CALL    DELAY_50_US    ; DELAY
    264.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    265.  
    266.     MOVFW    DATAoutA            ; READ DATA TO BE SENT
    267.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    268.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    269.     CALL    DELAY_50_US    ; DELAY
    270.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    271. ;-----------------------------------------------------------------------------------------------------------------------
    272. ;CHANNEL 3
    273.  
    274.     MOVLW    0X2C            ; READ DATA TO BE SENT
    275.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    276.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    277.     CALL    DELAY_50_US    ; DELAY
    278.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    279.  
    280.     MOVFW    DATAoutZ            ; READ DATA TO BE SENT
    281.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    282.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    283.     CALL    DELAY_50_US    ; DELAY
    284.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    285.  
    286.     MOVFW    DATAoutY            ; READ DATA TO BE SENT
    287.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    288.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    289.     CALL    DELAY_50_US    ; DELAY
    290.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    291.  
    292.     MOVFW    DATAoutX            ; READ DATA TO BE SENT
    293.     MOVWF    PORTD            ; PLACE THE DATA TO BUS
    294.     BSF        PORTE,WRITE        ; ACTIVE THE WRITE SIGNAL
    295.     CALL    DELAY_50_US    ; DELAY
    296.     BCF        PORTE,WRITE        ; DEACTIVE THE WRITE SIGNAL
    297.     ; SET THE STATUS THAT WRITING IS DONE
    298.     MOVWF    RDorWR
    299.  
    300.     GOTO    MAINLOOP
    301.  
     
  7. azhari24

    Thread Starter New Member

    Dec 5, 2011
    7
    0
    Code ( (Unknown Language)):
    1.  
    2. SEND_USB:
    3.     BTFSC    PORTB,TXE
    4.     GOTO    SEL1
    5.     CALL    SET_PORTD_OUT
    6.     MOVFW    DATAout
    7.     MOVWF    PORTD
    8.     BSF        PORTE,WRITE
    9.     CALL    DELAY_200_US
    10.     BCF        PORTE,WRITE
    11.     MOVLW    01H
    12.     MOVWF    RDorWR
    13. SEL1:
    14.     RETURN
    15.  
    16.  
    17. PROCESS_RECEIVED_DATA:
    18.     MOVFW    DATAin
    19.     ADDLW    01H
    20.     MOVWF    DATAout
    21.     CLRF    RDorWR        ; SET RECEIVED HAS BEEN DONE
    22.     RETURN
    23.  
    24. SET_PORT_BE:
    25.     BSF        STATUS,5    ;INISIASI PORT
    26.     CLRF    PORTB
    27.     MOVLW     03FH    ; bit 0-5 are for input
    28.     MOVWF    TRISB    ; bit 4 and 5 is for TxE and RxF    
    29.     MOVLW    0FCH    ; the only first two bits are output
    30.     MOVWF    TRISE    ; bit 0 and 1 are for WR and RD
    31.     BCF        STATUS,5
    32.     RETURN
    33.  
    34. SET_PORTD_IN:
    35.     BSF        STATUS,5    ;INISIASI PORT
    36.     MOVLW     0FFH    ; set port.D as input first
    37.     MOVWF     TRISD
    38.     BCF        TRISE,4
    39.     BCF        STATUS,5
    40.     RETURN
    41.  
    42. SET_PORTD_OUT:
    43.     BSF        STATUS,5    ;INISIASI PORT
    44.     MOVLW     00H            ; set port.D as input first
    45.     MOVWF     TRISD
    46.     BCF        TRISE,4
    47.     BCF        STATUS,5
    48.     RETURN
    49.  
    50. DELAY_50_US
    51.     MOVLW    D'250'
    52.     MOVWF    TIME
    53. LOOP_50_US:
    54.     NOP
    55.     DECFSZ    TIME,F
    56.     GOTO     LOOP_50_US
    57.     RETURN
    58.  
    59. DELAY_200_US
    60.     MOVLW    D'250'
    61.     MOVWF    TIME
    62. LOOP_200_US:
    63.     NOP
    64.     DECFSZ    TIME,F
    65.     GOTO     LOOP_200_US
    66.     RETURN
    67.  
    68. DELAY_50_MS:
    69.     MOVLW    D'250'
    70.     MOVWF    TIME1
    71. LOOP_50_MS:
    72.     CALL    DELAY_200_US
    73.     DECFSZ    TIME1,F
    74.     GOTO    LOOP_50_MS
    75.     RETURN
    76.  
    77. DELAY_ONE_SEC:
    78.     MOVLW    D'15'
    79.     MOVWF    TIME2
    80. LOOP_ONE_SEC:
    81.     CALL    DELAY_50_MS
    82.     DECFSZ    TIME2,F
    83.     GOTO    LOOP_ONE_SEC
    84.     RETURN
    85.  
    86. INT_SERVICE:
    87.     MOVWF    W_TEMP        ; SAVE  W AND STATUS REGISTERS
    88.     SWAPF    STATUS,W
    89.     MOVWF    STATUS_T
    90.  
    91.     MOVLW    D'61'            ; RESET COUNT FOR 156
    92.     MOVWF    TMR0        
    93.    
    94.     BCF        INTCON,T0IF        ; RESET T0 INT FLAGS
    95.     BSF        FLAGS,0            ; SET USER FLAG; INT OCCURS
    96.  
    97.     ;CALL    SEND_USB
    98.     MOVLW    00H
    99.     MOVWF    RDorWR
    100.  
    101. isr_end
    102.     BCF        INTCON,INTF
    103.     SWAPF    STATUS_T,W    ; RESTORE W AND STATUS REGISTERS
    104.     MOVWF    STATUS
    105.     SWAPF    W_TEMP,F
    106.     SWAPF    W_TEMP,W
    107.  
    108.     RETFIE    
    109.  
    110.  
    111. ; LOOK UP TABLE
    112. GET_CHAR_CODE:
    113.     ADDWF    PCL,F
    114.     RETLW    0X30    ; 0
    115.     RETLW    0X31    ; 1    
    116.     RETLW    0X32    ; 2
    117.     RETLW    0X33    ; 3
    118.     RETLW    0X34    ; 4
    119.     RETLW    0X35    ; 5
    120.     RETLW    0X36    ; 6
    121.     RETLW    0X37    ; 7
    122.     RETLW    0X38    ; 8
    123.     RETLW    0X39    ; 9
    124.     RETLW    0X41    ; A
    125.     RETLW    0X42    ; B
    126.     RETLW    0X43    ; C
    127.     RETLW    0X44    ; D
    128.     RETLW    0X45    ; E
    129.     RETLW    0X46    ; F
    130.     END
    131.  
     
  8. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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: Dec 6, 2011
  9. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    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.
     
  10. azhari24

    Thread Starter New Member

    Dec 5, 2011
    7
    0
    thank you... I hope your suggest can help my problem...
     
  11. azhari24

    Thread Starter New Member

    Dec 5, 2011
    7
    0
    okay. thank you about your formula...
     
Loading...