前述: QQ:961209458 V X:F9986858 承接毕业设计。
功能
设计内容:
1)温度控制、步进电机控制、定时控制三个控制部分; 2)时间、温度、步进电机转速显示; 3)录音模块。
设计要求:
1)定时喂食。能够根据不同宠物种类以及主人喂养宠物的方式习惯,自己定义时间为宠物提供食物; 2)定量喂食。通过步进电机的定时转速实现控制定量宠物粮食; 3)实时显示。OLED将检测的参数数据实时显示到屏幕上,显示时间、温度、步进电机转速转速; 4)语音提示。自定义录音,实现当到达定时喂食的时间时自动播放提示音宠物前来进食; 5)设置投喂量。设置控制步进电机转动时间,从而控制食物量多少。
本设计达到的目的:
能够自定义时间为宠物提供食物; 通过步进电机的定时转速实现控制定量宠物粮食; OLED将检测的参数数据实时显示到屏幕上; 自定义录音提示音宠物前来进食; 设置步进电机控制食物量。 通过语音模块录制语音信息,再按键设定喂食时间,屏幕显示数据信息。 到达所设置的时间,语音模块自动播放语音吸引宠物前来进食,同时单片机控制电机驱动工作,控制定量食物。
演示视频
演示视频
硬件电路
单片机代码
#include "REG51.h"
#include "oled.h"
#include "bmp.h"
#include "Ds18b20.h"
#include "DS1302.h"
#include "JQ8900.h"
#include "delay.h"
sbit K1 = P3^2;
sbit K2 = P3^3;
sbit K3 = P3^4;
sbit K4 = P3^5;
sbit IN1 = P1^3;
sbit IN2 = P1^4;
sbit IN3 = P1^5;
sbit IN4 = P1^6;
char FeedHour = 12;
char FeedMinter = 1;
char speed = 7;
int count50ms=200;
char MP3 = 1;
bit FeedOnOff=1;
char FeedTimeChange = 0;
void Delay_xms(u16 x)
{
u16 i,j;
for(i=0;i<x;i++)
for(j=0;j<112;j++);
}
void MotorCW(void)
{
IN1 = 1;IN2 = 0;IN3 = 0;IN4 = 1;Delay_xms(speed);
IN1 = 0;IN2 = 0;IN3 = 0;IN4 = 1;Delay_xms(speed);
IN1 = 0;IN2 = 0;IN3 = 1;IN4 = 1;Delay_xms(speed);
IN1 = 0;IN2 = 0;IN3 = 1;IN4 = 0;Delay_xms(speed);
IN1 = 0;IN2 = 1;IN3 = 1;IN4 = 0;Delay_xms(speed);
IN1 = 0;IN2 = 1;IN3 = 0;IN4 = 0;Delay_xms(speed);
IN1 = 1;IN2 = 1;IN3 = 0;IN4 = 0;Delay_xms(speed);
IN1 = 1;IN2 = 0;IN3 = 0;IN4 = 0;Delay_xms(speed);
}
void SetTimer0(unsigned char state)
{
TR0 = state;
ET0 = state;
EA = state;
}
void Timer0Init()
{
TMOD = 0X01;
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
SetTimer0(0);
}
void FeedControl()
{
char NowHour,NowMinter;
NowHour=TIME[2]/16*10+TIME[2]&0x0f;
NowMinter=TIME[1]/16*10+TIME[1]&0x0f;
OLED_ShowNum(40,6,FeedHour,2,16);
OLED_ShowNum(64,6,FeedMinter,2,16);
OLED_ShowNum(100,6,8-speed,1,16);
OLED_ShowNum(116,6,MP3,1,16);
if((NowHour==FeedHour)&&(NowMinter==FeedMinter)&&(count50ms==200)&&(FeedOnOff==1))
{
ONE_LINE_PLAY_SONG(MP3);
SetTimer0(1);
while(1)
{
MotorCW();
if(count50ms<=0)
{
SetTimer0(0);
break;
}
}
}
while((K2==0)||(K1==0))
{
if(K1==0)
{
if(FeedTimeChange==0)
{
if(++FeedHour>=23) FeedHour=23;
}
if(FeedTimeChange==1)
{
if(++FeedMinter>=59) FeedMinter=59;
}
if(FeedTimeChange==2)
{
if((speed--)<=1) speed=1;
}
if(FeedTimeChange==3)
{
if(++MP3>=7) MP3=7;
}
}
if(K2==0)
{
if(FeedTimeChange==0)
{
if((FeedHour--)<=0) FeedHour=0;
}
if(FeedTimeChange==1)
{
if((FeedMinter--)<=0) FeedMinter=0;
}
if(FeedTimeChange==2)
{
if(++speed>=7) speed=7;
}
if(FeedTimeChange==3)
{
if((MP3--)<=1) MP3=1;
}
}
delay_ms1(200);
}
if(K3==0)
{
delay_ms1(10);
if(K3==0)
{
if(++FeedTimeChange>=4) FeedTimeChange=0;
}
while(K3==0);
}
if(K4==0)
{
delay_ms1(10);
if(K4==0)
{
FeedOnOff=~FeedOnOff;
}
delay_ms1(200);
}
if(FeedOnOff==1)
{
OLED_ShowString(104,0,"ON ",16);
}
if(FeedOnOff==0)
{
OLED_ShowString(104,0,"OFF",16);
}
}
void Timer0Isr() interrupt 1
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
count50ms--;
}
int main(void)
{
OLED_Init();
OLED_Clear();
Timer0Init();
ONE_LINE_VOL(25);
OLED_ShowString(0,0,"Temp: . ",16);
OLED_ShowString(0,2,"Time: : :",16);
OLED_ShowString(0,4,"20 - - Wee:",16);
OLED_ShowString(0,6,"Feed: : ",16);
while(1)
{
FeedControl();
Ds1302ReadTime();
GetTemp(Ds18b20ReadTemp());
OLED_ShowNum(40,0,shi,1,16);
OLED_ShowNum(48,0,ge,1,16);
OLED_ShowNum(64,0,xs,1,16);
OLED_ShowNum(40,2,TIME[2]/16,1,16);
OLED_ShowNum(48,2,TIME[2]&0x0f,1,16);
OLED_ShowNum(64,2,TIME[1]/16,1,16);
OLED_ShowNum(72,2,TIME[1]&0x0f,1,16);
OLED_ShowNum(88,2,TIME[0]/16,1,16);
OLED_ShowNum(96,2,TIME[0]&0x0f,1,16);
OLED_ShowNum(16,4,TIME[6]/16,1,16);
OLED_ShowNum(24,4,TIME[6]&0x0f,1,16);
OLED_ShowNum(40,4,TIME[4]/16,1,16);
OLED_ShowNum(48,4,TIME[4]&0x0f,1,16);
OLED_ShowNum(64,4,TIME[3]/16,1,16);
OLED_ShowNum(72,4,TIME[3]&0x0f,1,16);
OLED_ShowNum(120,4,TIME[5]&0x0f,1,16);
}
}
|