CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC and Computer interaction

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
amal



Joined: 24 Aug 2005
Posts: 2
Location: vietnam

View user's profile Send private message

PIC and Computer interaction
PostPosted: Wed Sep 07, 2005 8:28 am     Reply with quote

Hello!!
I try to use PC to control my PIC, but i don't know how to make my own interface (a program on PC to control PIC). Somebody can tell me some tips to write a program to control serial port or parallel port (with C or VB...)? Thanks
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Wed Sep 07, 2005 9:08 am     Reply with quote

I/O port programming in windows is non-trivial, even for console applications. Many folks just use a terminal emulation like hyperterminal to talk directly with the serial port.

If you want to use C++, I'd download a library like http://www.codeproject.com/system/serial.asp or
http://www.marshallsoft.com/
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Sep 07, 2005 11:02 am     Reply with quote

sseidman wrote:
I/O port programming in windows is non-trivial, even for console applications. Many folks just use a terminal emulation like hyperterminal to talk directly with the serial port.

If you want to use C++, I'd download a library like http://www.codeproject.com/system/serial.asp or
http://www.marshallsoft.com/


I/O port programming in windows is trivial, especially with VB. VB provides the MSCOMM control. You can find tons of examples doing this.

To do it in Visual C++ isn't that bad either. Here's a snippet from my bootloader app
Code:

/****************************************************************************

    FUNCTION:   EnterBootMode

    PURPOSE:   This function is provided to open communications to the
            PIC through a serial port and place the PIC into bootmode.
            The function returns a handle to the opened port or returns a negative number on an error.

****************************************************************************/
INT APIENTRY EnterBootMode(LPSTR ComPort, DWORD BitRate, DWORD ReadTimeOut)
{
   HANDLE hComm;
   DCB dcb = {0};
   COMMTIMEOUTS CommTmOut = {0};
   
   // Get a handle to the port.
   hComm = CreateFile( ComPort, 
                       GENERIC_READ | GENERIC_WRITE,
                       0,
                       NULL,
                       OPEN_EXISTING,
                       FILE_ATTRIBUTE_NORMAL,
                       0);
   if (hComm == INVALID_HANDLE_VALUE)
      return -1;

   // Get the current state of the port
   FillMemory(&dcb, sizeof(dcb), 0);

   if (!GetCommState(hComm, &dcb)){
      return -1;
   }
   else{
      dcb.BaudRate = BitRate;
      dcb.Parity = NOPARITY;
      dcb.StopBits = ONESTOPBIT;
      dcb.fDtrControl = DTR_CONTROL_DISABLE;
      dcb.fRtsControl = RTS_CONTROL_DISABLE;
      dcb.fOutX = FALSE;
      dcb.fInX = FALSE;
      dcb.fOutxCtsFlow = FALSE;
      dcb.fOutxDsrFlow = FALSE;
      dcb.ByteSize = 8;
   }
      
   if (!SetCommState(hComm, &dcb))
      return -1;


   //Set the timeout conditions
   if (!GetCommTimeouts(hComm, &CommTmOut)){
      return -1;
   }
   else{
      CommTmOut.ReadIntervalTimeout = MAXDWORD;
      CommTmOut.ReadTotalTimeoutMultiplier = MAXDWORD;
      CommTmOut.ReadTotalTimeoutConstant = ReadTimeOut;
   }

   if (!SetCommTimeouts(hComm, &CommTmOut))
      return -1;

   //Send the boot command
   if (SendText(hComm, BootCmd, SIZEOFBOOTCMD) != SIZEOFBOOTCMD)
   {
      CloseHandle(hComm);
      return -1;
   }
    CloseHandle(hComm);
    return 0;
}
amal



Joined: 24 Aug 2005
Posts: 2
Location: vietnam

View user's profile Send private message

PostPosted: Mon Sep 12, 2005 5:31 am     Reply with quote

Sorry about my late reply.
Your information is really helpful. Thanks for showing me the way!!! Razz
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group