51单片机-红外点滴测速程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
void Int1() interrupt 2//液面检测部分
{
EX1 = 0;//开外部中断0
beep = 0;//如果触发外部中断,即检测脚为低电平,低于检测液面,蜂鸣器报警
EX1 = 1;//开外部中断0
}
/******************************定时器中断0**********************************************/
{
EX0 = 0;//开外部中断0
num1 = 0;//计数器1清零
speed ++;//点滴数目加1
EX0 = 1;//开外部中断0
delayms(1);
}
/******************************外部中断1 P3^3 **********************************************/
time_out = 0;
}
}
}
void init()
{
TMOD = 0x11;//设置定时器0和1为工作方式1(0001 0001)
TH0 = (65536-45872)/256; //装初值
TL0= (65536-45872)%256;
TH1 = (65536-45872)/256;
TL1= (65536-45872)%256;
EA = 1;//开总中断
ET0 = 1;//开定时器0中断
ET1 = 1;//开定时器1中断
EX0 = 1;//开外部中断0
EX1 = 1;//开外部中断1
TR0 = 1;//启动定时器0
TR1 = 1;//启动定时器1
IT0 = 1;//外部中断0低电平触发
IT1 = 0;//外部中断1低电平触发
uint num0,num1;
uchar time_out = 0;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code tablewe[]={
0xfe,0xfd,0xfb,0xf7};
void init();
void delayms(uint);
void display(uchar qian,uchar bai,uchar shi,uchar ge);
void main()
{
init();
while(1)
{பைடு நூலகம்
display(qian,bai,shi,ge);
void T1_time() interrupt 3
{
TH1 = (65536-45872)/256; //装初值
TL1= (65536-45872)%256;
num1 ++;
if(num1 == 60)//若3s时间到,还未检测到点滴滴下
{
beep = 0;//蜂鸣器报警
}
}
void delayms(uint xms)
if(time_out == 1)
{
speed_tmp = speed * 12; //每分钟的点滴数目等于每5秒的数目乘以12
speed = 0;
qian = 0;
bai = speed_tmp/100;
shi= (speed_tmp%100)/10;
ge = speed_tmp%10;
//speed = 0;//点滴数目清?
}
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit beep = P1^0;
sbit dula = P3^6;
sbit wela = P3^7;
uchar qian,bai,shi,ge;
uint speed = 0,speed_tmp = 0;
{
dula = 1;
P0 = table[qian];
dula = 0;
wela = 1;
P2 = tablewe[3];
wela = 0;
delayms(5);
dula = 1;
P0 = table[bai];
dula = 0;
wela = 1;
P2 = tablewe[2];
wela = 0;
delayms(5);
dula = 1;
P0 = table[shi];
dula = 0;
wela = 1;
P2 = tablewe[1];
wela = 0;
delayms(5);
dula = 1;
P0 = table[ge];
dula = 0;
wela = 1;
P2 = tablewe[0];
wela = 0;
delayms(5);
void T0_time() interrupt 1
{
TH0 = (65536-45872)/256; //装初值
TL0= (65536-45872)%256;
num0 ++;
if(num0 == 40)//每隔2s测一次点滴数
{
num0 = 0;//计数器0清零
time_out = 1;
}
}
/******************************定时器中断1**********************************************/
beep = 1;//关闭蜂鸣器
}
/******************************外部中断0 P3^2 **********************************************/
void Int0() interrupt 0//点滴检测部分,能触发中断,说明有点滴滴下
{
uint i,j;
for(i = xms;i > 0;i--)
for(j = 110;j > 0;j--);
}
/******************************数码管显示函数**********************************************/
void display(uchar qian,uchar bai,uchar shi,uchar ge)
相关文档
最新文档