Section 8 Chapters make the Development Board sound, buzzer drive
Experience
Create a makefile file under the directory
Run the make clean command to make sure that you compile some of the generated project files, execute the Make command, and recompile the driver. Copy the compiled generated Buzzer.ko kernel image file, adb push buzzer.ko/fpga/moudles
Then insert the kernel image file into the system, Insmod Buzzer.ko, and load the device driver, Mknod/dev/buzzer C 248 0
Now it is possible to write C + + files directly in the library layer to invoke this driver, this can install the NDK compilation environment in Ubuntu, create a new buzzer file, compile and build a library file, so you can directly at the application layer to use the library provided by the JNI method, the invocation will be more simple, Of course this call way Google does not advocate, I just want to show this kind of calling method here
Construct a JNI project and create a new BUZZER.C source file
The NDK compiles, generates libbuzzer.so, and the library can be called directly at the application layer
- #include <reg52.h>
- Sbit BUZZ = P1^6; //Buzzer control pin
- unsigned char t0rh = 0; //t0 High-byte of overloaded values
- unsigned char t0rl = 0; //t0 Low byte of overloaded value
- void Openbuzz(unsigned int frequ);
- void Stopbuzz();
- void main(){
- unsigned int i;
- Tmod = 0x01; //config T0 works in mode 1, but does not start first
- EA = 1;
- While (1){ //enable global interrupt
- Openbuzz(4000); //Start buzzer at a frequency of 4KHz
- For (i=0; I<40000; I+ +);
- Stopbuzz(); //Stop buzzer
- For (i=0; I<40000; I+ +);
- Openbuzz(+); //Start buzzer at a frequency of 1KHz
- For (i=0; I<40000; I+ +);
- Stopbuzz(); //Stop buzzer
- For (i=0; I<40000; I+ +);
- }
- }
- /* Buzzer start function, frequ-operating frequency */
- void Openbuzz(unsigned int frequ){
- unsigned int reload; Calculate the required timer reload value
- Reload = 65536 - (11059200/N)/(frequ*2); //Calculate timer reload value by given frequency
- T0RH = (unsigned char) (Reload >> 8); //16-bit overloaded value decomposed to two bytes high and low
- T0RL = (unsigned char) reload;
- TH0 = 0xFF; //Set an initial value close to the overflow so that the timer is put into operation immediately
- TL0 = 0xFE;
- ET0 = 1; //Enable T0 interrupt
- TR0 = 1; //Start T0
- }
- /* Buzzer Stop function */
- void Stopbuzz(){
- ET0 = 0; //Disable T0 interrupts
- TR0 = 0; //Stop T0
- }
- /* T0 Interrupt Service function for controlling buzzer sound */
- void InterruptTimer0() interrupt 1{
- TH0 = T0rh; //Reload load value
- TL0 = T0rl;
- BUZZ = ~buzz; //Invert buzzer control level
- }
The 8th chapter makes the Development Board sound, buzzer driver