There are four small LED lights on the tianembedded 2440 Development Board. The random band test software is developed using C ++. However, I prefer the C # language, so through the analysis of the BSP package of tq2440, the four small LED lights are controlled through gpio ports. Therefore, as long as the C # is used to control the gpio port, it can make the LED light.
The key code is as follows:
First, declare two windowce API function calls.
1st API declarations, which were found in the C # Serial Communication code and could not be used for gpio port control. (If you have time to learn it, post the code for your reference)
[Dllimport ("coredll. dll")]
Private Static extern intptr createfile (
String lpfilename,
Uint dwdesiredaccess,
Int dww.mode,
Int lpsecurityattributes,
Int dwcreationdisposition,
Int dwflagsandattributes,
Int htemplatefile
);
2nd: device I/O control, which is commonly used in Windows XP/2000 and also available in windows.
[Dllimport ("coredll. dll", entrypoint = "deviceiocontrol", setlasterror = true)]
Internal static extern int deviceiocontrol (
Intptr hdevice,
Int dwiocontrolcode,
Byte [] lpinbuffer,
Int ninbuffersize,
Byte [] lpoutbuffer,
Int noutbuffersize,
Ref int lpbytesreturned,
Intptr lpoverlapped );
Note: If you want to use the preceding APIs in a Win2000/XP... environment, declare that you want to use kernel32.dll.
After the API statement is complete, let's talk about controlling the gpio port of the LED light:
Supported CD _ 0829/tq2440_cd/wince resources/wince source code/BSP package/tq2440/src/Drivers/gpiodriver
The following shows the gpio driver code. You can find
# Define io_ctl_gpio_detail on 0x01
# Define io_ctl_gpio_2_on 0x02
# Define io_ctl_gpio_3_on 0x03
# Define io_ctl_gpio_4_on 0x04
# Define io_ctl_gpio_all_on 0x05
# Define io_ctl_gpio_0000off 0x06
# Define io_ctl_gpio_2_off 0x07
# Define io_ctl_gpio_3_off 0x08
# Define io_ctl_gpio_4_off 0x09
# Define io_ctl_gpio_all_off 0x0a
These macro definitions are consistent with those in the VC ++ instance of the Development Board.
The VC ++ example program in the Development Board is: L:/tq2440/tq2440 supporting CD _ 0829/tq2440_cd/wince resource/wince source code/application/gpio_test
It is not hard to see: On is LED light, off is led out.
Therefore, in C #, you can use the following code to control the LED light
Intptr gpiodriver = createfile ("gio1:", generic_read | generic_write, 0, 0, open_existing, 0, 0 );
If (gpiodriver = (intptr) (-1 ))
{
MessageBox. Show ("An error occurred while enabling the gpio device! ");
}
Else
{
Int bytesreturned = 0;
Deviceiocontrol (gpiodriver, 0x02, null, 0, null, 0, ref bytesreturned, intptr. Zero );
}
Note: 0x02 is used to make the LED shine. If led2 needs to be extinguished
Deviceiocontrol (gpiodriver, 0x07, null, 0, null, 0, ref bytesreturned, intptr. Zero );
If you want to extinguish all:
Deviceiocontrol (gpiodriver, 0x0a, null, 0, null, 0, ref bytesreturned, intptr. Zero );
If you are interested, you can package the above Code to do more control experiments. For a detailed explanation of the code above, we will continue later...
So far today, I will take the exam in a few days. I have to review it .... After the test, the C # In gpio control is described in detail.