|
|
View previous topic :: View next topic |
Author |
Message |
amal
Joined: 24 Aug 2005 Posts: 2 Location: vietnam
|
PIC and Computer interaction |
Posted: Wed Sep 07, 2005 8:28 am |
|
|
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
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Sep 07, 2005 11:02 am |
|
|
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
|
|
Posted: Mon Sep 12, 2005 5:31 am |
|
|
Sorry about my late reply.
Your information is really helpful. Thanks for showing me the way!!! |
|
|
|
|
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
|