项目描述:
准备制作一个宠物(兔子/狗)自动定时喂食机。由于出差、旅游或回家过年等原因,有时会有一周的时间不在家,但是所喂养的小动物又没人照顾,所以想借此机会在学习Freescale的Cortex-m0的KL25 MCU的同时,解决这个问题。
项目目标:可提供7天,每天3次的自动投食。3次的投食时间可设置。
后续可扩展:喂水,音乐或主人声音播放,增加雨棚的自动控制(要加雨滴传感器)。
使用KL25的:RTCGPIOPWM低功耗休眠及唤醒,实现按键、LCD驱动、步进电机驱动、时钟功能、闹钟功能(通过闹钟实现定时喂食)
系统框图:
系统框图.JPG (48.27 KB, 下载次数: 0)
下载附件
2015-1-13 19:48 上传
总费用:313元
7个小步进电机及驱动板 9X7=63 之所以采用7个步进电机,是担心7天的食物重量太重,一个步进电机带不动。另外就是考虑到宠物安全问题,希望采用锂电池供电,小电机锂电池可以带的动,当然也可以小蓄电池供电。一天分3次步进,对应3次喂食。
1个128X64点阵液晶屏 25
1个锂电池充电升压模块 10 时间紧张,就使用现成模块,实际上可以自己搭电路。
其他零件、结构费用: 50 不需要打板,自己用洞洞板搭。
如果KL25的RTC不适用,会采用时钟模块。
时钟模块、锂电池自备、电源适配器自备
计划完成时间:
预计完成的时间。
预计两个月完成。争取春节前可用。
版权:
作品的版权归作者本人所有。授权发布在阿莫网站上,阿莫网站和飞思卡尔拥有资料的发布权和使用权。
先发个时钟部分代码吧。调试已经通过。
- #include "includes.h" //包涵总头文件
- void MCGIRCLK_OutEnable(uint_8 clock); //启用内部快速时钟
- volatile uint_16 DSEC;
- unsigned char const MONTH_Table[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- unsigned int Time_MARK[6] = {2015,2,3,23,59,50};
- unsigned int Time_LAST[6] = {2000,8,18,18,18,18};
- #define YEAR Time_MARK[0]
- #define MONTH Time_MARK[1]
- #define DATE Time_MARK[2]
- #define HOUR Time_MARK[3]
- #define MINUTE Time_MARK[4]
- #define SECOND Time_MARK[5]
- int main(void)
- {
- //1.声明主函数使用的局部变量
- uint_8 i,j;
- uint_8 * g_time[] ={"00","01","02","03","04","05","06","07","08","09",
- "10","11","12","13","14","15","16","17","18","19",
- "20","21","22","23","24","25","26","27","28","29",
- "30","31","32","33","34","35","36","37","38","39",
- "40","41","42","43","44","45","46","47","48","49",
- "50","51","52","53","54","55","56","57","58","59",
- }; //0~59字符LCD显示转换
- uint_8 g_DispalyInit1[20] = "Now time is 88:88:88";
- uint_8 g_DispalyInit2[20] = " 2015-01-28";
- uint_8 g_DispalyInit3[20] = "Last feed time 88:88";
- uint_8 g_DispalyInit4[20] = "Next feed time 88:88";
- //2.关总中断
- DISABLE_INTERRUPTS;
- //3.初始化底层模块
- LEDInit(); //LED初始化
- LCDInit(); //LCD初始化
- KBInit(); //键盘初始化
- tpm_init(TPM0,TPM_CLKSRC_PLL,1000); //初始化TPM模块,1ms中断一次
- //4. 给有关变量赋初值
- i = 0;
- //LCD输出格式化
- LCD_write_String(1,0,g_DispalyInit1,20);
- LCD_write_String(2,0,g_DispalyInit2,20);
- LCD_write_String(3,0,g_DispalyInit3,20);
- LCD_write_String(4,0,g_DispalyInit4,20);
- //5. 使能模块中断
- tpm_enable_int(0);
- //6. 开总中断
- ENABLE_INTERRUPTS;
- for(;;)
- {
- Clock_OnTimer();
- if(DSEC == 0) //判断秒钟是否发生变化
- {
- if(Time_LAST[3] != HOUR)
- {
- i = HOUR;
- LCD_write_String(1,12,g_time[i],2);
- Time_LAST[3] = HOUR;
- }
- if(Time_LAST[4] != MINUTE)
- {
- i = MINUTE;
- LCD_write_String(1,15,g_time[i],2);
- Time_LAST[4] = MINUTE;
- }
- if(Time_LAST[5] != SECOND)
- {
- i = SECOND;
- LCD_write_String(1,18,g_time[i],2);
- Time_LAST[5] = SECOND;
- }
- if(Time_LAST[0] != YEAR)
- {
- i = 20;
- LCD_write_String(2,10,g_time[i],2);
- j = YEAR%100;
- LCD_write_String(2,12,g_time[j],2);
- Time_LAST[0] = YEAR;
- }
- if(Time_LAST[1] != MONTH)
- {
- i = MONTH;
- LCD_write_String(2,15,g_time[i],2);
- Time_LAST[1] = MONTH;
- }
- if(Time_LAST[2] != DATE)
- {
- i = DATE;
- LCD_write_String(2,18,g_time[i],2);
- Time_LAST[2] = DATE;
- }
- }
- }
- //===========================================================================
- return 0;
- }
- //启用MCGIRCLK时钟,输出时钟频率在31.25Khz ~ 4Mhz
- void MCGIRCLK_OutEnable(uint_8 clock)
- {
- PORTC_PCR3 = PORT_PCR_MUX(0x5);
- SIM_SOPT2 = SIM_SOPT2_CLKOUTSEL(clock); //复用PTC3为CLKOUT,观测输出时钟波形
- MCG_C1 |= MCG_C1_IRCLKEN_MASK|MCG_C1_IREFSTEN_MASK;
- MCG_C2 &= ~MCG_C2_IRCS_MASK;
- }
- void Clock_OnTimer()
- {
- unsigned char Days = 31;
- if (DSEC >= 1000)
- {
- DSEC = 0;
- SECOND++;
- } //1秒一次
- if (SECOND >= 60)
- {
- SECOND = 0;
- MINUTE++;
- } //60秒一次
- if (MINUTE >= 60)
- {
- MINUTE = 0;
- HOUR++;
- } //60分一次
- if (HOUR >= 24)
- {
- HOUR = 0;
- DATE++;
- if (MONTH == 2) //处理润年2月份问题
- {
- if (YEAR % 4 == 0)
- {
- Days = 29; //逢4润
- }
- else
- {
- Days = 28;
- }
- if (YEAR % 400 == 0)
- {
- Days = 28; //逢400不润
- }
- }
- else
- {
- Days = MONTH_Table[MONTH - 1]; //正常月份,查表得到当月天数
- }
- } //24小时一次
- if (DATE > Days) {
- DATE = 1;
- MONTH++;
- } //一个月一次
- if (MONTH > 12)
- {
- MONTH = 1;
- YEAR++;
- } //一年一次
- }
复制代码一周热门 更多>