分享瑞薩單片機計步器設計,包含程序及原理圖
0.png (99.18 KB, 下載次數: 65)
下載附件
2019-5-8 01:51 上傳
0.png (107.76 KB, 下載次數: 58)
下載附件
2019-5-8 01:51 上傳
單片機源程序如下:
- /***********************************************************************************************************************
- * File Name : r_main.c
- * Version : V1.00
- * Device(s) : R7F0C002G2DFB
- * Tool-Chain : CA78K0R
- * Description : This file implements main function.
- ***********************************************************************************************************************/
- /***********************************************************************************************************************
- * History : DD.MM.YYYY Version Description
- * : 31.03.2015 1.00 First Release
- ***********************************************************************************************************************/
- /***********************************************************************************************************************
- Includes <System Includes> , <Project Includes>
- ***********************************************************************************************************************/
- #include "r_macrodriver.h"
- #include "r_cgc.h"
- #include "r_port.h"
- #include "string.h"
- #include "r_lcd.h"
- #include "r_rtc.h"
- #include "r_timer.h"
- #include "r_userdefine.h"
- #include "r_Communication.h"
- #include "r_ADXL362.h"
- #include "pfdl.h"
- #include "pfdl_types.h"
- /***********************************************************************************************************************
- Global variables and functions
- ***********************************************************************************************************************/
- static uint16_t g_FontData[LCD_NUM_DATA_FONT_COUNT] = { LCD_DATA_0, LCD_DATA_1, LCD_DATA_2, LCD_DATA_3, LCD_DATA_4,
- LCD_DATA_5, LCD_DATA_6, LCD_DATA_7, LCD_DATA_8, LCD_DATA_9,
- LCD_DATA_NONE, LCD_DATA_COLON };
- static uint8_t g_WatchStatus;
- static uint8_t g_WeightStatus;
- static uint8_t g_Hour;
- static uint8_t g_Minute;
- uint8_t g_Weight = 0x40U;
- uint8_t g_Length = 0x70U;
- uint16_t g_Step;
- uint16_t g_Step_last;
- uint8_t Count_flag = 0U;
- uint8_t g_Step_temp1[2] = {0x00,0x00};
- uint8_t g_Step_temp2[2] = {0x00,0x00};
- uint16_t g_Calorie;
- uint8_t set_flag = 0U;
- uint8_t step1_flag = 0U;
- uint8_t step2_flag = 0U;
- uint8_t switch_status = 0U;
- uint8_t status = 0U;
- short xAxis = 0U;
- short yAxis = 0U;
- short zAxis = 0U;
- float temperature = 0U;
- pfdl_u16 StartAddrIndex = 0U;
- #define FALSE 0
- #define TRUE 1
- #define BLOCKBYTES 1024
- void R_MAIN_UserInit(void);
- pfdl_u08 Write_DataFlash(void);
- pfdl_u08 Read_DataFlash(void);
- pfdl_u08 Erase_DataFlash(pfdl_u16 block);
- /***********************************************************************************************************************
- * Function Name: main
- * Description : This function implements main function.
- * Arguments : None
- * Return Value : None
- ***********************************************************************************************************************/
- void main(void)
- {
- uint8_t set_count = 0U;
- uint8_t count = 0U;
- rtc_counter_value_t time_data;
- g_Hour = 0x00U;
- g_Minute = 0x00U;
-
- R_MAIN_UserInit();
- Read_DataFlash();
- g_Step_last = (((short)g_Step_temp2[1] << 8) + g_Step_temp2[0]);
- if(0xFFFFU == g_Step_last)
- g_Step_last = 0U;
- while(1U)
- {
- switch_status = R_MAIN_Get_SwitchStatus();
- if((0x23U == HOUR) && (0x59U == MIN) && (0x59U == SEC)&& (1U == RIFG))
- {
- DI();
- RIFG = 0U;
- g_Step_temp1[0] = (uint8_t)(g_Step & 0x00ff);
- g_Step_temp1[1] = (uint8_t)((g_Step >> 8) & 0x00ff);
- Write_DataFlash();
- g_Step = 0U;
- g_Calorie = 0U;
- Read_DataFlash();
- g_Step_last = (((short)g_Step_temp2[1] << 8) + g_Step_temp2[0]);
- EI();
- }
- if(0U == set_flag)
- {
- switch(count)
- {
- case 0:
- {
- R_RTC_Get_CounterValue(&time_data);
- g_Hour = time_data.hour;
- g_Minute = time_data.min;
- /* ---- Time displays on LCD ---- */
- R_MAIN_LcdDisplayNormal();
- }
- break;
-
- case 1:
- {
- /* ---- Steps displays on LCD ---- */
- R_MAIN_LcdStepDisplayNormal();
- }
- break;
-
- case 2:
- {
-
- /* ---- Carlorie displays on LCD ---- */
- R_MAIN_LcdCalorieDisplayNormal();
- }
- break;
-
- case 3:
- {
- /* ---- Last Steps displays on LCD ---- */
- R_MAIN_LcdLastStepDisplayNormal();
- }
- break;
- default:
- break;
- }
- if(switch_status == TRANS_SWITCH_ON)
- {
- count++;
- if(4U == count)
- count = 0U;
- }
- }
- else if(1U == set_flag)
- {
- switch(set_count)
- {
- case 0 :
- {
- R_MAIN_LcdHourBlink();
- if(UP_SWITCH_ON == switch_status)
- {
- g_Hour = adbcdb(g_Hour, 1U);
- /* ---- When hour data is 0x24 ---- */
- if (0x24U == g_Hour)
- {
- g_Hour = 0x00U;
- }
- time_data.hour = g_Hour;
- R_RTC_Set_CounterValue(time_data);
- }
- else if(DOWN_SWITCH_ON == switch_status)
- {
- g_Hour = sbbcdb(g_Hour, 1U);
- if (0x99U == g_Hour)
- {
- g_Hour = 0x23U;
- }
- time_data.hour = g_Hour;
- R_RTC_Set_CounterValue(time_data);
- }
- }
- break;
-
- case 1 :
- {
- R_MAIN_LcdMinuteBlink();
- if(UP_SWITCH_ON == switch_status)
- {
- g_Minute = adbcdb(g_Minute, 1U);
- /* ---- When hour data is 0x24 ---- */
- if (0x60U == g_Minute)
- {
- g_Minute = 0x00U;
- }
- time_data.min = g_Minute;
- R_RTC_Set_CounterValue(time_data);
- }
- else if(DOWN_SWITCH_ON == switch_status)
- {
- g_Minute = sbbcdb(g_Minute, 1U);
- /* ---- When hour data is 0x24 ---- */
- if (0x99U == g_Minute)
- {
- g_Minute = 0x59U;
- }
- time_data.min = g_Minute;
- R_RTC_Set_CounterValue(time_data);
- }
-
- }
- break;
-
- case 2 :
- {
- R_MAIN_LcdWeightBlink();
- if(UP_SWITCH_ON == switch_status)
- {
- g_Weight = adbcdb(g_Weight, 1U);
- /* ---- When hour data is 0x24 ---- */
- if (0x9AU == g_Weight)
- {
- g_Weight = 0x00U;
- }
- }
- else if(DOWN_SWITCH_ON == switch_status)
- {
- /* ---- When hour data is 0x24 ---- */
- if (0x00U == g_Weight)
- {
- g_Weight = 0x9AU;
- }
- g_Weight = sbbcdb(g_Weight, 1U);
- }
- }
- break;
-
- case 3 :
- {
- R_MAIN_LcdLengthBlink();
- if(UP_SWITCH_ON == switch_status)
- {
- g_Length = adbcdb(g_Length, 1U);
- /* ---- When hour data is 0x24 ---- */
- if (0x9AU == g_Length)
- {
- g_Length = 0x00U;
- }
- }
- else if(DOWN_SWITCH_ON == switch_status)
- {
- /* ---- When hour data is 0x24 ---- */
- if (0x00U == g_Length)
- {
- g_Length = 0x9AU;
-
- }
- g_Length = sbbcdb(g_Length, 1U);
- }
- }
- break;
-
- default:
- break;
- }
- if(TRANS_SWITCH_ON == switch_status)
- {
- set_count++;
- if(4U == set_count)
- {
- set_count = 0U;
- set_flag = 0U;
- }
- }
- }
- }
- }
- /***********************************************************************************************************************
- End of function main
- ***********************************************************************************************************************/
- /***********************************************************************************************************************
- * Function Name: R_MAIN_UserInit
- * Description : This function adds user code before implementing main function.
- * Arguments : None
- * Return Value : None
- ***********************************************************************************************************************/
- void R_MAIN_UserInit(void)
- {
- EI();
-
- R_LCD_Start();
- /* ---- Initialize display ---- */
- memset(LCD_POSITION_MINUTE_LOW, LCD_DATA_NONE, 9U);
- g_WatchStatus = WATCH_DISPLAY;
- R_RTC_Set_ConstPeriodInterruptOn(ONESEC);
- R_RTC_Start();
- R_TAU0_Channel0_Start();
- R_TAU0_Channel1_Start();
- /* Init device ADXL362. */
- ADXL362_Init();
- /* Put the device in standby mode. */
- ADXL362_SetPowerMode(0U);
- /* Set accelerometer's output data rate to: 12.5 Hz. */
- ADXL362_SetOutputRate(ADXL362_ODR_12_5_HZ);
- /* Setup the activity and inactivity detection. */
- ADXL362_SetRegisterValue(
- ADXL362_ACT_INACT_CTL_LINKLOOP(ADXL362_MODE_LINK),
- ADXL362_REG_ACT_INACT_CTL,
- 1U);
- ADXL362_SetupActivityDetection(1U, 30U, 1U);
- ADXL362_SetupInactivityDetection(1U, 700U, 25U);
- /* Start the measurement process. */
- ADXL362_SetPowerMode(1U);
- /* Clear ACT and INACT bits by reading the Status Register. */
- ADXL362_GetRegisterValue(&status,
- ADXL362_REG_STATUS,
- 1U);
- }
- /***********************************************************************************************************************
- End of function R_MAIN_UserInit
- ***********************************************************************************************************************/
- /***********************************************************************************************************************
- * Function Name: R_MAIN_GetSwitchStatus
- * Description : This function get switch status.
- * Arguments : None
- * Return Value : switch_status -The kind of pushed switch
- ***********************************************************************************************************************/
- uint8_t R_MAIN_Get_SwitchStatus(void)
- {
- uint8_t set_switch;
- uint8_t up_switch;
- uint8_t down_switch;
- uint8_t trans_switch;
- uint8_t switch_status = SWITCH_ALL_OFF;
- set_switch = P2.1;
- up_switch = P2.0;
- down_switch = P14.4;
- trans_switch = P14.3;
- /* ---- Set switch status ---- */
- if ((0U == set_switch) && (1U == up_switch) && (1U == down_switch) && (1U == trans_switch))
- {
- R_MAIN_Delay1ms(10U);
- set_switch = P2.1;
- up_switch = P2.0;
- down_switch = P14.4;
- trans_switch = P14.3;
- if((0U == set_switch) && (1U == up_switch) && (1U == down_switch) && (1U == trans_switch))
- {
- while(0U == set_switch)
- {
- set_switch = P2.1;
- set_flag = 1U;
- }
- switch_status = SET_SWITCH_ON;
- }
- }
- else if ((1U == set_switch) && (0U == up_switch) && (1U == down_switch) && (1U == trans_switch))
- {
- R_MAIN_Delay1ms(10U);
- set_switch = P2.1;
- up_switch = P2.0;
- down_switch = P14.4;
- trans_switch = P14.3;
- if((1U == set_switch) && (0U == up_switch) && (1U == down_switch) && (1U == trans_switch))
- {
- while(0U == up_switch)
- {
- up_switch = P2.0;
- }
- switch_status = UP_SWITCH_ON;
- }
- }
- else if ((1U == set_switch) && (1U == up_switch) && (0U == down_switch) && (1U == trans_switch))
- {
- R_MAIN_Delay1ms(10U);
- set_switch = P2.1;
- up_switch = P2.0;
- down_switch = P14.4;
- trans_switch = P14.3;
- if((1U == set_switch) && (1U == up_switch) && (0U == down_switch) && (1U == trans_switch))
- {
- while(0U == down_switch)
- {
- down_switch = P14.4;
- }
- switch_status = DOWN_SWITCH_ON;
- }
- }
- else if ((1U == set_switch) && (1U == up_switch) && (1U == down_switch) && (0U == trans_switch))
- {
- R_MAIN_Delay1ms(10U);
- set_switch = P2.1;
- up_switch = P2.0;
- down_switch = P14.4;
- trans_switch = P14.3;
- if((1U == set_switch) && (1U == up_switch) && (1U == down_switch) && (0U == trans_switch))
- {
- while(0U == trans_switch)
- {
- trans_switch = P14.3;
- }
- switch_status = TRANS_SWITCH_ON;
- }
- }
- else
- {
- /* Do Nothing */
- }
- return (switch_status);
- }
- /***********************************************************************************************************************
- End of function R_MAIN_GetSwitchStatus
- ***********************************************************************************************************************/
- /***********************************************************************************************************************
- * Function Name: R_MAIN_LcdHourBlink
- * Description : This function hour blink data setup.
- * Arguments : None
- * Return Value : None
- ***********************************************************************************************************************/
- void R_MAIN_LcdHourBlink(void)
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
0.png (9.12 KB, 下載次數: 67)
下載附件
2019-5-8 01:52 上傳
所有資料51hei提供下載:
電子計步器設計方案,附原理圖+PCB源文件+源代碼+BOM清單.zip
(3.92 MB, 下載次數: 61)
2019-5-7 19:18 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
r7f0c002_pedometer_brochure.pdf
(287.65 KB, 下載次數: 27)
2019-5-7 19:19 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|