本帖最后由 可乐丸子 于 2017-5-1 12:46 编辑
抱歉,因为之前笔记本和 手机被盗,存储在上面的资料都丢失了,所以结项比较晚。好了回归正题,笔者下面介绍使用LinkIT 7687 开发板、LCD1602液晶屏、PCF8574转换板、面包板、两个4.7K欧姆电阻打造数字时钟硬件配置
首先将LCD1602和PCF8574转换板按下图连接
然后将LinkIt 7687开发板、电阻、面包板用杜邦线按下图连接到LCD1602
这样就完成了硬件配置
软件配置
下载SDK
https://labs.mediatek.com/zh-cn/download/IK02Cbc5
然后如果使用的Ubuntu就按下面下载编译工具
- sudo apt-get install build-essential
复制代码
64位Ubuntu或者Debian还要下载安装下面组件
- sudo dpkg --add-architecture i386
- sudo apt-get update
- sudo apt-get install libc6-i386
复制代码
如果使用的Windows系统可以下载下面软件mingw
https://sourceforge.net/projects/mingw/files/Installer/mingw-get-setup.exe/download
下载安装后按下图配置
C:MinGWmsys1.0 目录,并且执行 msys.bat 来开启 MinGW 终端窗口
下载了SDK后在Debian或者Ubuntu里面解压SDK
- mkdir sdk_root
- tar zxvpf LinkIt_SDK_V3.3.1_public.tar.gz -C sdk_root
- tar -xv*** SDK_VX.Y.Z_tool_chain.tar.gz -C
复制代码
Windows下面的按下操作:
将 /tools/PC_tool.zip 复制至您的 Windows 计算机。
在 Windows 中解压缩PC_tool.zip 文档解压缩的目的地目录,在后面的章节当中,将一律简称为
若您打算在 Windows MinGW 环境中编译项目,请依照本步骤准备 GCC 工具链:
从此链接下载 GCC 工具链,文件名 gcc-ARM-none-eabi-4_8-2014q3-20140805-win32.zip 。
在toolsgcc下创建一个名为 win 的新文件 夹。
将gcc-arm-none-eabi-4_8-2014q3-20140805-win32.zip 解压缩至 toolsgccwin 文件夹。
将解压缩后的 gcc-arm-none-eabi-4_8-2014q3-20140805-win32 文件夹改名为 gcc-arm-none-eabi 。最后所形成的目录,应该有如下的文件:
toolsgccwingcc-arm-none-eabibinarm-none-eabi-gcc.exe
下面开始创建项目,在 /project/mt7687_hdk/apps文件夹中创建一个digitalclock文件夹
- mkdir /project/mt7687_hdk/apps/digitalclock
复制代码
然后将/project/mt7687_hdk/apps/freertos_thread_creation中文件拷贝到digitalclock目录
- cd /project/mt7687_hdk/apps
- cp -r freertos_thread_creation digitalclock
复制代码
修改 Makefile 设定
- vi /project/mt7687_hdk/apps/digitalclock/GCC/Makefile
复制代码
修改里面的PROJ_NAME和APP_PATH定义
- # Project name
- PROJ_NAME = digitalclock
- APP_PATH = project/mt7687_hdk/apps/digitalclock
复制代码
编辑main函数
- vi /project/mt7687_hdk/apps/digitalclock/src/main.c
复制代码
复制粘贴如下进去
- #define AP_SSID "your_SSID"
- #define AP_PWD "your_pwd"
- #define NTP_SERVER1 "time.stdtime.gov.tw"
- #define NTP_SERVER2 "clock.stdtime.gov.tw"
- #define TIMEZONE_OFFSET 8
- #define CURR_CENTURY 2000
- /* End of modification */
- #include
- #include
- #include
- #include "FreeRTOS.h"
- #include "task.h"
- #include "os.h"
- #include "sys_init.h"
- #include "wifi_api.h"
- #include "network.h"
- #include "sntp.h"
- #include "syslog.h"
- #include "hal.h"
- #include
- #include "lcd.h"
- #define US2TICK(us) (us/(1000*portTICK_RATE_MS))
- #define MS2TICK(ms) (ms/(portTICK_RATE_MS))
- static void _timezone_shift(hal_rtc_time_t* t, int offset_hour)
- {
- struct tm gt;
- struct tm *nt;
- time_t secs;
- gt.tm_year = t->rtc_year + (CURR_CENTURY-1900);
- gt.tm_mon = t->rtc_mon-1;
- gt.tm_mday = t->rtc_day;
- gt.tm_wday = t->rtc_week;
- gt.tm_hour = t->rtc_hour;
- gt.tm_min = t->rtc_min;
- gt.tm_sec = t->rtc_sec;
- secs = mktime(>);
- secs += offset_hour * 3600;
- nt = gmtime(&secs);
- if (!nt) {
- nt = localtime(&secs);
- }
- t->rtc_year = (nt->tm_year % 100);
- t->rtc_mon = nt->tm_mon + 1;
- t->rtc_day = nt->tm_mday;
- t->rtc_week = nt->tm_wday;
- t->rtc_hour = nt->tm_hour;
- t->rtc_min = nt->tm_min;
- t->rtc_sec = nt->tm_sec;
- }
- static void _sntp_check_loop(void)
- {
- hal_rtc_time_t r_time;
- hal_rtc_status_t ret;
- while(1) {
- ret = hal_rtc_get_time(&r_time);
- if (ret == 0)
- {
- char buf[20];
- _timezone_shift(&r_time, TIMEZONE_OFFSET);
- LOG_I(common, "%04d/%d/%d %02d:%02d:%02d", r_time.rtc_year+CURR_CENTURY, r_time.rtc_mon, r_time.rtc_day, r_time.rtc_hour, r_time.rtc_min, r_time.rtc_sec);
- rgblcd_clear();
- snprintf(buf, 19, "%04d/%d/%d", r_time.rtc_year+CURR_CENTURY, r_time.rtc_mon, r_time.rtc_day);
- rgblcd_setCursor(0, 0);
- rgblcd_write_str(buf);
- snprintf(buf, 19, "%02d:%02d:%02d", r_time.rtc_hour, r_time.rtc_min, r_time.rtc_sec);
- rgblcd_setCursor(0, 1);
- rgblcd_write_str(buf);
- }
- // wait 1 sec and retry
- vTaskDelay(MS2TICK(1000));
- }
- }
- static void _i2c_write(uint8_t addr, uint8_t* data, uint8_t dataLen)
- {
- hal_i2c_status_t ret;
- ret = hal_i2c_master_send_polling(HAL_I2C_MASTER_0, addr, data, dataLen);
- if(HAL_I2C_STATUS_OK != ret)
- {
- LOG_E(common, "_i2c_write(%X) FAIL: %d", addr, ret);
- }
- }
- static void lcd_init(void)
- {
- hal_i2c_config_t i2c_init;
- hal_gpio_init(HAL_GPIO_27);
- hal_gpio_init(HAL_GPIO_28);
- hal_pinmux_set_function(HAL_GPIO_27,HAL_GPIO_27_I2C1_CLK);
- hal_pinmux_set_function(HAL_GPIO_28,HAL_GPIO_28_I2C1_DATA);
- hal_gpio_pull_up(HAL_GPIO_27);
- hal_gpio_pull_up(HAL_GPIO_28);
- i2c_init.frequency = HAL_I2C_FREQUENCY_100K;
- hal_i2c_master_init(HAL_I2C_MASTER_0, &i2c_init);
- rgblcd_registerFunc(_i2c_write);
- }
- static void main_task(void *args)
- {
- LOG_I(common, "LCD init");
- lcd_init();
- rgblcd_begin(16, 2);
- LOG_I(common, "LCD init done");
- rgblcd_setRGB(255, 0, 0);
- rgblcd_setCursor(0, 0);
- rgblcd_write_str("Connecting AP...");
- LOG_I(common, "network init: %s, %s", AP_SSID, AP_PWD);
- network_init(AP_SSID, AP_PWD);
- LOG_I(common, "network init done");
- rgblcd_setRGB(0, 255, 0);
- rgblcd_clear();
- //SNTP start.
- sntp_setservername(0, NTP_SERVER1);
- sntp_setservername(1, NTP_SERVER2);
- sntp_init();
- LOG_I(common, "SNTP inited");
- vTaskDelay(MS2TICK(1000));
- _sntp_check_loop();
- }
- int main(void)
- {
- log_config_print_level(hal, PRINT_LEVEL_WARNING);
- system_init();
- xTaskCreate(main_task, "main task", 1024, NULL, 1, NULL);
- vTaskStartScheduler();
- /* If all is well, the scheduler will now be running, and the following line
- will never be reached. If the following line does execute, then there was
- insufficient FreeRTOS heap memory available for the idle and/or timer tasks
- to be created. See the memory management section on the FreeRTOS web site
- for more details. */
- for ( ;; );
- }
复制代码
其中需要修改的参数如下,AP_SSID为无线信号名称、AP_PWD为无线信号密码,NTP_SERVER1和NTP_SERVER2为NTP服务器地址,TIMEZONE_OFFSET为时区,CURR_CENTURY为目前世纪
- #define AP_SSID "your_SSID"
- #define AP_PWD "your_pwd"
- #define NTP_SERVER1 "time.stdtime.gov.tw"
- #define NTP_SERVER2 "clock.stdtime.gov.tw"
- #define TIMEZONE_OFFSET 8
- #define CURR_CENTURY 2000
- /* End of modification */
复制代码
修改好main函数后保存修改,然后切换到项目文件夹开始编译
- cd /project/mt7687_hdk/apps/digitalclock/GCC
- make
复制代码
编译完成后将build下文件夹拷贝出来,按下面方法下载到开发板然后上电即可完成程序烧写
https://docs.labs.mediatek.com/resource/mt7687-mt7697/zh_cn/get-started-linkit-7687/gcc-arm-embedded-command-line-tools-free/download-a-pre-built-binary-example
效果如下图
0
|
|
|
|