【E836】基于美信MAX32660的OLED智能手表设计

2021-09-07 14:17:33      索炜达电子      534     

项目编号:E836

文件大小:4.1M

源码说明:带中文注释

开发环境:C编译器

简要概述

本代码主要实现了显示时间,以及对步数的记录。顺便加了个小的下位机,用来修改时间。

【E836】基于美信MAX32660的OLED智能手表设计

硬件连接

#define SPI_CS_Pin PIN_12

#define SPI_CS_GPIO_Port PORT_0

#define SPI_DC_Pin PIN_13

#define SPI_DC_GPIO_Port PORT_0

#define SPI_RES_Pin PIN_4

#define SPI_RES_GPIO_Port PORT_0

#define SPI_DIN_Pin PIN_3

#define SPI_DIN_GPIO_Port PORT_0

#define SPI_CLK_Pin PIN_2

#define SPI_CLK_GPIO_Port PORT_0

image-20210216221845791


时间显示

这次还是用了OLED的文字库,用到了显示文字,和画图功能。



DrawNum(0,0,step_cnt,5);

SetFontSize(3);

DrawChar(30,24,':');

DrawNum(0,24,hour,2);

DrawNum(42,24,min,2);

fresh_g();

RoundClock(hour,min,sec);

其中画时钟的函数是我之前有用过,参照的是另外一个up主的内容,程序里有提到。具体的使用可以参照我之前的项目


下面源码,主要用了简单的画图函数。



void RoundClock(int hours ,int minute ,int sec)

{

unsigned char i=0;


TypeXY hourspoint,minutepoint,secpoint,tmp1,tmp2;


center_pos.x = 104;

center_pos.y = 39;


//时针

SetRotateValue(center_pos.x,center_pos.y,hours*30+(minute*30)/60+clock_angle,1); //设定旋转中心,旋转角度,旋转方向

hourspoint=GetRotateXY(center_pos.x,center_pos.y-CLOCK_R+12);         //给出一个不在中心的点,计算出其旋转后的坐标

DrawLine(center_pos.x,center_pos.y,hourspoint.x,hourspoint.y);//画线

//分针

SetRotateValue(center_pos.x,center_pos.y,minute*6+(sec*6)/60+clock_angle,1);

minutepoint=GetRotateXY(center_pos.x,center_pos.y-CLOCK_R+6);

DrawLine(center_pos.x,center_pos.y,minutepoint.x,minutepoint.y);

//秒针

SetRotateValue(center_pos.x,center_pos.y,sec*6+clock_angle,1);

secpoint=GetRotateXY(center_pos.x,center_pos.y-CLOCK_R+2);

DrawLine(center_pos.x,center_pos.y,secpoint.x,secpoint.y);

//表盘

for(i=0;i<12;i++)

{

SetRotateValue(center_pos.x,center_pos.y,i*30+clock_angle,1);

tmp1=GetRotateXY(center_pos.x,center_pos.y-CLOCK_R+1);

tmp2=GetRotateXY(center_pos.x,center_pos.y-CLOCK_R+1+CLOCK_LEN);

DrawLine(tmp1.x,tmp1.y,tmp2.x,tmp2.y);

}

// /*表盘上的数字*/

// SetRotateValue(60,30,i*30+clock_angle,1);

// if(i==0)

// {

// tmp3=GetRotateXY(center_pos.x,center_pos.y-num_pos);

// SetFontSize(1);

// DrawNum(tmp3.x,tmp3.y,12,2);

// }

// else if(i<7)

// {

// SetRotateValue(62,29,i*30+clock_angle,1);

// tmp3=GetRotateXY(center_pos.x,center_pos.y-num_pos);

// SetFontSize(1);

// DrawNum(tmp3.x,tmp3.y,i,1);

// }

// else if(i<10)

// {

// tmp3=GetRotateXY(center_pos.x,center_pos.y-num_pos);

// SetFontSize(1);

// DrawNum(tmp3.x,tmp3.y,i,1);

// }

// else if(i<12)

// {

// tmp3=GetRotateXY(center_pos.x,center_pos.y-num_pos);

// SetFontSize(1);

// DrawNum(tmp3.x,tmp3.y,i,2);

// }

// }

DrawFillCircle(center_pos.x,center_pos.y,2);//中心圆点

DrawCircle(center_pos.x,center_pos.y,CLOCK_R);

UpdateScreen();

ClearScreen();

}

步数记录

代码设计过程参考了CSDN上的一篇博客


前面是一些基本的滤波以及求峰值,后面才是计算是否走步。



filter_acc();

peak_caculate();

slid_update(&temp_acc,&mpu);

detect_step(&peak_acc,&temp_acc,&mpu);

下面是判断是否走步的代码:



void detect_step(peak_info *peak, slid_reg_t *slid, axis_info *cur_sample)

{

char res = is_most_active(peak);

switch (res) {

case MOST_ACTIVE_NULL: {

//fix

break;

}

case MOST_ACTIVE_X: {

short threshold_x = (peak->max_x + peak->min_x) / 2;

if (slid->old_sample.acc_x > threshold_x && slid->new_sample.acc_x < threshold_x) {

step_cnt ++;

}

break;

}

case MOST_ACTIVE_Y: {

short threshold_y = (peak->max_y + peak->min_y) / 2;

if (slid->old_sample.acc_y > threshold_y && slid->new_sample.acc_y < threshold_y) {

step_cnt ++;

}

break;

}

case MOST_ACTIVE_Z: {

short threshold_z = (peak->max_z + peak->min_z) / 2;

if (slid->old_sample.acc_z > threshold_z && slid->new_sample.acc_z < threshold_z) {

step_cnt ++;

}

break;

}

default: 

break;

}

}

简易下位机

参照我之前的项目,这次的下位机更加简单,没有头文件和结束语句,原因是max的串口我用的不是很明白,所以简化了



void fresh_s_time(char *temp)

{

    while(*temp != '\0')

    {

        switch(*temp++)

        {

case 'h':

hour = (*temp-'0')*10 + (*(temp+1)-'0');

temp+=2;

break;

case 'm':

min = (*temp-'0')*10 + (*(temp+1)-'0');

temp+=2;

break;

case 's':

sec = (*temp-'0')*10 + (*(temp+1)-'0');

temp+=2;

break;

       

        }

    }

}

上位机

也是和之前一样用的python编写


#-*- coding: UTF-8 -*- 


import serial # pyserial

import datetime


try:

    # 端口:CNU; Linux上的/dev /ttyUSB0等; windows上的COM3等

    portx = "COM3"


    # 波特率,标准值有:50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,19200,38400,57600,115200

    bps = 115200


    # 超时设置,None:永远等待操作;

    #         0:立即返回请求结果;

    #        其他:等待超时时间(单位为秒)

    timex = 5


    # 打开串口,并得到串口对象

    ser = serial.Serial(portx, bps, timeout=timex)


    # 写数据

    curr_time = datetime.datetime.now()

    result = ser.write(datetime.datetime.strftime(curr_time,'h%Hm%Ms%S').encode("gbk"))


    result = ser.write(datetime.datetime.strftime(curr_time,'s%S').encode("gbk"))


    ser.close() # 关闭串口


except Exception as e:

    print("error!", e)


程序流图以及各个模块

【E836】基于美信MAX32660的OLED智能手表设计

模块关系图:

【E836】基于美信MAX32660的OLED智能手表设计

目录│文件列表:

 └ max32660_-oled

    │ image-20210216221845791.png

    │ 上位机.py

    └ maxim32660

       │ ~$$逻辑关系系统框图‘.~vsdx

       │ 开发流程.md

       │ 文案.md

       │ 流程图.vsdx

       │ 流程图v1.1.png

       │ 逻辑关系系统框图.png

       │ 逻辑关系系统框图‘.vsdx

       └ maxim32660

          │ GPIO_my.c

          │ GPIO_my.h

          │ I2C_my.c

          │ I2C_my.h

          │ include.h

          │ main.c

          │ TIM_my.c

          │ TIM_my.h

          │ uart_my.c

          │ uart_my.h

          ├ ARM

          │  │ Abstract.txt

          │  │ GPIO.uvguix.张辰

          │  │ GPIO.uvoptx

          │  │ GPIO.uvprojx

          │  ├ Listings

          │  │  │ GPIO_Demo.map

          │  │  └ startup_max32660.lst

          │  ├ Objects

          │  │  │ board.crf

          │  │  │ board.d

          │  │  │ board.o

          │  │  │ clock.crf

          │  │  │ clock.d

          │  │  │ clock.o

          │  │  │ flc.crf

          │  │  │ flc.d

          │  │  │ flc.o

          │  │  │ gpio.crf

          │  │  │ gpio.d

          │  │  │ gpio.o

          │  │  │ gpio_1.crf

          │  │  │ gpio_1.d

          │  │  │ gpio_1.o

          │  │  │ GPIO_Debug.dep

          │  │  │ GPIO_Demo.axf

          │  │  │ GPIO_Demo.build_log.htm

          │  │  │ GPIO_Demo.hex

          │  │  │ GPIO_Demo.htm

          │  │  │ GPIO_Demo.lnp

          │  │  │ GPIO_Demo.sct

          │  │  │ gpio_my.crf

          │  │  │ gpio_my.d

          │  │  │ gpio_my.o

          │  │  │ i2c.crf

          │  │  │ i2c.d

          │  │  │ i2c.o

          │  │  │ i2c_1.crf

          │  │  │ i2c_1.d

          │  │  │ i2c_1.o

          │  │  │ i2c_my.crf

          │  │  │ i2c_my.d

          │  │  │ i2c_my.o

          │  │  │ icc.crf

          │  │  │ icc.d

          │  │  │ icc.o

          │  │  │ led.crf

          │  │  │ led.d

          │  │  │ led.o

          │  │  │ lp.crf

          │  │  │ lp.d

          │  │  │ lp.o

          │  │  │ main.crf

          │  │  │ main.d

          │  │  │ main.o

          │  │  │ mpu6050.crf

          │  │  │ mpu6050.d

          │  │  │ mpu6050.o

          │  │  │ mxc_assert.crf

          │  │  │ mxc_assert.d

          │  │  │ mxc_assert.o

          │  │  │ mxc_delay.crf

          │  │  │ mxc_delay.d

          │  │  │ mxc_delay.o

          │  │  │ mxc_lock.crf

          │  │  │ mxc_lock.d

          │  │  │ mxc_lock.o

          │  │  │ mxc_pins.crf

          │  │  │ mxc_pins.d

          │  │  │ mxc_pins.o

          │  │  │ mxc_sys.crf

          │  │  │ mxc_sys.d

          │  │  │ mxc_sys.o

          │  │  │ nvic_table.crf

          │  │  │ nvic_table.d

          │  │  │ nvic_table.o

          │  │  │ oled_basic.crf

          │  │  │ oled_basic.d

          │  │  │ oled_basic.o

          │  │  │ oled_bmp.crf

          │  │  │ oled_bmp.d

          │  │  │ oled_bmp.o

          │  │  │ oled_buffer.crf

          │  │  │ oled_buffer.d

          │  │  │ oled_buffer.o

          │  │  │ oled_color.crf

          │  │  │ oled_color.d

          │  │  │ oled_color.o

          │  │  │ oled_config.crf

          │  │  │ oled_config.d

          │  │  │ oled_config.o

          │  │  │ oled_debug.crf

          │  │  │ oled_debug.d

          │  │  │ oled_debug.o

          │  │  │ oled_draw.crf

          │  │  │ oled_draw.d

          │  │  │ oled_draw.o

          │  │  │ oled_driver.crf

          │  │  │ oled_driver.d

          │  │  │ oled_driver.o

          │  │  │ oled_font.crf

          │  │  │ oled_font.d

          │  │  │ oled_font.o

          │  │  │ pb.crf

          │  │  │ pb.d

          │  │  │ pb.o

          │  │  │ rtc.crf

          │  │  │ rtc.d

          │  │  │ rtc.o

          │  │  │ spi.crf

          │  │  │ spi.d

          │  │  │ spi.o

          │  │  │ spi17y.crf

          │  │  │ spi17y.d

          │  │  │ spi17y.o

          │  │  │ spimss.crf

          │  │  │ spimss.d

          │  │  │ spimss.o

          │  │  │ startup_max32660.d

          │  │  │ startup_max32660.o

          │  │  │ stdio.crf

          │  │  │ stdio.d

          │  │  │ stdio.o

          │  │  │ system_max32660.crf

          │  │  │ system_max32660.d

          │  │  │ system_max32660.o

          │  │  │ tim_my.crf

          │  │  │ tim_my.d

          │  │  │ tim_my.o

          │  │  │ tmr.crf

          │  │  │ tmr.d

          │  │  │ tmr.o

          │  │  │ tmr_utils.crf

          │  │  │ tmr_utils.d

          │  │  │ tmr_utils.o

          │  │  │ tracer_api.crf

          │  │  │ tracer_api.d

          │  │  │ tracer_api.o

          │  │  │ uart.crf

          │  │  │ uart.d

          │  │  │ uart.o

          │  │  │ uart_my.crf

          │  │  │ uart_my.d

          │  │  └ uart_my.o

          │  └ RTE

          │     ├ Device

          │     │  └ MAX32660

          │     │     │ mxc_config.h

          │     │     │ startup_max32660.s

          │     │     └ system_max32660.c

          │     └ _Debug

          │        └ RTE_Components.h

          ├ CLOCK

          │  │ CLOCK.c

          │  └ CLOCK.h

          ├ IAR

          │  │ GPIO.ewd

          │  └ GPIO.ewp

          ├ MPU6050

          │  │ mpu6050.c

          │  │ mpu6050.c.orig

          │  │ mpu6050.h

          │  └ eMPL

          │     │ dmpKey.h

          │     │ dmpmap.h

TAGMAX32660
  • 2 次
  • 1 分