Serial from PC into an Array


Results 1 to 8 of 8

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    yep i agree. BTW i have few minutes to spend on it and here's an update tested @19200 bauds @ 4MHZ
    Code:
        '   Program to echo incoming serial data string
        '   Baudrate : 19200 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=12  ' set baudrate to 19200 Bauds                  
            
        '   Alias definition
        '   ================
            '
            '
            RCIF   VAR PIR1.5  ' Receive  interrupt flag (1=full , 0=empty)
            TXIF   VAR PIR1.4  ' Transmit interrupt flag (1=empty, 0=full)
            CREN   var RCSTA.4 ' Receiver enable bit
            OERR   var RCSTA.1 ' Overrun  error
            
        '   Variable definition
        '   ===================
            '
            '
            SerialString var byte[40]
            Counter      var byte
            Success      var bit
            i            var byte
            temp         var byte
            header       var bit
            
        '   Hardware initialisation
        '   =======================
            '
            '
            pause 100 ' safe start-up delay
            clear
    
    Main:
       IF oerr then
          cren=0
          cren=1
          endif
          
       if RCIF then                ' incomming data?
          I=RCREG                  ' take it
            
          if header then
              if i ="L" then discard  ' is it the end?
              serialstring[counter]=i ' Store into the array
              counter=counter+1       '
              endif
    
          if i ="!" then header=1 ' is it the header character?          
          Discard:
              while RCIF
                    temp=RCREG
                    wend
        
              if i="L" then 
                 success=1 ' Yeah i got a valid string
                 header=0
                 endif
          endif
      
       if success then
          cren=0  ' Disable Receiver
          hserout ["String received : ",str serialstring\counter,13,10,_
                   "Character count : ", dec counter,13,10]
          cren=1  ' Enable receiver
          clear
          endif
       goto main
    Last edited by mister_e; - 13th May 2005 at 19:38.
    Steve

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

Similar Threads

  1. PIC18F4680 to PC via MAX232 (RS232 serial) no output
    By opticsteam1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th April 2008, 20:39
  2. interfacing to the pc serial port
    By kelangfei in forum General
    Replies: 4
    Last Post: - 7th October 2007, 22:35
  3. PC serial port funny
    By nicjo in forum Serial
    Replies: 13
    Last Post: - 6th February 2007, 05:34
  4. Replies: 2
    Last Post: - 28th April 2006, 12:10
  5. Interrupt and Serial communication to PC.
    By obaskirt in forum mel PIC BASIC
    Replies: 2
    Last Post: - 17th June 2005, 20:01

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