单片机论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 89|回复: 0
打印 上一主题 下一主题
收起左侧

51单片机PS2手柄控制舵机与W25Q64存储源代码

[复制链接]
跳转到指定楼层
楼主
bwd1610 发表于 2018-4-28 21:14 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
51单片机开发控制代码


单片机源程序如下:
  1. /*
  2.         1、串口1调试                ok
  3.         2、串口2调试                ok
  4.         3、定时器0调试                ok
  5.         4、定时器1调试                ok
  6.         5、PS2手柄调试                ok
  7.         6、4通道PWM调试                ok
  8.         7、舵机调试                        ok
  9.         8、W25Q64存储调试        ok
  10.         
  11.         调试的过程:
  12.         如上,一个一个模块调通,最后组合
  13.         左边的目录结构就是正队每一个模块调试好做成一个模块文件,便于移植
  14.         
  15.         看程序方法:
  16.         看程序的时候,从main文件的main函数看起
  17.         基本的程序思路是
  18.         主函数->各个模块初始化->大循环while(1)
  19.                                                   ->中断(串口、定时器等)
  20.         大家在深究本程序时,建议大家先去了解各个模块的原理,然后看懂文件结构和程序结构,最后再细究算法问题
  21. */

  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "stc15.h"
  25. #include "uart.h"
  26. #include "delay.h"
  27. #include "io.h"
  28. #include "ps2.h"
  29. #include "pwm.h"
  30. #include "timer.h"
  31. #include "w25q64.h"
  32. #include "global.h"
  33. #include "adc.h"
  34. #include "oled.h"


  35. #define PS2_LED_RED                  0x73
  36. #define PS2_LED_GRN                  0x41
  37. #define PSX_BUTTON_NUM                 16
  38. #define PS2_MAX_LEN                 64

  39. #define CAR_PWM                                0
  40. #define VOL_CH                                7
  41. #define VERSION                                20170912        //版本定义

  42. #define W25Q64_INFO_ADDR_SAVE_STR                        (((8<<10)-4)<<10)//(8*1024-1)*1024                //eeprom_info结构体存储的位置
  43. #define FLAG_VERIFY 0x38

  44. void led_beep_start(void);
  45. void handle_ps2(void);
  46. void handle_nled(void);
  47. void handle_car(void);
  48. void handle_uart(void);
  49. void handle_button(void);
  50. void parse_psx_buf(unsigned char *buf, unsigned char mode);
  51. void parse_cmd(u8 *cmd);

  52. void action_save(u8 *str);
  53. int get_action_index(u8 *str);//获取动作序号
  54. void print_group(int start, int end);
  55. void int_exchange(int *int1, int *int2);
  56. void erase_sector(int start, int end);

  57. void do_group_once(int group_num);
  58. void handle_action(void);
  59. u8 check_dj_state(void);//检查舵机状态,是否全部到位

  60. void do_action(u8 *uart_receive_buf);
  61. void replace_char(u8*str, u8 ch1, u8 ch2);
  62. void car_pwm_set(int car_left, int car_right);
  63. //void car_io_set(int car_left, int car_right);

  64. void handle_uart_get(void);
  65. void handle_warning(void);
  66. void handle_oled(void);
  67. void handle_sensor(void);
  68. void oled_dis_init(void);
  69. void rewrite_eeprom(void);

  70. #define CYCLE   1000                                                                                     //
  71. u8 psx_buf[9]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};         //
  72. unsigned short adc7_value = 0, adc0_value = 0;
  73. float vol_adc = 0;


  74. unsigned char code BMP1[] =
  75. {
  76.         0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8,
  77.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00,
  78.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  79.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  80.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  81.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92,
  82.         0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xC7,0x01,0x7D,
  83.         0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00,
  84.         0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
  85.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
  86.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  87.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  88.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  89.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,
  90.         0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,
  91.         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,
  92.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00,
  93.         0x6D,0x6D,0x6D,0x6D,0x6D,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x00,0x00,0x40,0x40,
  94.         0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  97.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  98.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  99.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  100.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,
  101.         0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB,
  102.         0xDB,0xDB,0xDB,0x00,0x00,0xDA,0xDA,0xDA,0xDA,0xDA,0x00,0x00,0xD8,0xD8,0xD8,0xD8,
  103.         0xD8,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
  104.         0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x80,
  105.         0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  106.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  107.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  108.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,
  109.         0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,
  110.         0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0xE6,0x66,0x20,0x00,0x06,0x06,0x86,0x06,
  111.         0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x86,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,
  112.         0x00,0x86,0x86,0x86,0x86,0x86,0x80,0x80,0x86,0x86,0x06,0x86,0x86,0xC0,0xC0,0x86,
  113.         0x86,0x86,0x06,0x06,0xD0,0x30,0x76,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,
  114.         0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,
  115.         0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  116.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  117.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  118.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x1C,0x00,0xFE,0x00,0x01,
  119.         0x02,0x00,0xC4,0x18,0x20,0x02,0x9E,0x63,0xB2,0x0E,0x00,0xFF,0x81,0x81,0xFF,0x00,
  120.         0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0xFF,0x00,0x23,0xEA,0xAA,0xBF,0xAA,
  121.         0xEA,0x03,0x3F,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  122.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  123.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  124.         0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,
  125.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  126.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x0C,0x08,0x00,0x00,0x01,0x01,0x01,
  127.         0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x81,0x80,0x80,0x81,0x80,
  128.         0x81,0x80,0x80,0x80,0x80,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
  129.         0x01,0x00,0x01,0x01,0x09,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  130.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
  131.         0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
  132.         0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E,0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E,
  133.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  134.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  135.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xC1,0xC1,0xFF,
  136.         0xFF,0xC1,0xC1,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  137.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  138.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x80,0xFC,0xF3,0xEF,0xF3,0xFC,
  139.         0x80,0xFF,0x80,0xEE,0xEE,0xEE,0xF5,0xFB,0xFF,0x9C,0xBE,0xB6,0xB6,0x88,0xFF,0x00,/*"D:\DreamSpark\OLED\MP3_UI.bmp",0*/
  140. };

  141. unsigned char code BMP2[] =
  142. {
  143.         0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8,
  144.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00,
  145.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  146.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  147.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  148.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92,
  149.         0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xFF,0x01,0x7D,
  150.         0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00,
  151.         0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
  152.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
  153.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  154.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  155.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  156.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,
  157.         0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,
  158.         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,
  159.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  160.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,
  161.         0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0xF8,0x18,0x60,0x80,0x00,0x00,0x00,0x80,
  162.         0x60,0x18,0xF8,0x00,0x00,0x00,0x20,0x20,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,
  163.         0x10,0x08,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x20,0x20,0xF8,0x00,0x00,0x00,
  164.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x88,0x68,
  165.         0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  166.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  167.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  168.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,
  169.         0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x7F,0x00,0x00,0x01,0x06,0x18,0x06,0x01,
  170.         0x00,0x00,0x7F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x00,0x00,0x00,0x1F,
  171.         0x20,0x40,0x40,0x40,0x40,0x20,0x1F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,
  172.         0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x18,0x06,0x01,0x00,
  173.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  174.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  175.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  176.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  177.         0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x20,0x20,0xC0,0x00,0x00,0xE0,0x20,0x20,0x20,
  178.         0xE0,0x00,0x00,0x00,0x40,0xE0,0x00,0x00,0x00,0x00,0x60,0x20,0x20,0x20,0xE0,0x00,
  179.         0x00,0x00,0x00,0x00,0xE0,0x20,0x20,0x20,0xE0,0x00,0x00,0x00,0x00,0x00,0x40,0x20,
  180.         0x20,0x20,0xC0,0x00,0x00,0x40,0x20,0x20,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
  181.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  182.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  183.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  184.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  185.         0x00,0x00,0x00,0x00,0x00,0x0C,0x0A,0x0A,0x09,0x0C,0x00,0x00,0x0F,0x08,0x08,0x08,
  186.         0x0F,0x00,0x00,0x00,0x08,0x0F,0x08,0x00,0x00,0x00,0x0C,0x08,0x09,0x09,0x0E,0x00,
  187.         0x00,0x0C,0x00,0x00,0x0F,0x09,0x09,0x09,0x0F,0x00,0x00,0x0C,0x00,0x00,0x0C,0x0A,
  188.         0x0A,0x09,0x0C,0x00,0x00,0x0C,0x0A,0x0A,0x09,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,
  189.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  190.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  191.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  192.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  193.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  194.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,
  195.         0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  196.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  197.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  198.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  199.         0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F,0x00,0x00,0x38,0x54,0x54,0x58,0x00,0x00,
  200.         0x7C,0x04,0x04,0x78,0x00,0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,
  201.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  202.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xAA,0xAA,0xAA,
  203.         0x28,0x08,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  204.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  205.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F,
  206.         0x00,0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00,0x7F,0x02,0x04,0x08,0x10,0x7F,0x00,/*"D:\12?í\show2.bmp",0*/
  207. };

  208. code const char *pre_cmd_set_red[PSX_BUTTON_NUM] = {
  209.         "<PS2_RED01:#005P2400T2000!^$DST:5!>",        //L2                                                  
  210.         "<PS2_RED02:#005P0600T2000!^$DST:5!>",                //R2                                                  
  211.         "<PS2_RED03:#004P0600T2000!^$DST:4!>",                //L1                                                  
  212.         "<PS2_RED04:#004P2400T2000!^$DST:4!>",        //R1                        
  213.         "<PS2_RED05:#002P2400T2000!^$DST:2!>",        //RU                                                  
  214.         "<PS2_RED06:#003P2400T2000!^$DST:3!>",        //RR                                                  
  215.         "<PS2_RED07:#002P0600T2000!^$DST:2!>",                //RD                                                  
  216.         "<PS2_RED08:#003P0600T2000!^$DST:3!>",                //RL                                
  217.         "<PS2_RED09:$!>",                                //SE                                                         
  218.         "<PS2_RED10:$DWD!>",                                        //AL                                                  
  219.         "<PS2_RED11:$DWA!>",                                        //AR                                                  
  220.         "<PS2_RED12:$DJR!>",                                        //ST                        
  221.         "<PS2_RED13:#001P0600T2000!^$DST:1!>",                //LU                                                  
  222.         "<PS2_RED14:#000P0600T2000!^$DST:0!>",                //LR                                                                  
  223.         "<PS2_RED15:#001P2400T2000!^$DST:1!>",        //LD                                                  
  224.         "<PS2_RED16:#000P2400T2000!^$DST:0!>",        //LL                                                
  225.                
  226. };

  227. code const char *pre_cmd_set_grn[PSX_BUTTON_NUM] = {
  228.         "<PS2_GRN01:#005P2400T2000!^$DST:5!>",        //L2                                                  
  229.         "<PS2_GRN02:#005P0600T2000!^$DST:5!>",                //R2                                                  
  230.         "<PS2_GRN03:#004P0600T2000!^$DST:4!>",                //L1                                                  
  231.         "<PS2_GRN04:#004P2400T2000!^$DST:4!>",        //R1                        
  232.         "<PS2_GRN05:#002P2400T2000!^$DST:2!>",        //RU                                                  
  233.         "<PS2_GRN06:#003P2400T2000!^$DST:3!>",        //RR                                                  
  234.         "<PS2_GRN07:#002P0600T2000!^$DST:2!>",                //RD                                                  
  235.         "<PS2_GRN08:#003P0600T2000!^$DST:3!>",                //RL                                
  236.         "<PS2_GRN09:$!>",                                //SE                                                         
  237.         "<PS2_GRN10:$!>",                                                //AL-NO                                                  
  238.         "<PS2_GRN11:$!>",                                                //AR-NO                                                  
  239.         "<PS2_GRN12:$DJR!>",                                        //ST                        
  240.         "<PS2_GRN13:#001P0600T2000!^$DST:1!>",                //LU                                                  
  241.         "<PS2_GRN14:#000P0600T2000!^$DST:0!>",                //LR                                                                  
  242.         "<PS2_GRN15:#001P2400T2000!^$DST:1!>",        //LD                                                  
  243.         "<PS2_GRN16:#000P2400T2000!^$DST:0!>",        //LL                                                  
  244. };

  245. u8 dbt_flag = 0;
  246. code const char *action_pre[] = {
  247. "{G0000#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
  248. "{G0001#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
  249. "{G0002#000P1500T1000!#001P1705T1000!#002P1859T1000!#003P1936T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
  250. "{G0003#000P1500T1000!#001P1705T1000!#002P1859T1000!#003P1936T1000!#004P2000T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
  251. "{G0004#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P1000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
  252. "{G0005#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P2000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
  253. "{G0006#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P1000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
  254. "{G0007#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P2000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
  255. "{G0008#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P1000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
  256. "{G0009#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P2000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
  257. "{G0010#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
  258. "{G0011#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
  259. "{G0012#000P1500T1000!#001P1346T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  260. "{G0013#000P1500T1000!#001P1346T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  261. "{G0014#000P1500T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  262. "{G0015#000P2200T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  263. "{G0016#000P2200T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  264. "{G0017#000P2200T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  265. "{G0018#000P2200T1000!#001P1800T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  266. "{G0019#000P2200T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  267. "{G0020#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
  268. "{G0021#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  269. "{G0022#000P1500T1000!#001P1346T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  270. "{G0023#000P1500T1000!#001P1346T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  271. "{G0024#000P1500T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  272. "{G0025#000P0800T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  273. "{G0026#000P0800T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  274. "{G0027#000P0800T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  275. "{G0028#000P0800T1000!#001P1800T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  276. "{G0029#000P0800T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  277. "{G0030#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
  278. "{G0031#000P0800T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  279. "{G0032#000P0800T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  280. "{G0033#000P0800T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  281. "{G0034#000P0800T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  282. "{G0035#000P0800T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  283. "{G0036#000P2200T2000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  284. "{G0037#000P2200T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
  285. "{G0038#000P2200T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  286. "{G0039#000P2200T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
  287. "{G0040#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
  288. };

  289. u32 save_addr_sector = 0, save_action_index_bak = 0;
  290. #define ACTION_SIZE 256

  291. u8 group_do_ok = 1;
  292. int do_start_index, do_time, group_num_start, group_num_end, group_num_times;

  293. u8 car_dw = 1;



  294. /*
  295.         代码从main里开始执行
  296.         在进入大循环while(1)之前都为各个模块的初始化
  297.         最后在大循环处理持续执行的事情

  298.         另外注意uart中的串口中断,赌球网|真人赌球网|世界杯赌球网:接收数据处理
  299.         timer中的定时器中断,舵机的脉冲收发就在那里
  300. */

  301. void main(void) {
  302.         //IO初始化
  303.         io_init();
  304.         
  305.         //P10通道初始化,用于读取AD 电压值
  306.         adc_init(VOL_CH);
  307.         
  308.         //全局变量初始化
  309.         global_init();
  310.         
  311.         //手柄初始化
  312.         psx_init();
  313.         
  314.         //定时器0、1初始化
  315.         timer0_init();
  316.         timer1_init();
  317.                
  318.         //pwm模块初始化
  319.         pwm_init(CYCLE);
  320.         
  321.         //串口1初始化
  322.         uart1_init();
  323.         uart1_close();
  324.         uart1_open();
  325.         
  326.         //串口2初始化
  327.         uart2_init();
  328.         uart2_close();
  329.         uart2_open();
  330.         
  331.         //串口4初始化
  332.         uart4_init();
  333.         uart4_close();
  334.         uart4_open();
  335.         
  336.         //存储器初始化,读取ID进行校验,若错误则长鸣不往下执行
  337.         w25x_init();
  338.         while(w25x_readId()!= W25Q64)beep_on();
  339.         
  340.         w25x_read((u8 *)(&eeprom_info), W25Q64_INFO_ADDR_SAVE_STR, sizeof(eeprom_info_t));        //读取全局变量
  341.         if(eeprom_info.version != VERSION) {        //判断版本是否是当前版本
  342.                 eeprom_info.version = VERSION;                //复制当前版本
  343.                 eeprom_info.dj_record_num = 0;                //学习动作组变量赋值0
  344.                 rewrite_eeprom();                                        //写入到存储器
  345.         }
  346.         
  347.         //oled初始化
  348.         OLED_Init();
  349.         OLED_CLS();
  350.         mdelay(500);
  351.         oled_dis_init();
  352.         mdelay(3000);
  353.         OLED_CLS();
  354.         

  355.         
  356. //        //串口1 2 4 发送数据测试OK
  357. //        uart1_send_str("uart1_init OK!");
  358. //        uart2_send_str("uart2_init OK!");
  359. //        uart4_send_str("uart4_init OK!");
  360. //               
  361.         
  362.         //LED灯和蜂鸣器闪烁表示初始化完毕
  363.         led_beep_start();
  364.         
  365. ……………………

  366. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
000 51控制器代码.rar (2.75 MB, 下载次数: 0)




您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|单片机论坛

Powered by 单片机教程网

快速回复 赌球网|真人赌球网|世界杯赌球网 返回列表