How to configure UART with 16F877A

Discussion in 'Embedded Systems and Microcontrollers' started by waseem1, Mar 26, 2010.

  1. waseem1

    Thread Starter New Member

    Mar 26, 2010
    7
    0
    I have a project wireless circuit having transmitter and receiver by using XBee for wireless. The protocol used for communicate the PIC 16F877A and the XBee is UART. And I wrote my program in assembly languge and I don't know the correct way for the UART configuration so could any one help to run my project.

    this is my program for TX
    include <p16f877a.inc>
    COUNT1 equ H'20'
    COUNT2 equ H'21'
    COUNT3 equ H'22'
    COUNT4 equ H'23'
    Init
    bsf STATUS,RP0 ;Move to Bank1
    movlw b'11111111'
    movwf TRISA ;Set port A as input
    movlw b'00000000'
    movwf TRISB ;Set port B as output
    movlw b'00000000'
    movwf TRISC ;Set port C as output
    movlw b'00000000'
    movwf TRISD ;Set port D as output
    movlw b'00000000'
    movwf TRISE ;Set port E as output

    bcf STATUS,RP0 ;Return to Bank0
    clrf PORTA
    clrf PORTB
    clrf PORTC
    clrf PORTD
    clrf PORTE
    bcf TXSTA,TX9 ;Selects 8-bit transmission
    bsf TXSTA,TXEN ;Transmit Enable bit
    bcf TXSTA,SYNC ;Asynchronous mode select
    bsf TXSTA,BRGH ;High Baud Rate Select bit
    bcf TXSTA,TRMT ;Transmit Shift Register Status bit
    start

    btfsc PORTC,7
    goto powerON
    goto powerfail
    powerfail
    bsf PORTC,6 ;send data to transmitter
    bsf PORTD,1 ;switch ON alarm
    goto start

    powerON
    bcf PORTC,6 ;power resume stop sending data for transsmitter
    bcf PORTD,1 ;switch off alarm
    goto start

    Delay ;a delay subroutine of around 1 sec.
    movlw d'239'
    movwf COUNT3
    end
     
  2. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,750
    759
    Did you check the PIC datasheet.
    Everything is explained in it
     
  3. waseem1

    Thread Starter New Member

    Mar 26, 2010
    7
    0
    I checked the datasheet I got only the configration but how to do it I don't know. you can see above what i have done so could any one tell me the correct way to do the configuration in the program
     
  4. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,750
    759
    that is not ur whole asm.
    where's the config statement.
    Post all and then someone will take a good look at it.
    Otherwise ur question will get ignored.

    If you are asking for help, provide every info.
    And also properly quote the coding
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Please read section 10.1. USART Baud Rate Generator(BRG) in the data sheet;)
     
  6. waseem1

    Thread Starter New Member

    Mar 26, 2010
    7
    0
    Thanks for your reply Iam using 16MHz oscillator. I read the datasheet for configuration but still I don't know how to make the configuration in the program. So could you please help me.
     
  7. waseem1

    Thread Starter New Member

    Mar 26, 2010
    7
    0
    could you please tell me how can i do that in assembly, what I want only send 1 or 0 from XBee transmitter to XBee receiver.
    what i have done for receiver
    include <p16f877a.inc>
    COUNT1 equ H'20'
    COUNT2 equ H'21'
    COUNT3 equ H'22'
    COUNT4 equ H'23'
    Init
    bsf STATUS,RP0 ;Move to Bank1
    movlw b'11111111'
    movwf TRISA ;Set port A as input
    movlw b'00000000'
    movwf TRISB ;Set port B as output
    movlw b'00000000'
    movwf TRISC ;Set port C as output
    movlw b'00000000'
    movwf TRISD ;Set port D as output
    movlw b'00000000'
    movwf TRISE ;Set port E as output

    bcf STATUS,RP0 ;Return to Bank0
    clrf PORTA
    clrf PORTB
    clrf PORTC
    clrf PORTD
    clrf PORTE
    bsf RCSTA,SPEN ;Serial port enabled (configures RC7/RX/DT and RC6/TX/CK pins as serial port pins)
    bcf RCSTA,RX9 ;Selects 8-bit reception
    bsf RCSTA,CREN ;Enables continuous receive
    bcf RCSTA,FERR ;No framing error
    bcf RCSTA,OERR ;No overrun error

    start

    btfss PORTC,7
    goto powerON
    goto powerfail
    powerfail
    bsf PORTD,0 ;turn on led
    bsf PORTD,1 ;alarm switch on
    bsf PORTD,3 ;energize relay to start timer
    goto start

    powerON
    bcf PORTD,0 ;turn off led
    bcf PORTD,1 ;alarm switch off
    bcf PORTD,3 ;de-energize timer relay
    goto start

    Delay ;a delay subroutine of around 1 sec.
    movlw d'239'
    movwf COUNT3
    end
    how can i do the that configuration for the transmitter and receiver if the masseage only 1 or 0?
     
  8. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,750
    759
    U are using MPLAB IDE. right.
     
  9. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,750
    759
    Above is statements you will need in your program when you compile the ASM.
     
  10. waseem1

    Thread Starter New Member

    Mar 26, 2010
    7
    0
    thanks for your cooperating could you please explain to me what is that?
    Iam using MPLAP IDE v7.42
     
  11. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,750
    759
    Download V8.43
     
  12. waseem1

    Thread Starter New Member

    Mar 26, 2010
    7
    0
    what about the configuration?
     
  13. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,750
    759
    It will be in the MPASM tool suite.
    You should follow the Installation as stated in the website.
    All the .inc Files will then be installed.
    Read the help file to preserve the .inc and tempo files.
    These files tend to get over written if you donno what you are doing.
    If over written, you might need to reinstall them again.
     
Loading...