Serial Communication Problem


Results 1 to 24 of 24

Threaded View

  1. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Here's something to play with.
    Code:
        '   Program to echo incoming serial data 
        '   Baudrate : 2400 Bauds
        '   Method :   Polling USART interrupts flags
    
        '   Pic Definition
        '   ==============
            ' Using PIC 18F2320 @ 4MHZ and bootloader
            '
            DEFINE LOADER_USED 1
            DEFINE OSC 4
            
        '   Hardware configuration
        '   ======================
            '
            '
            TRISC  = %10000000    ' PORTC.7 is the RX input
                                  ' PORTC.6 is the TX output
        
        '   Serial communication definition
        '   ===============================
            ' Using internal USART and MAX232 to interface to PC
            '
            RCSTA = $90 ' enable serial port, 
                        ' enable continuous receive
                        '
            TXSTA = $24 ' enable transmit, 
                        ' BRGH=1
                        '
            SPBRG = 103 ' set baudrate to 2400                   
            
        '   Alias definition
        '   ================
            '
            '
            RCIF VAR PIR1.5     ' Receive  interrupt flag (1=full , 0=empty)
            TXIF VAR PIR1.4     ' Transmit interrupt flag (1=empty, 0=full)
            OERR var RCSTA.1    ' Overrun error
            CREN var RCSTA.4    ' Continuous receive
                    
        '   Hardware initialisation
        '   =======================
            '
            '
            pause 10 ' safe start-up delay
        
    Main:
        if oerr then  ' Overrun error?
           cren=0     ' clear it
           cren=1
           endif
    
        if RCIF then    ' incomming data?
           TXREG=RCREG  ' take it, send it
           while TXIF=0 ' wait untill transmit buffer is empty
           wend
           endif
        goto main
    the following use HSERIN/HSEROUT statement. Since your PIC have internal USART... why not using it
    Code:
        '   Program to echo incoming serial data 
        '   Baudrate : 2400 Bauds
        '   Method :   Polling USART interrupts flags
    
        '   Pic Definition
        '   ==============
            ' Using PIC 18F2320 @ 4MHZ and bootloader
            '
            DEFINE LOADER_USED 1
            DEFINE OSC 4
            
        '   Hardware configuration
        '   ======================
            '
            '
            TRISC  = %10000000    ' PORTC.7 is the RX input
                                  ' PORTC.6 is the TX output
        
        '   Serial communication definition
        '   ===============================
            ' Using internal USART and MAX232 to interface to PC
            '
            DEFINE HSER_RCSTA 90h ' enable serial port, 
                                  ' enable continuous receive
                                  '
            define HSER_TXSTA 24h ' enable transmit, 
                                  ' BRGH=1
                                  '
            define HSER_SPBRG 103 ' set baudrate to 2400                   
            DEFINE HSER_CLOERR  1 ' automatic clear overrun error  
            
        '   Alias definition
        '   ================
            '
            '
            RCIF VAR PIR1.5     ' Receive  interrupt flag (1=full , 0=empty)
            TXIF VAR PIR1.4     ' Transmit interrupt flag (1=empty, 0=full)
            
        '   Variable definition
        '   ===================
            '
            '
            SerialData var byte
            
        '   Hardware initialisation
        '   =======================
            '
            '
            pause 10 ' safe start-up delay
        
    Main:
        if RCIF then            ' incomming data?
           hserin  [Serialdata] ' take it
           hserout [serialdata] ' send it
           endif
        goto main
    hope this help
    Last edited by mister_e; - 11th May 2005 at 02:41.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Replies: 18
    Last Post: - 4th July 2017, 14:26
  2. serial communication problem
    By kindaichi in forum Serial
    Replies: 13
    Last Post: - 11th March 2010, 16:37
  3. Replies: 5
    Last Post: - 20th March 2006, 01:34
  4. Problem in Serial Communication
    By uuq1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th June 2005, 07:17
  5. Replies: 8
    Last Post: - 11th November 2004, 20:08

Members who have read this thread : 2

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