Any one know how my program should be like when i need to pass in information for example "a" and display it in a display box... through serial communication.
You can set up the serial port of the microcontroller (lots of example programs use it so that should be no problem) and use a function like scanf() or getchar() (both from STDIO.H) to load a character into the microcontroller via the COM-port. It could look like:
unsinged char first, second, third; scanf("%c %c %c",&first, &second, &third);
do you know where i can find programs that set up microcontroller??
I don't know what microcontroller you use. But try the File Download Area (http://www.keil.com/download/). Just look through the example programs. Greets Laurens
hi, i added codes like read, write into the program and when the serial cable is not connected to the mircocontroller, the program works. but when i connect to the mc, it hangs. why is it so?
That's hard to tell. You should be more specific. What microcontroller do you use? How do you debug? Do you have a JTAG interface?
1) WHAT microcontroller 2) added codes like read, write into the program and when the serial cable is not connected to the mircocontroller WHAT program? PC program or uC program 3) i need to pass in information for example "a" and display it in a display box WHAT is in the "display box" More words does not make you appear "stupid" It makes you appear "coherent" If you want hep, you need to be specific WHAT you need help with. Guesses will most likely lead you astray. Erik
1) using vc++ 2) written codes like read and write
void CSerialComm::Send(HANDLE *pComm, CString str) { unsigned char StopByte=0x1; unsigned long int n_out; str = "0x80"; WriteFile(*pComm, str, str.GetLength(),&n_out , NULL); WriteFile(*pComm, &StopByte, 1, &n_out, NULL); } void CSerialComm::Receive(HANDLE *pComm, CString str1) { char cRxByte; DWORD dwRead; while(cRxByte!=0x1) { ReadFile(*pComm, &cRxByte, 1, &dwRead, NULL); str1+=cRxByte; } MessageBox("Acknowledge Received"); // MessageBox(str1); } void CSerialComm::initComm(HANDLE *pComm) { *pComm = CreateFile("COM1:", GENERIC_WRITE|GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (*pComm ==INVALID_HANDLE_VALUE) { //MessageBox("Please input value !"); } //FillMemory(&dcb, sizeof(dcb), 0); dcb.DCBlength = sizeof(dcb); dcb.BaudRate = CBR_9600; dcb.fBinary = TRUE; dcb.fDtrControl = DTR_CONTROL_DISABLE; dcb.fRtsControl = RTS_CONTROL_DISABLE; dcb.ByteSize = 8; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; if (!SetCommState(*pComm, &dcb)) { //MessageBox("Wrong Port"); } }
Use a standalone terminal or a terminal emulation program and verify that you can communicate with the MCU system. After doing that, if your PC program does not run properly, you where to look and can ask PC questions on forums and newsgroups related to PC programming. By the way, GetCommState() before you go messing with a DCB to then submit to SetCommState().
sorry, i don't quite understand what you are trying to mean...
"sorry, i don't quite understand what you are trying to mean..." You say, when you connect the PC and microcontroller to gether, it doesn't work. What you neeed to determine is why it doesn't work - then you can fix it! There are 3 possibilities: 1. There's a problem at the PC end; 2. There's a problem at the microcontroller end; 3. There's problems at both ends! Dan's suggestion is to help you check if the microcontroller end is working: by removing your PC software from the equation, and using a terminal emulator instead, you can verify that the microcontroller end is working. You should start by running the microcontroller software in the simulator - this eliminates any problems due to your hardware. Set the simulator up so that it uses a PC COM port for its serial IO (see the Manual). In the simulator, you can single-step, examine variables, etc, etc...
is there some one that can help me write a program for read and write?? using Visual C++
You should use MSComm ActiveX control (mscomm32.ocx) under Visual C++ which is quite easy to use. I could send you a sample if you want to. Jean-Pierre
none of my beeswax, but what does this have to do with Keil software? Are there no websites for PC programming. so, 1) this is not the place and 2) the right place will, probably, have more answers. Erik
"is there some one that can help me write a program for read and write?? using Visual C++" You need to do some serious study! This is not something that can be taught in just a few brief posts on a forum like this! (and, anyhow, this forum is for Keil - not Microsoft tools!) There are hundreds of books available on "Teach Yourself MSVC Programming", or you could look for taught courses in your locality.
"Are there no websites for PC programming." For all Microsoft development issues, your first port of call should be the MS Developer Network, MSDN: http://msdn.microsoft.com/
Teach Yourself C++ in 24 Hours: Complete Starter Kit Jessie Liberty, David Horvath http://www.amazon.co.uk/exec/obidos/ASIN/0672326817/qid=1132708016/sr=2-1/ref=sr_2_11_1/203-5826643-3305507