51单片机开发控制代码
单片机源程序如下:
- /*
- 1、串口1调试 ok
- 2、串口2调试 ok
- 3、定时器0调试 ok
- 4、定时器1调试 ok
- 5、PS2手柄调试 ok
- 6、4通道PWM调试 ok
- 7、舵机调试 ok
- 8、W25Q64存储调试 ok
-
- 调试的过程:
- 如上,一个一个模块调通,最后组合
- 左边的目录结构就是正队每一个模块调试好做成一个模块文件,便于移植
-
- 看程序方法:
- 看程序的时候,从main文件的main函数看起
- 基本的程序思路是
- 主函数->各个模块初始化->大循环while(1)
- ->中断(串口、定时器等)
- 大家在深究本程序时,建议大家先去了解各个模块的原理,然后看懂文件结构和程序结构,最后再细究算法问题
- */
- #include <stdio.h>
- #include <string.h>
- #include "stc15.h"
- #include "uart.h"
- #include "delay.h"
- #include "io.h"
- #include "ps2.h"
- #include "pwm.h"
- #include "timer.h"
- #include "w25q64.h"
- #include "global.h"
- #include "adc.h"
- #include "oled.h"
- #define PS2_LED_RED 0x73
- #define PS2_LED_GRN 0x41
- #define PSX_BUTTON_NUM 16
- #define PS2_MAX_LEN 64
- #define CAR_PWM 0
- #define VOL_CH 7
- #define VERSION 20170912 //版本定义
- #define W25Q64_INFO_ADDR_SAVE_STR (((8<<10)-4)<<10)//(8*1024-1)*1024 //eeprom_info结构体存储的位置
- #define FLAG_VERIFY 0x38
- void led_beep_start(void);
- void handle_ps2(void);
- void handle_nled(void);
- void handle_car(void);
- void handle_uart(void);
- void handle_button(void);
- void parse_psx_buf(unsigned char *buf, unsigned char mode);
- void parse_cmd(u8 *cmd);
- void action_save(u8 *str);
- int get_action_index(u8 *str);//获取动作序号
- void print_group(int start, int end);
- void int_exchange(int *int1, int *int2);
- void erase_sector(int start, int end);
- void do_group_once(int group_num);
- void handle_action(void);
- u8 check_dj_state(void);//检查舵机状态,是否全部到位
- void do_action(u8 *uart_receive_buf);
- void replace_char(u8*str, u8 ch1, u8 ch2);
- void car_pwm_set(int car_left, int car_right);
- //void car_io_set(int car_left, int car_right);
- void handle_uart_get(void);
- void handle_warning(void);
- void handle_oled(void);
- void handle_sensor(void);
- void oled_dis_init(void);
- void rewrite_eeprom(void);
- #define CYCLE 1000 //
- u8 psx_buf[9]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //
- unsigned short adc7_value = 0, adc0_value = 0;
- float vol_adc = 0;
- unsigned char code BMP1[] =
- {
- 0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92,
- 0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xC7,0x01,0x7D,
- 0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00,
- 0x6D,0x6D,0x6D,0x6D,0x6D,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x00,0x00,0x40,0x40,
- 0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,
- 0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB,
- 0xDB,0xDB,0xDB,0x00,0x00,0xDA,0xDA,0xDA,0xDA,0xDA,0x00,0x00,0xD8,0xD8,0xD8,0xD8,
- 0xD8,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
- 0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x80,
- 0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,
- 0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,
- 0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0xE6,0x66,0x20,0x00,0x06,0x06,0x86,0x06,
- 0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x86,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,
- 0x00,0x86,0x86,0x86,0x86,0x86,0x80,0x80,0x86,0x86,0x06,0x86,0x86,0xC0,0xC0,0x86,
- 0x86,0x86,0x06,0x06,0xD0,0x30,0x76,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,
- 0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,
- 0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x1C,0x00,0xFE,0x00,0x01,
- 0x02,0x00,0xC4,0x18,0x20,0x02,0x9E,0x63,0xB2,0x0E,0x00,0xFF,0x81,0x81,0xFF,0x00,
- 0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0xFF,0x00,0x23,0xEA,0xAA,0xBF,0xAA,
- 0xEA,0x03,0x3F,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x0C,0x08,0x00,0x00,0x01,0x01,0x01,
- 0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x81,0x80,0x80,0x81,0x80,
- 0x81,0x80,0x80,0x80,0x80,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
- 0x01,0x00,0x01,0x01,0x09,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
- 0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
- 0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E,0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xC1,0xC1,0xFF,
- 0xFF,0xC1,0xC1,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x80,0xFC,0xF3,0xEF,0xF3,0xFC,
- 0x80,0xFF,0x80,0xEE,0xEE,0xEE,0xF5,0xFB,0xFF,0x9C,0xBE,0xB6,0xB6,0x88,0xFF,0x00,/*"D:\DreamSpark\OLED\MP3_UI.bmp",0*/
- };
- unsigned char code BMP2[] =
- {
- 0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92,
- 0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xFF,0x01,0x7D,
- 0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,
- 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0xF8,0x18,0x60,0x80,0x00,0x00,0x00,0x80,
- 0x60,0x18,0xF8,0x00,0x00,0x00,0x20,0x20,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,
- 0x10,0x08,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x20,0x20,0xF8,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x88,0x68,
- 0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x7F,0x00,0x00,0x01,0x06,0x18,0x06,0x01,
- 0x00,0x00,0x7F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x00,0x00,0x00,0x1F,
- 0x20,0x40,0x40,0x40,0x40,0x20,0x1F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,
- 0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x18,0x06,0x01,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x20,0x20,0xC0,0x00,0x00,0xE0,0x20,0x20,0x20,
- 0xE0,0x00,0x00,0x00,0x40,0xE0,0x00,0x00,0x00,0x00,0x60,0x20,0x20,0x20,0xE0,0x00,
- 0x00,0x00,0x00,0x00,0xE0,0x20,0x20,0x20,0xE0,0x00,0x00,0x00,0x00,0x00,0x40,0x20,
- 0x20,0x20,0xC0,0x00,0x00,0x40,0x20,0x20,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x0C,0x0A,0x0A,0x09,0x0C,0x00,0x00,0x0F,0x08,0x08,0x08,
- 0x0F,0x00,0x00,0x00,0x08,0x0F,0x08,0x00,0x00,0x00,0x0C,0x08,0x09,0x09,0x0E,0x00,
- 0x00,0x0C,0x00,0x00,0x0F,0x09,0x09,0x09,0x0F,0x00,0x00,0x0C,0x00,0x00,0x0C,0x0A,
- 0x0A,0x09,0x0C,0x00,0x00,0x0C,0x0A,0x0A,0x09,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,
- 0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F,0x00,0x00,0x38,0x54,0x54,0x58,0x00,0x00,
- 0x7C,0x04,0x04,0x78,0x00,0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xAA,0xAA,0xAA,
- 0x28,0x08,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F,
- 0x00,0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00,0x7F,0x02,0x04,0x08,0x10,0x7F,0x00,/*"D:\12?í\show2.bmp",0*/
- };
- code const char *pre_cmd_set_red[PSX_BUTTON_NUM] = {
- "<PS2_RED01:#005P2400T2000!^$DST:5!>", //L2
- "<PS2_RED02:#005P0600T2000!^$DST:5!>", //R2
- "<PS2_RED03:#004P0600T2000!^$DST:4!>", //L1
- "<PS2_RED04:#004P2400T2000!^$DST:4!>", //R1
- "<PS2_RED05:#002P2400T2000!^$DST:2!>", //RU
- "<PS2_RED06:#003P2400T2000!^$DST:3!>", //RR
- "<PS2_RED07:#002P0600T2000!^$DST:2!>", //RD
- "<PS2_RED08:#003P0600T2000!^$DST:3!>", //RL
- "<PS2_RED09:$!>", //SE
- "<PS2_RED10:$DWD!>", //AL
- "<PS2_RED11:$DWA!>", //AR
- "<PS2_RED12:$DJR!>", //ST
- "<PS2_RED13:#001P0600T2000!^$DST:1!>", //LU
- "<PS2_RED14:#000P0600T2000!^$DST:0!>", //LR
- "<PS2_RED15:#001P2400T2000!^$DST:1!>", //LD
- "<PS2_RED16:#000P2400T2000!^$DST:0!>", //LL
-
- };
- code const char *pre_cmd_set_grn[PSX_BUTTON_NUM] = {
- "<PS2_GRN01:#005P2400T2000!^$DST:5!>", //L2
- "<PS2_GRN02:#005P0600T2000!^$DST:5!>", //R2
- "<PS2_GRN03:#004P0600T2000!^$DST:4!>", //L1
- "<PS2_GRN04:#004P2400T2000!^$DST:4!>", //R1
- "<PS2_GRN05:#002P2400T2000!^$DST:2!>", //RU
- "<PS2_GRN06:#003P2400T2000!^$DST:3!>", //RR
- "<PS2_GRN07:#002P0600T2000!^$DST:2!>", //RD
- "<PS2_GRN08:#003P0600T2000!^$DST:3!>", //RL
- "<PS2_GRN09:$!>", //SE
- "<PS2_GRN10:$!>", //AL-NO
- "<PS2_GRN11:$!>", //AR-NO
- "<PS2_GRN12:$DJR!>", //ST
- "<PS2_GRN13:#001P0600T2000!^$DST:1!>", //LU
- "<PS2_GRN14:#000P0600T2000!^$DST:0!>", //LR
- "<PS2_GRN15:#001P2400T2000!^$DST:1!>", //LD
- "<PS2_GRN16:#000P2400T2000!^$DST:0!>", //LL
- };
- u8 dbt_flag = 0;
- code const char *action_pre[] = {
- "{G0000#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0001#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0002#000P1500T1000!#001P1705T1000!#002P1859T1000!#003P1936T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0003#000P1500T1000!#001P1705T1000!#002P1859T1000!#003P1936T1000!#004P2000T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0004#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P1000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
- "{G0005#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P2000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
- "{G0006#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P1000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
- "{G0007#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P2000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
- "{G0008#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P1000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
- "{G0009#000P1500T0500!#001P1705T0500!#002P1859T0500!#003P1936T0500!#004P2000T0500!#005P1500T0500!#006P1500T1000!#007P1500T1000!}",
- "{G0010#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0011#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0012#000P1500T1000!#001P1346T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0013#000P1500T1000!#001P1346T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0014#000P1500T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0015#000P2200T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0016#000P2200T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0017#000P2200T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0018#000P2200T1000!#001P1800T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0019#000P2200T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0020#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0021#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0022#000P1500T1000!#001P1346T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0023#000P1500T1000!#001P1346T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0024#000P1500T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0025#000P0800T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0026#000P0800T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0027#000P0800T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0028#000P0800T1000!#001P1800T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0029#000P0800T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0030#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0031#000P0800T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0032#000P0800T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0033#000P0800T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0034#000P0800T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0035#000P0800T1000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0036#000P2200T2000!#001P2000T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0037#000P2200T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P2000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0038#000P2200T1000!#001P1300T1000!#002P2013T1000!#003P2115T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0039#000P2200T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1000T1000!#006P1500T1000!#007P1500T1000!}",
- "{G0040#000P1500T1000!#001P1500T1000!#002P1500T1000!#003P1500T1000!#004P1500T1000!#005P1500T1000!#006P1500T1000!#007P1500T1000!}",
- };
- u32 save_addr_sector = 0, save_action_index_bak = 0;
- #define ACTION_SIZE 256
- u8 group_do_ok = 1;
- int do_start_index, do_time, group_num_start, group_num_end, group_num_times;
- u8 car_dw = 1;
- /*
- 代码从main里开始执行
- 在进入大循环while(1)之前都为各个模块的初始化
- 最后在大循环处理持续执行的事情
- 另外注意uart中的串口中断,接收数据处理
- timer中的定时器中断,舵机的脉冲收发就在那里
- */
- void main(void) {
- //IO初始化
- io_init();
-
- //P10通道初始化,用于读取AD 电压值
- adc_init(VOL_CH);
-
- //全局变量初始化
- global_init();
-
- //手柄初始化
- psx_init();
-
- //定时器0、1初始化
- timer0_init();
- timer1_init();
-
- //pwm模块初始化
- pwm_init(CYCLE);
-
- //串口1初始化
- uart1_init();
- uart1_close();
- uart1_open();
-
- //串口2初始化
- uart2_init();
- uart2_close();
- uart2_open();
-
- //串口4初始化
- uart4_init();
- uart4_close();
- uart4_open();
-
- //存储器初始化,读取ID进行校验,若错误则长鸣不往下执行
- w25x_init();
- while(w25x_readId()!= W25Q64)beep_on();
-
- w25x_read((u8 *)(&eeprom_info), W25Q64_INFO_ADDR_SAVE_STR, sizeof(eeprom_info_t)); //读取全局变量
- if(eeprom_info.version != VERSION) { //判断版本是否是当前版本
- eeprom_info.version = VERSION; //复制当前版本
- eeprom_info.dj_record_num = 0; //学习动作组变量赋值0
- rewrite_eeprom(); //写入到存储器
- }
-
- //oled初始化
- OLED_Init();
- OLED_CLS();
- mdelay(500);
- oled_dis_init();
- mdelay(3000);
- OLED_CLS();
-
-
- // //串口1 2 4 发送数据测试OK
- // uart1_send_str("uart1_init OK!");
- // uart2_send_str("uart2_init OK!");
- // uart4_send_str("uart4_init OK!");
- //
-
- //LED灯和蜂鸣器闪烁表示初始化完毕
- led_beep_start();
-
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
000 51控制器代码.rar
(2.75 MB, 下载次数: 100)
|