Xunwei 4412 Development Board Linux Character Device Control (2)

17.3 Character Buzzer Buzzer
Similar to led lights, the device node of the buzzer is also in the /dev directory, as shown in the figure below.

The hardware of the buzzer is similar to the LED light, as shown in the figure below.

As shown in FIG.
Schematic readily appreciated, if the network MOTOR_ the PWM  is high, the ON L9014, buzzer, MOTOR_PWM if the network is low, the L9014 off, the buzzer will not sound.
The operation method is similar to that of small led lights.
Buzzer test routine
Write a simple buzzertest.c file to test the buzzer.
First add the header file, as shown in the figure below. Several new library files are added below. Generally, the following ones are commonly used. When writing code
, you can add them directly for convenience.

Then the main function is shown in the figure below.

As shown in the code above. Since there is only one IO, the bottom layer does not judge the third parameter, so it is invalid
. Lines 16-19, there is a simple judgment on the parameter argv[1], the command can only be 0 or 1.
Line 21-24, open function opens the buzzer device node
Line 26, use ioctl function to operate the buzzer.
On line 27, use the close function to close the device node.
Compile and run the test
In the  Ubuntu  system, as shown in the figure below, enter the directory "/home/linuxsystemcode/charcontrol" created in the previous experiment, and copy the source code buzzertest.c into it, as shown in the figure below.

Use the command "arm-none-linux-gnueabi-gcc -o buzzertest buzzertest.c -static" to compile the buzzertest file, as shown in the figure below, use the command "ls" to see that the buzzertest executable file is generated.

Here is how to copy the code from the USB flash drive, which can also be compiled into the file system.
Copy the compiled executable file buzzertest to a U disk, start the development board, insert the U disk, load the U disk, and run the program as follows.
Using parameters 1 and 0, the buzzer will sound. The second parameter does not actually work.

As shown in the figure below, using parameters 0 and 0, the buzzer will stop sounding.

17.4 Character  ADC   analog-to-digital conversion
Similar to led lights, the device node for digital-to-analog conversion is also under the /dev directory, as shown in the figure below.

The hardware part of analog to digital conversion is shown in the figure below.

As shown in FIG.
The XadcAIN0 network can read the current input voltage . When the sliding rheostat R moves, the resistance  R12 between 1 and 2 changes. The maximum resistance of the sliding rheostat is R13, and then the voltage Vadc=R12*VDD1V8_EXT/R13. In the
above formula, Vadc can pass 4412 After reading it out, VDD1V8 and R13 are known, then it is easy to find the resistance of R12. As shown in the figure below, there are real resistance and voltage curves in the ADC chapter of the 4412datasheet.

Here is a simple conversion of the value,
1.8V corresponds to 10K ohms, and the corresponding register value is 0xfff;
0V corresponds to 0 ohm, and the corresponding register value is 0x0.
This is a simple formula to convert the read value r into the resistance value R.
R = r*10000/0xfff, that is, R = r*10000/4095.
This small formula will be used in the following code.
Analog-to-digital conversion routines
Write a simple ADC.c file to test the adc driver. First add the header file, as shown in the figure below.

Then the main function is shown in the figure below.

As shown in the code above.
On line 14, the device node is char *adc = "/dev/adc".
On line 21, open the device node file.
In line 26, use the read function to assign the read number to the buffer.
On lines 30 and 31, do a simple conversion to convert the read value into a resistance value.
Compile and run the test
In the Ubuntu system, as shown in the figure below, enter the directory "/home/linuxsystemcode/charcontrol/" created in the previous experiment and
copy the source code ADC.c into it, as shown in the figure below.

Use the command "arm-none-linux-gnueabi-gcc -o ADC ADC.c -static" to compile the ADC file, as shown in the figure below, use the command "ls" to see that the ADC executable file is generated.

Here is the method of copying code from U disk, which can also be compiled into the file system. For the specific method, refer to section 10.3.5. Open the compiled executable file, copy it to the U disk, start the development board, insert the U disk, load the U disk, and run the program.
As shown in the figure below, use the command "./mnt/udisk/ADC" to detect the current resistance value. The large print parameter in the middle is the value of the multi-print register, which will be introduced in the driving experiment.

After adjusting the sliding resistor, use the test program again, as shown in the figure below, the output value will change.

When the sliding rheostat rotates clockwise, the resistance value will decrease, and the minimum value is 0; when the
sliding rheostat rotates counterclockwise, the resistance value will increase, and the maximum value is 10K.

 

Guess you like

Origin blog.csdn.net/mucheni/article/details/114583773