標題: 自己做的鼠標調(diào)試方案 帶單片機程序 [打印本頁]

作者: jing123a    時間: 2017-2-26 14:12
標題: 自己做的鼠標調(diào)試方案 帶單片機程序
具體的還有一些問題,請大家看看

下載:
單片機練習.zip (46.26 KB, 下載次數(shù): 12)

主程序預覽:
  1. #include <reg52.h>
  2. #include <LCD1602_4.h>
  3. #include <mouse.h>
  4. #include <string.h>
  5. #include <DELAY52.h>
  6. sbit beep=P3^7;
  7. void main()
  8. {  

  9. mouse_SDA=1;
  10. mouse_CLK=1;
  11. LCD1602_Init();                //初始化液晶屏幕1602
  12. LCD1602_write_cmd(0x80);//寫命令,光標定位在第一行
  13. write_bytes("Initializing````");



  14. LCD1602_Init();                //初始化液晶屏幕1602
  15. CLEARSCREEN;                   //清屏
  16. Init_mouse();                       //中斷
  17. delayms(500);                       //延時500ms,必須
  18. num(0,2,mouse_byte);                   //LCD顯示
  19. delayms(500);

  20. host_to_mouse(0xf3);                   //設置采樣頻率
  21. num(0,2,mouse_byte);                   //LCD顯示
  22. num(0,10,1);
  23. delayms(500);
  24. delay10us(1);
  25. host_to_mouse(0xc8);
  26. num(0,2,mouse_byte);
  27. num(0,10,2);
  28. delayms(500);
  29. delay10us(1);
  30. host_to_mouse(0xf3);
  31. num(0,2,mouse_byte);
  32. num(0,10,3);
  33. delayms(500);


  34. host_to_mouse(0x64);
  35. num(0,2,mouse_byte);
  36. num(0,10,4);
  37. delayms(500);
  38. host_to_mouse(0xf3);
  39. num(0,2,mouse_byte);
  40. num(0,10,5);
  41. delayms(500);

  42. host_to_mouse(0x50);
  43. num(0,2,mouse_byte);
  44. num(0,10,6);
  45. delayms(50);
  46. delay10us(1);
  47. host_to_mouse(0xf2);
  48. num(0,2,mouse_byte);
  49. num(0,10,7);
  50. delayms(50);
  51. if(mouse_byte==0x03)
  52. {
  53. LCD1602_write_string(0,0,"ok");
  54. delayms(500);
  55. }
  56. else
  57. {
  58. LCD1602_write_string(0,0,"DE");
  59. delayms(500);
  60. }
  61. delayms(500);
  62. while(1);
  63. {
  64. led=1;
  65. CLEARSCREEN;//清屏
  66. LCD1602_write_string(0,0,"x:");
  67. num(0,2,move_x);//X坐標值
  68. LCD1602_write_string(0,0,"y:");
  69. num(0,10,move_y);//Y坐標值
  70. LCD1602_write_string(0,0,"z:");
  71. num(1,10,move_z);//Z坐標值
  72. if(mouse_data[0]&0x01)//如果點下左鍵
  73. {
  74. beep=0;
  75. LCD1602_write_string(1,0,"left");
  76. }
  77. else if(mouse_data[0]&0x02)//如果點下右鍵
  78. {
  79. beep=0;
  80. LCD1602_write_string(1,0,"right");
  81. }
  82. else if(mouse_data[0]&0x04)//如果點下中鍵
  83. {
  84. beep=0;
  85. LCD1602_write_string(1,0,"middle");
  86. }
  87. else
  88. {
  89. beep=1;
  90. LCD1602_write_string(1,0,"nothing");
  91. }
  92. delayms(50);
  93. }
  94. }
復制代碼







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1