#include <ioCC2530.h> #include <string.h> #include <stdio.h> #include "UART.h" #include "OLED.h" #define KEY P2_0 //定义KEY为P20口 void clock_setup(void) { CLKCONCMD &= ~0x40; //设置系统时钟源为32MHZ晶振 while(CLKCONSTA & 0x40); //等待晶振稳定 CLKCONCMD &= ~0x47; //设置系统主时钟频率为32MHZ } void init_sensor_io(void) { //1.设置IO为普通IO P0SEL |= 0xC0; P1SEL |= 0x07; //2.设置编码口为输入 P0DIR &= ~0xC0; P1DIR &= ~0x07; } uchar get_sensor_id(void) { volatile uchar temp = P0_6<<4|P0_7<<3|P1_0<<2|P1_1<<1|P1_2; return temp; } void InitKey(void) { P2DIR &= ~0x01; //P20定义为输入 KEY = 1; } uchar CheckKey(void) { if(KEY == 0) { Delay_ms(10); if(KEY == 0) { KEY = 1; return 1; } } return 0; } void yuyin_trform(uint8 *HZdata) { unsigned char Frame_Info[100]; unsigned int HZ_Length; HZ_Length =strlen((char*)HZdata); Frame_Info[0] = 0xFD ; Frame_Info[1] = 0x00 ; Frame_Info[2] = HZ_Length+4; Frame_Info[3] = 0x01 ; Frame_Info[4] = 0x01; Frame_Info[HZ_Length+5] = 0x0D; Frame_Info[HZ_Length+6] = 0x0A; memcpy(&Frame_Info[5], HZdata, HZ_Length); UartSendBytes(Frame_Info,7+HZ_Length); } void main(void) { uchar temp8; uchar buf[16]; clock_setup(); //系统时钟设置,精确延时必须要设置 Delay_ms(1000); //让设备稳定 port_init(); initial_lcd(); InitUart(); clear_screen(); //清屏 disp_string_8x16_16x16(1,1,"武汉唯众智创科技"); //显示字符串,括号里的参数分别为(PAGE,列,字符串指针) disp_string_8x16_16x16(3,1,"----实验3.1-----"); Delay_ms(1000); while(1) { temp8 = get_sensor_id(); if(temp8 != 15){ disp_string_8x16_16x16(1,1,"请插语音播放模块"); disp_string_8x16_16x16(3,1,"----实验3.1-----"); Delay_ms(1000); continue; } if(CheckKey()>0){ clear_screen(); sprintf(buf,"编号:%d",temp8); disp_string_8x16_16x16(1,1,buf); disp_string_8x16_16x16(3,1,"正在播放..."); yuyin_trform("[m53][f1]欢迎使用[p100]唯众智创[p100]物联网综合实验箱"); Delay_ms(5000); disp_string_8x16_16x16(3,1,"播放结束,请按键!"); } } } |