C++ part 1
1 the simplest RS232 only TX program


Create Your own MFC Dialog Project
Insert a EditControl and a Button
Add files CommCtrl.cpp and CommCtrl.h to your project

If you have problems download the complete project
download source and EXE for Visual C++.Net
The EXE is in the "Release" directory

Compiled with Visual C++.Net

You can use CommCtrl.cpp and *.h for Visual C++ 6.0 too.
 RS232 only TX more sofisticated


add another button
add CR Carriage Return and LF Line Feed to STRING
Send this string over RS232

If you have problems download the complete project
download source and EXE for Visual C++.Net
The EXE is in the "Release" directory

Compiled with Visual C++.Net

You can use CommCtrl.cpp and *.h for Visual C++ 6.0 too.
RS232 RX and TX communication


The receiver routine is added to file CommCtrl.cpp

Press the RX-button and read the contents of RS232 RX buffer.
If you need a more sofistcated receiver routine have a look to example nr 6
download source and EXE for Visual C++.Net

Compiled with Visual C++.Net

You can use CommCtrl.cpp and *.h for Visual C++ 6.0 too.
RS232 serial communication in hex- and textmode
RS232 draw received bytes
RS232 send one byte every second
RS232 open COM1 COM2 COM3 COM4

download the exe
download the C-sourcefiles for this 5 windows
the first window is a dialog window (parent) with 4 kind windows IDD_COM1, IDD_COM2 a.s.o.

expand the program
we insert now SerialCtrl.cpp and SerialCtrl.h without a class (old C)
the kind windows needs two WM_MESSAGES:
 WM_INITDIALOG function OnInitDialog  (to open the COM port)
 WM_TIMER      function OnTimer       (to read every 50 msec the COM port)



I don't have COM3 or COM4 on my PC
You can connect PIN3 an PIN2 from your serial (9 DSUB) connector.
If you connect COM1 with COM2 you must invert PIN3 and PIN2
download the exe
download the C-sourcefiles for the complete program
Compiled with Visual C++ 6.0
2 RS232 connected with a Modem

Send text data and receive text data from a modem.
download source with EXE
Compiled with Visual C++ 6.0

void CRs232aDlg::OnTimer(UINT nIDEvent) 
{
unsigned char buf[500];
int xx,index;

  if(nIDEvent==1)
  {
   xx = ReadRs232Input(buf, COM1);
   if(xx)
   {
    index=0; 
    while(xx--)  m_strEditRead += buf[index++];
    UpdateData(false);
   }
  }
 CDialog::OnTimer(nIDEvent);
}

There is a periodically readout of the input buffer of RS232 with a TIMER-Function.
RS232 connected with a Modem

Send text data and receive text data from a modem with LF detect.
download source with EXE
Compiled with Visual C++ 6.0

void CRs232aDlg::OnTimer(UINT nIDEvent) 
{
unsigned char buf[500];
int xx,index;

  if(nIDEvent==1)
  {
   xx = ReadRs232Input(buf, COM1);
   if(xx)
   {
   index=0;
   
    while(xx--) {  m_strEditRead   += buf[index];
		   RxBuffer[iRxIndex++] = buf[index];
		   if(buf[index] == LF) LineFeedDetected();
		   index++;
		}

   
	UpdateData(false);
   }
  }
 CDialog::OnTimer(nIDEvent);
}

void CRs232aDlg::LineFeedDetected()
{
CString str;
RxBuffer[iRxIndex]=0;  // end of string; now you can evaluate this string 
iRxIndex=0;

str.Format("LineFeed%c%c",CR,LF);
m_strEditRead += str;
}
There is a periodically readout of the input buffer of RS232 with a TIMER-Function.
In the function "LineFeedDetected()" you can evaluate the content of RxBuffer
RS232 Modem state_machine


download source with EXE
Compiled with Visual C++ 6.0


To control a Modem we need automatics steps. One solution is a state machine. This is an example with six states.
Send ATZ with CarriageReturn and LineFeed, the modem answers with ATZ CR LF followed with OK CR LF.
Every time we receive a LF the input string is checked.
  GSM-MODEM terminal program
3 LPT: read and write to parallel port

download the EXE
download the driver GIVEIO.SYS

download the complete C-sourcefiles

Compiled with Visual C++ 6.0

The driver GIVEIO.SYS must be in the root directory c:\
to install this driver you must have administrator rigths
if you have an error in attempt to write to LPT restart the program
The output byte toggles only from 0xAA to 0x55
3.01 LPT: flashing light on parallel port

download the EXE and source
download the complete C-sourcefiles

Compiled with Visual C++ 6.0

The driver GIVEIO.SYS must be in the root directory c:\
to install this driver you must have administrator rigths

3.01 LPT: flashing light on parallel port

download the EXE and source
download the complete C-sourcefiles

Compiled with Visual C++ 6.0

The driver GIVEIO.SYS must be in the root directory c:\
to install this driver you must have administrator rigths

7 Exercises and training programs

Exercises to learn hex and binary arithmetic
The programs can print a DINA4 page with exercises without solutions,
Pressing the button “F” the solutions are displayed.
If you have 20 students the values for every student are different.
Try it out and give me a feedback.

You can download only the EXE or the complete source files
EXE-FILE: BITCHANGE.ZIP Sourcefile: bitchange.zip

EXE-FILE: BINHEX.ZIP Sourcefile: binhex.zip

Compiled with Visual C++ 6.0
8) USB Control program


Under construction

The program on 68HC908JB is made in assembler and I have made now
my "own" driver (a derivate from Win DDK examples driver),
I will explain all the project from assembler, driver and application
software

Change to USB page