毕业设计 单片机智能宠物投食系统(AT89C51 lcd1602)

一、电路设计

此电路由单片机最小系统板、LCD240*128液晶显示模块、DS18B20测温模块、步进电机模块和重量检车模块组成。当检测实物不符合要求时声光报警并驱动步进电机投食。

二、运行结果

三、部分代码



    #include "reg52.h"		
    #include "ds1302.h"	
    #include "lcd.h"
    #include "temp.h"
    #include "intrins.h"
    /*对数据类型进行声明定义*/
    typedef unsigned int u16;	  
    typedef unsigned char u8;
    #define ulong unsigned long
    #define GPIO_MOTOR P1
    
    /****I/O口定义****/
    sbit KEY1 = P3^0;
    sbit KEY2 = P3^1;
    sbit KEY3 = P3^2;
    
    sbit BEEP = P2^7;
    sbit LED1  = P3^3;


    sbit DOUT=P3^4;	//定义2543数据读取口
    sbit DIN =P3^5;	//定义2543数据写入口
    sbit CS  =P3^6;	//定义2543片选信号口
    sbit CLK =P3^7;	//定义时钟信号口
    
    /****变量定义****/
    bit adjust;//调节标志位  0-1
    u8 num;//闹钟调节位
    u8 hour_shi, hour_ge, minute_shi, minute_ge;//闹钟调节
    ulong Volt;//测量的电压值
    ulong AD_Volt;//测量的电压值
    ulong quality;//检测重量
    ulong quality_set=2000;//设置的重量阈值200克
    
    unsigned char code FFW_X[8]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09}; //X反转顺序
    
    unsigned char code FFZ_X[8]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1}; //X正转顺序
    
    unsigned char Direction,stop=0;
    
    void delay30ms(void)   //误差 0us
    {
        unsigned char a,b;
        for(b=101;b>0;b--)
            for(a=147;a>0;a--);
    }
    
    void Delay(unsigned int t)
    {
     unsigned int k;
     while(t--)
     {
     for(k=0; k<80; k++)
     { }
     }
    }


    void Motor()
    {
    	unsigned char a=30;
     unsigned char i;
     for(i=0;i<8;i++)
     {
    
      if(Direction==1&&stop;==0)		 //正转电机&电机没按下停止
    
     GPIO_MOTOR = FFW_X[i]&0x0F;//取数据
    
     if(Direction==2&&stop;==0)		 //反转&X;电机&电机没按下停止
    
     GPIO_MOTOR = FFZ_X[i]&0x0F;
     
      Delay(a);
      }
    }


    void KEY_Control()//按键调节
    {
    	if(KEY1==0)
    	{
    		delay30ms();
    		if(KEY1==0)
    		{
    		  stop=0;
    		 	Direction=1;	
    		}
    	}
    	if(KEY2==0)
    	{
    		delay30ms();
    		if(KEY2==0)
    		{
    		stop=0;
    		 	Direction=2;	
    		}
    	}
    	if(KEY3==0)
    	{
    		delay30ms();
    		if(KEY3==0)
    		{
    		
    		 stop=1;	
    		}
    	}
    	
    }


    void main()//主函数
    {	
    	
    	LcdInit();
    
    	DisplayOneChar(0,0,'2'); 
        DisplayOneChar(1,0,'0');
        DisplayOneChar(4,0,'-'); 
        DisplayOneChar(7,0,'-');//2022-05-05  6
    	DisplayOneChar(2,1,':'); 
        DisplayOneChar(5,1,':'); 
        DisplayOneChar(2,1,':');//13:39:40	
    	DisplayListChar(9,1,"T:"); 
        DisplayOneChar(13,1,'.'); 
        DisplayOneChar(15,1,'C');//T:23.5C
    	DisplayOneChar(15,0,'g');
    
    	while(1)
    	{
    		
    		KEY_Control();//按键控制
    		Motor();//步进电机控制
    			
    		Read2543(0);//检测重量
    		show_quality();//显示重量
    		
    		ReadTemperature();//读取温度	
    		DisplayTemp();//显示温度
    			
    		Ds1302ReadTime();//读取时间
    		DisplayTime();//显示时间

    	}
    }


项目获取:

https://gitee.com/feifei1122/simulation-project

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值