In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to achieve Linux character device control". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Similar to the led light, the device node of the buzzer is in the / dev directory, as shown in the following figure.
The hardware of the buzzer is similar to the led lamp, as shown in the following figure.
As shown in the image above.
The schematic diagram is easy to understand. If the network MOTOR_PWM is high, the L9014 turns on and the buzzer sounds. If the network MOTOR_PWM is low, the L9014 is off and the buzzer is not.
The mode of operation is similar to that of led lights.
Buzzer test routine
Write a simple buzzertest.c file to test the buzzer.
First of all, add the header file, as shown in the following figure, several new library files have been added below, which are commonly used when writing code
For convenience, you can add them directly.
Then the main function is shown in the following figure.
As shown in the code in the figure above. Since there is only one IO, the bottom layer does not judge the third parameter, so it is invalid.
On lines 16-19, there is a simple judgment for the parameter argv [1]. The command can only be 0 or 1.
On lines 21-24, the open function opens the buzzer device node
Line 26, use the ioctl function to operate the buzzer.
On line 27, use the close function to close the device node.
Compile and run the test
Under the Ubuntu system, as shown in the following figure, enter the directory "/ home/linuxsystemcode/charcontrol" created in the previous experiment and copy the source code buzzertest.c into it, as shown in the following figure.
Compile the buzzertest file with the command "arm-none-linux-gnueabi-gcc-o buzzertest buzzertest.c-static", as shown in the following figure, and use the command "ls" to see that the buzzertest executable is generated.
Here we introduce the method of copying code from U disk, which can also be compiled into the file system.
Copy the compiled executable file buzzertest to U disk, start the development board, insert U disk, load U disk, and run the program as follows.
Using parameters 1 and 0, the buzzer will ring. The second parameter doesn't actually work.
As shown in the following figure, using the parameters 0 and 0, the buzzer stops.
17.4 character class ADC A / D conversion
Similar to the led lamp, the device node of the digital-to-analog conversion is also in the / dev directory, as shown in the following figure.
The hardware part of the analog-to-digital conversion is shown in the following figure.
As shown in the image above.
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
The Vadc in the above formula can be read by 4412, and VDD1V8 and R13 are known, so it is easy to find the resistance of R12. As shown in the figure below, there is a real resistance and voltage curve in the ADC section of 4412datasheet.
Here we do a simple conversion of the value.
1.8V corresponds to 10K ohms and the corresponding register value is 0xfff
0V corresponds to 0 ohms and the corresponding register value is 0x0.
Do this with a simple formula that converts the read value r into the resistance value R.
R = r*10000/0xfff, that is to say, R = ritual 10000 compass 4095.
This small formula will be used later in the code.
Analog to digital conversion routine
Write a simple ADC.c file to test the adc driver. First add the header file, as shown in the following figure.
Then the main function is shown in the following figure.
As shown in the code in the figure above.
Line 14, the device node is char * adc = "/ dev/adc".
Line 21, open the device node file.
Line 26, using the read function, assigns the read number to buffer.
Lines 30 and 31, do a simple conversion to convert the read value into a resistance value.
Compile and run the test
Under the Ubuntu system, as shown in the following figure, enter the directory "/ home/linuxsystemcode/charcontrol/" created in the previous experiment to change the source
Copy the code ADC.c into it, as shown in the following figure.
Compile the ADC file with the command "arm-none-linux-gnueabi-gcc-o ADC ADC.c-static", as shown in the following figure, and use the command "ls" to see that the ADC executable is generated.
This paper introduces the method of copying code from U disk, which can also be compiled into the file system. The specific method can be found in section 10.3.5. Copy the compiled executable file open to U disk, start the development board, insert U disk, load U disk, and run the program.
As shown in the following figure, the current resistance can be detected by using the command ". / mnt/udisk/ADC". The middle large print parameter is the value of multiple print registers, which will be introduced in the drive experiment.
After adjusting the sliding resistor, use the test program again, as shown in the following figure, the output value will change.
When the sliding rheostat rotates clockwise, the resistance value decreases to a minimum of 0.
When the sliding rheostat rotates counterclockwise, the resistance value will increase to a maximum of 10K.
This is the end of the content of "how to implement Linux character device Control". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.