The 8th chapter makes the Development Board sound, buzzer driver

Source: Internet
Author: User

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

  1. #include <reg52.h>
  2. Sbit BUZZ = P1^6; //Buzzer control pin
  3. unsigned char t0rh = 0; //t0 High-byte of overloaded values
  4. unsigned char t0rl = 0; //t0 Low byte of overloaded value
  5. void Openbuzz(unsigned int frequ);
  6. void Stopbuzz();
  7. void main(){
  8. unsigned int i;
  9. Tmod = 0x01; //config T0 works in mode 1, but does not start first
  10. EA = 1;
  11. While (1){ //enable global interrupt
  12. Openbuzz(4000); //Start buzzer at a frequency of 4KHz
  13. For (i=0; I<40000; I+ +);
  14. Stopbuzz(); //Stop buzzer
  15. For (i=0; I<40000; I+ +);
  16. Openbuzz(+); //Start buzzer at a frequency of 1KHz
  17. For (i=0; I<40000; I+ +);
  18. Stopbuzz(); //Stop buzzer
  19. For (i=0; I<40000; I+ +);
  20. }
  21. }
  22. /* Buzzer start function, frequ-operating frequency */
  23. void Openbuzz(unsigned int frequ){
  24. unsigned int reload; Calculate the required timer reload value
  25. Reload = 65536 - (11059200/N)/(frequ*2); //Calculate timer reload value by given frequency
  26. T0RH = (unsigned char) (Reload >> 8); //16-bit overloaded value decomposed to two bytes high and low
  27. T0RL = (unsigned char) reload;
  28. TH0 = 0xFF; //Set an initial value close to the overflow so that the timer is put into operation immediately
  29. TL0 = 0xFE;
  30. ET0 = 1; //Enable T0 interrupt
  31. TR0 = 1; //Start T0
  32. }
  33. /* Buzzer Stop function */
  34. void Stopbuzz(){
  35. ET0 = 0; //Disable T0 interrupts
  36. TR0 = 0; //Stop T0
  37. }
  38. /* T0 Interrupt Service function for controlling buzzer sound */
  39. void InterruptTimer0() interrupt 1{
  40. TH0 = T0rh; //Reload load value
  41. TL0 = T0rl;
  42. BUZZ = ~buzz; //Invert buzzer control level
  43. }

The 8th chapter makes the Development Board sound, buzzer driver

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.