+ Post New Thread
Results 1 to 15 of 15
  1. #1
    Member level 1
    Points: 1,194, Level: 7

    Join Date
    Jul 2013
    Posts
    32
    Helped
    1 / 1
    Points
    1,194
    Level
    7

    PIC16F877 UART rx is not working TX and ADC are working

    Hello everybody
    I am trying to show the ADC value and UART RX value on LCD .ADC value is showing on but the the uart value is not getting.
    Please help me to find out the problem in my assembly code with (PIC16F877A) uart rx (receive ) (RXPOLL) . But the UART TX (TXPOLL) is working very well .
    Please note the attached ASM code and screen shots of Proteus simulation...

  2. #2
    Super Moderator
    Points: 81,377, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,340
    Helped
    4454 / 4454
    Points
    81,377
    Level
    69

    Re: PIC16F877 UART rx is not working TX and ADC are working

    Before even looking at the problem, tell me why you are redefining all the PIC register addresses and mixing 'banksel' directives with direct bank selection instructions.

    You also state the PC should run at 19200 Bauds but the comment in the code suggest you configure the UART for 2400 Bauds.

    Why are you polling the interrupt flag? It's much easier to enable interrupts and read the UART inside an ISR.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  3. #3
    Member level 1
    Points: 1,194, Level: 7

    Join Date
    Jul 2013
    Posts
    32
    Helped
    1 / 1
    Points
    1,194
    Level
    7

    Re: PIC16F877 UART rx is not working TX and ADC are working

    dear sir....

    sorry for the mistake ... actually I change the baud rate to 9600 . but I forget to change the comments .
    I am using polling because I am not an expert with ISR method



  4. #4
    Super Moderator
    Points: 81,377, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,340
    Helped
    4454 / 4454
    Points
    81,377
    Level
    69

    Re: PIC16F877 UART rx is not working TX and ADC are working

    I assume you are using MPLAB or MPLABX, can you post the project files please so I can replicate exactly what you have there. With just the source file it's difficult to know the environment you are using and it can make a big difference to the way the code works.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  5. #5
    Member level 1
    Points: 1,194, Level: 7

    Join Date
    Jul 2013
    Posts
    32
    Helped
    1 / 1
    Points
    1,194
    Level
    7

    Re: PIC16F877 UART rx is not working TX and ADC are working

    dear sir...
    please note the attached files



  6. #6
    Member level 1
    Points: 1,194, Level: 7

    Join Date
    Jul 2013
    Posts
    32
    Helped
    1 / 1
    Points
    1,194
    Level
    7

    Re: PIC16F877 UART rx is not working TX and ADC are working

    I am also attaching proteus simulation files



  7. #7
    Member level 1
    Points: 1,194, Level: 7

    Join Date
    Jul 2013
    Posts
    32
    Helped
    1 / 1
    Points
    1,194
    Level
    7

    Re: PIC16F877 UART rx is not working TX and ADC are working

    Dear all .....
    still the same problem , anybody help to add an ISR ?



    •   AltAdvertisement

        
       

  8. #8
    Super Moderator
    Points: 81,377, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,340
    Helped
    4454 / 4454
    Points
    81,377
    Level
    69

    Re: PIC16F877 UART rx is not working TX and ADC are working

    Sorry for the delay, I've been busy with other tasks.
    I had some problems importing your code into MPLABX but I have it there now. It will take me a while to work out exactly what it does, especially the math part.

    An ISR is quite easy to implement, based on your code, all you have to do is make room for the ISR code because it has to be located at address 0004 and you already have code there, then write the interrupt handler, the code for this is in the template, add the specific part to detect the UART as the cause of the interrupt and read the data and finally, have a mechanism to tell the main code that a character has been received.

    What should happen is your main code loop runs all the time and when a character arrives, no matter when it is, the loop is suspended, the UART read then the loop resumes. It means it no longer has to wait in a loop checking the RCIF bit until a character arrives.

    I'll try to add an ISR to your code and post it here as quickly as possible but I'm very busy at the moment so please be patient.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.


    1 members found this post helpful.

  9. #9
    Member level 1
    Points: 1,194, Level: 7

    Join Date
    Jul 2013
    Posts
    32
    Helped
    1 / 1
    Points
    1,194
    Level
    7

    Re: PIC16F877 UART rx is not working TX and ADC are working

    Dear sir
    I have added an ISR code in my program but i can't solve the problem myself,
    please see the modified code.adc and uart isr.txt



  10. #10
    Super Moderator
    Points: 81,377, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,340
    Helped
    4454 / 4454
    Points
    81,377
    Level
    69

    Re: PIC16F877 UART rx is not working TX and ADC are working

    I'm not at an assembler at the moment but I can see some errors.
    Code:
    IntSRV                       ;The result is placed in W register
         MOVWF          W_TEMP          ;Copy W to TEMP register
         SWAPF          STATUS,W        ;Swap status to be saved into W
         CLRF           STATUS          ;bank 0, regardless of current bank, Clears IRP,RP1,RP0
         MOVWF          STATUS_TEMP     ;Save status to bank zero STATUS_TEMP register
         MOVF           PCLATH, W       ;Only required if using pages 1, 2 and/or 3
         MOVWF          PCLATH_TEMP     ;Save PCLATH into W
         CLRF           PCLATH          ;Page zero, regardless of current page <-- instead use banksel RCSTA to access CREN
         BSF            RCSTA,CREN <-- this should be in the register initialization not in the ISR
         banksel        PIR1
    RXPOLL btfss          PIR1, RCIF    ;RX Buffer Full? (i.e. Data Received?)
         goto           RXPOLL <-- remove this line, if the interrupt occurred RCIF must already be set
         banksel        RCREG
         movf           RCREG,0 ;received data to W
         banksel        TEMPLOW
         movwf          TEMPLOW   ;tempHIGH <--ADRESH
         MOVF           PCLATH_TEMP, W    ;Restore PCLATH
         MOVWF          PCLATH            ;Move W into PCLATH
         SWAPF          STATUS_TEMP,W     ;Swap STATUS_TEMP register into W
    ;(sets bank to original state)
         MOVWF          STATUS            ;Move W into STATUS register
         SWAPF          W_TEMP,F          ;Swap W_TEMP
         SWAPF          W_TEMP,W          ;Swap W_TEMP into W
         retfie
    I would move all that code so it is 'in line' with the interrupt vector like this:
    Code:
    ;=========================================================
        org       0x0000
        GOTO      START
        org       0x04                   ;        
        goto      IntSRV                 ;added isr <-- put the whole ISR code here
        org       0x10  <-- remove this line otherwise you may be overwriting the end of the ISR code
    The "START" label will make sure the address of the 'GOTO START' is correct. The assembler learns the addresses of all the labels on it's first pass then inserts them into the instruction on the second pass so except for special cases such as the ISR and sometimes data tables, you don't need to use 'org' again. When you add an 'org' statement it resets the address where the following instructions will be located so there is a risk of overwriting something already there, it's better to let the assembler work out the best addresses for you. You DO need to use 'org' at the reset vector (0x0000) and the ISR (0x0004) as they are special addresses and the code following them has to be there because of the way the PIC works internally.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.


    1 members found this post helpful.

  11. #11
    Member level 1
    Points: 1,194, Level: 7

    Join Date
    Jul 2013
    Posts
    32
    Helped
    1 / 1
    Points
    1,194
    Level
    7

    Re: PIC16F877 UART rx is not working TX and ADC are working

    Dear sir,
    thank you for your quick reply. I have changed the code and now the code is running . . but the 2nd row of the received data on lcd display is incorrect (1st row showing the ADC value is correct).CHANGED CODE.txt
    Last edited by asthra123; 20th July 2017 at 07:03.



  12. #12
    Member level 1
    Points: 1,194, Level: 7

    Join Date
    Jul 2013
    Posts
    32
    Helped
    1 / 1
    Points
    1,194
    Level
    7

    Re: PIC16F877 UART rx is not working TX and ADC are working

    Dear all.....
    The main code have a subroutine "AGAIN " (maths routine) to show the ADC value on LCD display.
    like that the ISR for UART receive also required the subroutine to show the received value on the second line of the LCD screen
    how we can implement the code .



  13. #13
    Member level 1
    Points: 1,194, Level: 7

    Join Date
    Jul 2013
    Posts
    32
    Helped
    1 / 1
    Points
    1,194
    Level
    7

    Re: PIC16F877 UART rx is not working TX and ADC are working

    dear sir....
    My question is the ASM code for PIC16F877 have to display both ADC value and UART value on LCD by two lines..
    The main code have two subroutines one for ADC and other for LCD write . but i am using an ISR for reading UART receive , and how we show the UART receive value on the second row of the LCD. can we use the lcd write subroutine in the main loop ?



  14. #14
    Super Moderator
    Points: 77,678, Level: 67
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,748
    Helped
    3587 / 3587
    Points
    77,678
    Level
    67

    Re: PIC16F877 UART rx is not working TX and ADC are working

    Hi,

    Within the Uart_receive_ISR just put the received data in a buffer (FIFO) and set a flag to indicate new received data.
    Don't process the data in the ISR. Every ISR should be short in time.
    In main loop: Poll the flag, if SET process the received data. Send them to the display as you like.

    Don't mix display access in main_loop and ISR.
    Either do all display access via ISR, or all display access in main

    Klaus


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  15. #15
    Member level 1
    Points: 1,194, Level: 7

    Join Date
    Jul 2013
    Posts
    32
    Helped
    1 / 1
    Points
    1,194
    Level
    7

    Re: PIC16F877 UART rx is not working TX and ADC are working

    Thank you very much sir..
    I can solve the problem with your help..
    now its working..



--[[ ]]--