Very beginner with uart

Thread Starter

Ahmed Adel

Joined May 12, 2008
18
hi everyone ..

I am striving to make a simple example of uart .. my circuit diagram is




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:
Rich (BB code):
        processor 16f877a
        include <p16f877a.inc>
        __config _HS_OSC & _WDT_OFF & _PWRTE_ON
    
        ;configuring TX of UART
        banksel TRISA
        movlw 0xFF
        movwf TRISA
        
        bsf TXSTA, BRGH        ;high speed

        banksel SPBRG
        movlw 0x19
        movwf SPBRG    ;set baud rate to 9600

        banksel RCSTA
        bsf RCSTA, SPEN

        banksel TXSTA
        bsf TXSTA, TXEN
        bcf TXSTA, SYNC


rep
                banksel PORTA        
                btfsc PORTA,0
                goto transmit
                btfss PORTA,0
                goto rep
        
transmit                
                movlw 0xAB
                banksel TXREG
                movwf TXREG
                goto rep

        end


Rx code:


Rich (BB code):
        processor 16f877a
        include <p16f877a.inc>
        __config _HS_OSC & _WDT_OFF & _PWRTE_ON

        ;configuring RX of UART
        banksel TRISA
        movlw 0x00
        movwf TRISA

        banksel RCSTA
        bsf RCSTA, SPEN
        
        
        banksel TXSTA
        bcf TXSTA, SYNC
        bsf TXSTA, CREN
        bsf TXSTA, BRGH        ;high speed

        banksel SPBRG
        movlw 0x19
        movwf SPBRG    ;set baud rate to 9600
        
k
        
        banksel PIE1
        btfsc PIE1, RCIF
        goto m
        nop
m
        banksel RCREG
        movf RCREG,w
        banksel PORTA
        movwf PORTA
        goto k


        end
 

AlexR

Joined Jan 16, 2008
732
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.
 

cheezewizz

Joined Apr 16, 2009
82
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:

Thread Starter

Ahmed Adel

Joined May 12, 2008
18
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

But don't the PORTA pins default to analogue inputs? i don't see anywhere in the TX chip code these being changed .....
no my mate, I have already configured porta as digital input .. here is the code

Rich (BB code):
banksel TRISA        
movlw 0xFF        
movwf TRISA
Please I need urgent help ..

Thanks in advance to everybody ..
 

cheezewizz

Joined Apr 16, 2009
82
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...
Rich (BB code):
BSF     STATUS, RP0
MOVLW    0x06
MOVWF    ADCON1
 

Thread Starter

Ahmed Adel

Joined May 12, 2008
18
haaaaaaaay guys ..

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