Why the data sent is double?

This is a discussion on Why the data sent is double? within the C Programming forums, part of the General Programming Boards category; .......Hello there..i encountered one problem when sending this message...that is when i am sending the putrsUSART("ok"); over to my hyperterminal ...

  1. #1
    CSooi
    Join Date
    Oct 2004
    Posts
    5

    Why the data sent is double?

    .......Hello there..i encountered one problem when sending this message...that is when i am sending the
    putrsUSART("ok");
    over to my hyperterminal from my PICDEM 2 PLUS BOARD in MPLAB ICD 2,the data that i received is ok[00].do you know how to get it send only ok?and when i the second data is send the hyperterminal will be seeing ok[00]ok[00]..and the data keep echoing following the number of ok sent..here i attached on the code for you to have a look.so hope you can help....

    #include <p18f452.h>
    #include <usart.h>
    #include <delays.h>

    char getcharusart()
    {
    // Wait until the byte recieved interrupt flag (RCIF) is set on the interrupt register
    while (!PIR1bits.RCIF)
    continue;

    //Clear the interrupt register until another byte is recieved
    PIR1bits.RCIF = 0;

    //Return the value stored in RCREG, which is the byte that has been recieved
    return RCREG;
    }


    void main(void)
    {
    //port configuration
    TRISCbits.TRISC6 = 0;
    TRISCbits.TRISC7 = 1;

    // configure USART
    OpenUSART( USART_TX_INT_OFF &
    USART_RX_INT_OFF & //usart configuration
    USART_ASYNCH_MODE &
    USART_EIGHT_BIT &
    USART_CONT_RX &
    USART_BRGH_HIGH,25 );



    //All PORTB are outputs
    TRISB = 0;

    //Clear PORTB
    PORTB = 0;

    // while (1)
    {
    //PORTB =getcharusart();
    putrsUSART("ok"); //9600,n,8,1!\r\n");

    }


    }

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Without knowing what those two things are and how they work, we can't help. It looks like the bracketed number might be the number of errors encountered on the last burst or something.

  3. #3
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by ooicheesan
    putrsUSART("ok");
    Meaning:
    "ok" = {'o','k',0};-> zero, the terminating string's char.
    To send ok, the final 0 seems to be sent also.

  4. #4
    CSooi
    Join Date
    Oct 2004
    Posts
    5

    Question the data is double...

    The data that i sent from my board to the VB at comm 1 is double..the char that i am sending out form my board is to clear the timer of my VB as acknowledgement that the byte is received by the board..so since it is quite troublesome to saying how it work...i attached on the Vb code for you to have a look so that you to have a look at my serial communication... hope to hear from you soon..


    'Data Declaration required
    Option Explicit
    'Declare data as global attributes
    Dim byteDataA As Byte
    Dim byteDataB As Byte
    Dim byteDataC As Byte
    Dim sLastSend As String
    Dim bTimerCount As Byte

    Private Sub Check1_Click(Index As Integer)
    'Private data declaration
    Dim temp As Byte


    If Check1(Index).Value = 1 Then
    'Byte Calulation by Or operation
    temp = 2 ^ Index
    byteDataA = byteDataA Or temp
    Else
    'Byte Calculation by Xor and And operation
    temp = 255 Xor 2 ^ Index
    byteDataA = byteDataA And temp

    End If
    'Send data to MSComm port
    Send_Inform "A" & Chr(byteDataA)

    End Sub

    Private Sub Check2_Click(Index As Integer)
    Dim temp As Byte

    If Check2(Index).Value = 1 Then
    'Byte Calulation by Or operation
    temp = 2 ^ Index
    byteDataB = byteDataB Or temp

    Else
    'Byte Calulation by Xor and And operation
    temp = 255 Xor 2 ^ Index
    byteDataB = byteDataB And temp

    End If
    'Send data to MSComm port
    Send_Inform "B" & Chr(byteDataB)

    End Sub

    Private Sub Check3_Click(Index As Integer)
    Dim temp As Byte


    If Check3(Index).Value = 1 Then
    'Byte Calulation by Or operation
    temp = 2 ^ Index
    byteDataC = byteDataC Or temp

    Else
    'Byte Calulation by Xor and And operation
    temp = 255 Xor 2 ^ Index
    byteDataC = byteDataC And temp

    End If
    'Send data to MSComm port
    Send_Inform "C" & Chr(byteDataC)

    End Sub


    Public Sub Send_Inform(sMsg As String)
    'Marked last sent message
    sLastSend = sMsg
    'MSComm output last send Msg
    MSComm1.Output = sLastSend
    'Activate timer
    tmrResponse.Enabled = True

    End Sub



    Private Sub tmrResponse_Timer()
    'Initialize timer to "0"
    tmrResponse.Enabled = False

    'Check byte timer count
    If bTimerCount < 2 Then
    'Send last sent Msg
    Send_Inform sLastSend
    bTimerCount = bTimerCount + 1

    Else
    'Indicate that no reply from hardware after 5000ms
    MsgBox "No responce from the hardware."
    'Reset counter
    bTimerCount = 0


    End If


    End Sub


    Private Sub Form_Load()

    With MSComm1
    'Activate the MSComm port
    If .PortOpen = True Then .PortOpen = False
    'Selecting MSComm Port 1
    .CommPort = 1
    '9600 Baud, No Parity, 8 Data Bits, 1 Stop Bit
    .Settings = "9600,n,8,1"
    'Enable port 1
    .PortOpen = True
    End With

    End Sub
    Private Sub MSComm1_OnComm()
    Dim sTemp As String
    'Enabling MSComm to receive MSg
    Select Case MSComm1.CommEvent
    'COmm Recieve Event
    Case comEvReceive
    'Receive Data at MSComm Port 1
    sTemp = MSComm1.Input
    'Check for "ok"
    If sTemp = "ok" Then
    'If "ok" detected reset Timer count
    tmrResponse.Enabled = False
    bTimerCount = 0

    End If


    End Select
    End Sub

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  4. need some help with last part of arrays
    By Lince in forum C Programming
    Replies: 3
    Last Post: 11-18-2006, 08:13 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21