Published:2011/8/15 22:40:00 Author:Amy From:SeekIC
Paul Goossens
Get to work with Word
In the June edition of Elektor Electronics we showed how the well-known word processor MS-Word could also be used to write your own programs. Since most Windows users have a copy of this word processor, it made sense to show you a simple example, written using Word. We have of course kept this example fairly simple and didn’t use any arrays when communicating with the DLL!
The required file is part of the project software (order code 040334-11) and can be found in the folder ’Word example’. When you open this document you may, depending on the security settings of Word, get a question asking if you want to use macros in this document. You should answer this question with ’yes’, otherwise the example won’t work.
You should then see the document on the screen as shown in Figure 5. When you press the top button the software searches for the interface. The box next to this button shows whether the interface has been found or not.
Before we can use the interface, it must first be opened. This requires a mouse click on the button ’Open interface’. Once you have finished using the interface, it should be closed with a click on the button ’Close interface’. The result of a click on these two buttons can be seen on the associated yellow pane.
The next two buttons are used to turn the LEDs on and off (you have of course built and connected the circuit shown in Figure 4, haven’t you?). You can obviously tell from the LEDs on the module if the data was successfully sent, but as you may have gathered, this is also shown in the box to the right of these buttons.
The final button is used to show the status of the inputs of the PCF8574. The value returned by the PCF8574 is shown in the window to the right of this button.
A more detailed explanation is given in the sidebar for ’Using the DLL without arrays’. This sidebar and the source code of the Word document should be enough for a programmer to understand how it all works.
Delphi
Our second example is a very simple application written in Delphi. A question we’re sometimes asked is why we use the Delphi language so often in our examples. The reason this programming language is so useful for examples is that it is derived from Pascal and easy to follow. A C programmer should also be able to follow it without problems. The opposite is not true, since a Pascal programmer would have great difficulty in following a C program.
The files for this example can be found in the folder ’Delphi example’. The source code has been kept as compact as possible, which resulted in a single procedure {Timer 1 Timer) for all communication with the interface. This procedure is also responsible for detecting and opening the interface. Immediately afterwards the program reads and writes to the PFC8574, which you had already connected to the I2C bus, of course!
We would like to reassure you that it’s not a problem if you open the interface as soon as your program starts and if you close it when the program finishes. In this case we did this in a timer routine that is called twice a second. You can therefore connect and disconnect the USB interface at will while the program runs.
Follow-up
This edition of Elektor Electronics also contains an application for this interface, where we can control various peripherals (see ’I2C Home Bus’). It is also possible to design your own modules and to control them using this interface. You will of course need some programming experience under Windows for this.
Reprinted Url Of This Article: http://www.seekic.com/blog/project_solutions/2011/08/15/USB_Isup2;C_INTERFACE_I_square_C_rules…_4.html
Print this Page | Comments | Reading(1643)
Author:Ecco Reading(32820)
Author:Ecco Reading(3526)
Author:Ecco Reading(3246)
Author:Ecco Reading(3801)
Author:Ecco Reading(5331)
Author:Ecco Reading(3315)
Author:Ecco Reading(3462)
Author:Ecco Reading(3604)
Author:Ecco Reading(4009)
Author:Ecco Reading(3807)
Author:Ecco Reading(3748)
Author:Ecco Reading(3780)
Author:Ecco Reading(6094)
Author:Ecco Reading(3764)
Author:Ecco Reading(4579)