how to store received values in serial communication ?


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: how to store received values in serial communication ?

    '************************************************* ***************
    '* Name : 7SEG-MULTIPLEXING.BAS *
    '* Author : [ Eng. Mohammad Aqel ] *
    '* Date : 11/9/2007 *
    '************************************************* ***************
    DEFINE OSC 20

    ' Set LCD Data port
    DEFINE LCD_DREG PORTD
    ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 4
    ' Set LCD Register Select port
    DEFINE LCD_RSREG PORTD
    ' Set LCD Register Select bit
    DEFINE LCD_RSBIT 0
    ' Set LCD Enable port
    DEFINE LCD_EREG PORTD
    ' Set LCD Enable bit
    DEFINE LCD_EBIT 1
    ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
    ' Set number of lines on LCD
    DEFINE LCD_LINES 2
    ' Set command delay time in us
    DEFINE LCD_COMMANDUS 2000
    ' Set data delay time in us
    DEFINE LCD_DATAUS 50

    INCLUDE "modedefs.bas"


    ' Set baud rate
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 129 ' 2400 Baud @ 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically

    datain var byte

    SerialData var byte

    COUNTER VAR WORD
    COUNTER1 VAR BYTE
    COUNTER2 VAR BYTE
    ASCII VAR BYTE




    Ser var byte[40]
    Ser1 var byte
    A var byte[5]
    B var byte[5]
    i var byte
    j var byte


    ADCON1 = 6 'PORTA AND e DIGITAL
    TRISC = %10000000 ' PORTC.7 is the RX input
    ' PORTC.6 is the TX output
    TRISB=0
    TRISD=0
    TRISA=0
    PORTD=$FF
    PORTB=0
    A0 var WORD
    A1 var WORD
    A2 var WORD
    A3 var byte
    A4 var byte
    A5 var byte
    A6 var byte

    DEFINE SER2_BITS 4 ' Set Serin2 and Serout2 data bits to 4
    DEFINE SER2_BITS 5 ' Set Serin2 and Serout2 data bits to 5
    DEFINE SER2_BITS 6 ' Set Serin2 and Serout2 data bits to 6
    DEFINE SER2_BITS 7 ' Set Serin2 and Serout2 data bits to 7
    DEFINE SER2_BITS 8 ' Set Serin2 and Serout2 data bits to 8 (default)



    b0 var byte
    num var byte


    Hex_input var byte
    A_D_A VAR WORD [9]

    MAIN:


    'hserin [WAIT( "=" ) ,dec3 a0]
    'Serin2 RX,396,[WAIT("="),dec a0]
    Serin2 RX,396,[WAIT("="),DEC A0]
    Serout2 TX,396,["3: ",DEC A0,13,10]
    Serin2 RX,396,[WAIT("Y-"),DEC A0]
    Serout2 TX,396,["3: ",DEC A0,13,10]
    A3=Ser dig 3
    A4=a0 dig 0
    A5=a0 dig 1
    A6=a0 dig 2



    LCDOUT $fe,$80, dec2 A0
    LCDOUT $fe,$c0, dec A4, dec A5, dec A6



    goto MAIN

    eND



    ----------

    i used pic16f877

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: how to store received values in serial communication ?

    PORTC.7 is the RX input
    ' PORTC.6 is the TX output

    Add to the Variable section of your code to let the compiler know the pins you are using
    RX VAR PORTC.7
    TX VAR PORTC.6


    Or
    Serout2 POTRC.6,396,["3: ",DEC A0,13,10]
    And the same for SERIN2.
    Either way, you need to tell the compiler.


    Why are you adding
    DEFINE SER2_BITS 4 ' Set Serin2 and Serout2 data bits to 4
    DEFINE SER2_BITS 5 ' Set Serin2 and Serout2 data bits to 5
    DEFINE SER2_BITS 6 ' Set Serin2 and Serout2 data bits to 6
    DEFINE SER2_BITS 7 ' Set Serin2 and Serout2 data bits to 7
    DEFINE SER2_BITS 8 ' Set Serin2 and Serout2 data bits to 8 (default)
    Dave
    Always wear safety glasses while programming.

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