Very beginner with uart

Discussion in 'Embedded Systems and Microcontrollers' started by Ahmed Adel, Dec 9, 2009.

  1. Ahmed Adel

    Thread Starter Member

    May 12, 2008
    18
    0
    hi everyone ..

    I am striving to make a simple example of uart .. my circuit diagram is [​IMG]

    [​IMG]

    the switch at Tx, when pushed, is to cause Tx to send the character 0xAB to Rx, which will ,in turn, indicate the receiption of this character on the corresponding leds .. my code (of course) doesn't work at all ..

    Tx code:
    Code ( (Unknown Language)):
    1.  
    2.         processor 16f877a
    3.         include <p16f877a.inc>
    4.         __config _HS_OSC & _WDT_OFF & _PWRTE_ON
    5.    
    6.         ;configuring TX of UART
    7.         banksel TRISA
    8.         movlw 0xFF
    9.         movwf TRISA
    10.        
    11.         bsf TXSTA, BRGH        ;high speed
    12.  
    13.         banksel SPBRG
    14.         movlw 0x19
    15.         movwf SPBRG    ;set baud rate to 9600
    16.  
    17.         banksel RCSTA
    18.         bsf RCSTA, SPEN
    19.  
    20.         banksel TXSTA
    21.         bsf TXSTA, TXEN
    22.         bcf TXSTA, SYNC
    23.  
    24.  
    25. rep
    26.                 banksel PORTA        
    27.                 btfsc PORTA,0
    28.                 goto transmit
    29.                 btfss PORTA,0
    30.                 goto rep
    31.        
    32. transmit                
    33.                 movlw 0xAB
    34.                 banksel TXREG
    35.                 movwf TXREG
    36.                 goto rep
    37.  
    38.         end
    39.  


    Rx code:


    Code ( (Unknown Language)):
    1.  
    2.         processor 16f877a
    3.         include <p16f877a.inc>
    4.         __config _HS_OSC & _WDT_OFF & _PWRTE_ON
    5.  
    6.         ;configuring RX of UART
    7.         banksel TRISA
    8.         movlw 0x00
    9.         movwf TRISA
    10.  
    11.         banksel RCSTA
    12.         bsf RCSTA, SPEN
    13.        
    14.        
    15.         banksel TXSTA
    16.         bcf TXSTA, SYNC
    17.         bsf TXSTA, CREN
    18.         bsf TXSTA, BRGH        ;high speed
    19.  
    20.         banksel SPBRG
    21.         movlw 0x19
    22.         movwf SPBRG    ;set baud rate to 9600
    23.        
    24. k
    25.        
    26.         banksel PIE1
    27.         btfsc PIE1, RCIF
    28.         goto m
    29.         nop
    30. m
    31.         banksel RCREG
    32.         movf RCREG,w
    33.         banksel PORTA
    34.         movwf PORTA
    35.         goto k
    36.  
    37.  
    38.         end
    39.  
     
  2. Ahmed Adel

    Thread Starter Member

    May 12, 2008
    18
    0
    is it too complex to solve ?
     
  3. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Is your circuit diagram showing the true state of the circuit or have you left things off?
    Without a diagram showing the actual connections it's impossible to say what you are doing wrong.
    The diagram as shown is missing:
    1. Vss and Vdd
    2. A crystal or resonator
    3. The MCLR pulled up to Vdd.
    4. Resistors to limit the LED current
    You probably some some or all of those connected but we or not mind readers and unless you supply full information we can't help you.
     
  4. cheezewizz

    Active Member

    Apr 16, 2009
    82
    10
    On proteus the Vss and Vdd pins are automatically connected to the appropriate voltage and the pins aren't shown on the schematic unless specified. The clock is set in the chip options (same place where voltage can be given) too. But don't the PORTA pins default to analogue inputs? i don't see anywhere in the TX chip code these being changed .....

    ps i love your sig AlexR :)
     
    Last edited: Dec 10, 2009
  5. Ahmed Adel

    Thread Starter Member

    May 12, 2008
    18
    0
    thanks AlexR .. but as cheezewizz said .. proteus connects vss and vdd automatically, crystal is set in chip options, no need for led resistors .. if possible please have a look on my code and notify me with the bug :D :D

    no my mate, I have already configured porta as digital input .. here is the code

    Code ( (Unknown Language)):
    1.  
    2. banksel TRISA        
    3. movlw 0xFF        
    4. movwf TRISA
    5.  
    Please I need urgent help ..

    Thanks in advance to everybody ..
     
  6. cheezewizz

    Active Member

    Apr 16, 2009
    82
    10
    nah what i meant was according to the datasheet, port A default to analogue inputs. you need to use the following code to set them as digital...
    Code ( (Unknown Language)):
    1. BSF     STATUS, RP0
    2. MOVLW    0x06
    3. MOVWF    ADCON1
     
  7. Ahmed Adel

    Thread Starter Member

    May 12, 2008
    18
    0
    no my mate .. I tried your code and the problem is still exist .. pleaeaeaeaeaeaese heeelp ..
     
  8. Ahmed Adel

    Thread Starter Member

    May 12, 2008
    18
    0
    haaaaaaaay guys ..

    ok .. don't care about my question .. I want the simplest example to implement uart on 877A .. can anybody help ..?
     
  9. Ahmed Adel

    Thread Starter Member

    May 12, 2008
    18
    0
    that is fine !!
     
Loading...