基于51单片机的报警器【ADC0832,LCD1602,上下限】(仿真)

1、使用AD芯片测量水位或浓度等模拟量信号(可以任意改名)

2、设置上下限,测量值过限报警

3、LCD显示测量结果和上下限

说明:显示单位只需要修改程序里面的显示数组即可

 

 

#include "ADC0832.h"
#include "intrins.h"
/*********************************************
读取ADC
**********************************************/
uchar ADC(uchar ch)//通道ch	 1,2
{
	uchar temp0,temp1,i;
	CS=0;
	temp0=0;
	temp1=0;
	_nop_();
	_nop_();
	DI=1;//开始位
	_nop_();
	_nop_();
	CLK=1;
	_nop_();
	_nop_();
	CLK=0;
	_nop_();
	_nop_();
	DI=0;
	_nop_();
	_nop_();
//选择通道0
	DI=1;
	_nop_();
	CLK=1;//上升沿DI=1
	_nop_();
	CLK=0;//1个下降沿DI=1
	_nop_();
	if(ch==1)
	DI=0;
	if(ch==2)
	DI=1;
	_nop_();
	CLK=1;
	_nop_();
	CLK=0;//第3个上升沿DI=0
	_nop_();
   	DI=1;
//********通道选择结束开始读取转换后的二进制数****
//下降沿读数,一下进行判断和处理,共8次
for(i=0;i<8;i++)
   {
	temp0=temp0<<1;
	CLK=1;
    if(DO)
   	temp0++;
   	_nop_();
   	CLK=0;
   }
for(i=0;i<8;i++)
   {
	temp1=temp1>>1;
	CLK=1;
    if(DO)
   	temp1=temp1 +0x80;
   	_nop_();
   	CLK=0;
   }
	 CS=1;
   return temp0;
}

 

#include "lcd1602.h"

void delay_uint(uint i)
{
	while(i--);
}
/********************************************************************
* 名称 : write_com(uchar com)
* 功能 : 1602命令函数
* 输入 : 输入的命令值
* 输出 : 无
***********************************************************************/
void write_com(uchar com)
{
	e=0;
	rs=0;
	rw=0;
	P0=com;
	delay_uint(20);
	e=1;
	delay_uint(20);
	e=0;
}

/********************************************************************
* 名称 : write_data(uchar dat)
* 功能 : 1602写数据函数
* 输入 : 需要写入1602的数据
* 输出 : 无
***********************************************************************/
void write_data(uchar dat)
{
	e=0;
	rs=1;
	rw=0;
	P0=dat;
	delay_uint(20);
	e=1;
	delay_uint(20);
	e=0;	
}

/********************************************************************
* 名称 : write_string(uchar hang,uchar add,uchar *p)
* 功能 : 改变液晶中某位的值,如果要让第一行,第五个字符开始显示"ab cd ef" ,调用该函数如下
	 	 write_string(1,5,"ab cd ef;")
* 输入 : 行,列,需要输入1602的数据
* 输出 : 无
***********************************************************************/
void write_string(uchar hang,uchar add,uchar *p)
{
	if(hang==1)   
		write_com(0x80+add);
	else
		write_com(0x80+0x40+add);
		while(1)
		{
			if(*p == '\0')  break;
			write_data(*p);
			p++;
		}	
}

/********************************************************************
* 名称 : init_1602()
* 功能 : 初始化1602液晶 
* 输入 : 无
* 输出 : 无
***********************************************************************/
void init_1602()
{
	write_com(0x38);						//数据总线为8位,显示2行,5x7点阵
	write_com(0x0e);						//开显示,有光标,光标闪烁
	write_com(0x06);						//光标自动右移
	delay_uint(1000);						//等待设置完成
}

资料借鉴于此 纷传

  • 11
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白茶丫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值