UART.bas getting weird symbol???


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2007
    Posts
    10

    Default UART.bas getting weird symbol???

    Im using PIC 16F877A with 20MHZ crystal

    and the UART.bas
    ================================================== ==================
    define OSC 20

    B1 var byte

    TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
    SPBRG = 25 ' Set baud rate to 2400
    RCSTA = %10010000 ' Enable serial port and continuous receive
    TXSTA = %00100000 ' Enable transmit and asynchronous mode

    'Echo received characters in infinite loop
    loop: Gosub charin ' Get a character from serial input, if any
    If B1 = 0 Then loop ' No character yet

    Gosub charout ' Send character to serial output
    Goto loop ' Do it forever

    ' Subroutine to get a character from USART receiver
    charin: B1 = 0 ' Preset to no character received

    If PIR1.5 = 1 Then ' If receive flag then...
    B1 = RCREG ' ...get received character to B1

    'high PORTB.5
    'pause 200
    'low PORTB.5
    'pause 200
    Endif

    ciret: Return ' Go back to caller

    ' Subroutine to send a character to USART transmitter
    charout: If PIR1.4 = 0 Then charout ' Wait for transmit register empty

    TXREG = B1 ' Send character to transmit register

    'high PORTB.4
    'pause 200
    'low PORTB.4
    'Pause 200

    Return ' Go back to caller
    ================================================== =================

    However what ever i type in like ABCD then the HYPERTERMINAL will return back some funny symbol can anyone help me???

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    Try your code with a 4MHz Xtal and it will (most likely) work. Because you are using a 20 MHz Xtal and not a 4 MHz Xtal, you will need to change your SPBRG value - see Table 10.3 in the datasheet for the 877A.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Aug 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    thx alot. I will try to change the SPBRG to 129 for 2400 baud rate (20MHZ XTAL).

  4. #4
    Join Date
    Aug 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Thx paul borgmeier for pointing out my careless mistake. Now everything is working fine

Similar Threads

  1. DT's instant interupts compile problem
    By comwarrior in forum General
    Replies: 4
    Last Post: - 18th October 2009, 19:30
  2. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  3. 16f877 and ps/2 keyboard error???
    By boraciner in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th July 2009, 08:14
  4. STATUS re-curtain W
    By zugvogel1 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th February 2005, 15:21
  5. Proton development board with Picbasic
    By pjsmith in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th July 2004, 22:19

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts