#include <reg52.h>
#include <intrins.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
uchar code zifux[] ="0123456789abcdef";
uchar code zifu0[]="T1: 000^ T2: 000^";
uchar code zifu1[]=" SET: 000^ ";
#include "1602.H"
int wendua1=0;
int wendua2=0;
int wendu1=0;
int wendu2=0;
int wendu3=0;
int wendu4=0;
#include "ds18.h"
#include "ds182.h"
#include "ds183.h"
#include "ds184.h"
sbit key1=P3^3;
sbit key2=P3^4;
sbit key3=P3^5;
sbit key4=P3^6;
sbit key5=P3^7;
sbit led1=P1^4;
sbit led2=P1^5;
sbit led3=P1^6;
sbit led4=P1^7;
uchar bz1=0;
uchar bz2=0;
uchar bz3=0;
uchar bz4=0;
uint moshi=0;
uchar x=0;
int wendux=28;
sbit beer=P2^0;
void beerc()
{
beer=0;_delay_ms(70);beer=1;_delay_ms(50);
}
void dis()
{
if(x==0) {readds18(); wendu1=wendu1; }
if(x==1) {readds182();wendu2=wendu2; wendua1=(wendu1+wendu2)/2;}
if(x==2) {readds183();wendu3=wendu3; }
if(x==3) {readds184();wendu4=wendu4; wendua2=(wendu3+wendu4)/2;}
x=(x+1)%4;
lcd1602_adr(0x02);
if(wendua1>=0)
{
lcd1602_writenumber('+');
lcd1602_writenumber(0x30+wendua1%1000/100);
lcd1602_writenumber(0x30+wendua1%100/10);
lcd1602_writenumber(0x30+wendua1%10);
lcd1602_writenumber(0xdf);
}
if(wendua1<0)
{
lcd1602_writenumber('-');
lcd1602_writenumber(0x30+(0-wendua1)%1000/100);
lcd1602_writenumber(0x30+(0-wendua1)%100/10);
lcd1602_writenumber(0x30+(0-wendua1)%10);
lcd1602_writenumber(0xdf);
}
lcd1602_adr(0x0b);
if(wendua2>=0)
{
lcd1602_writenumber('+');
lcd1602_writenumber(0x30+wendua2%1000/100);
lcd1602_writenumber(0x30+wendua2%100/10);
lcd1602_writenumber(0x30+wendua2%10);
lcd1602_writenumber(0xdf);
}
if(wendua2<0)
{
lcd1602_writenumber('-');
lcd1602_writenumber(0x30+(0-wendua2)%1000/100);
lcd1602_writenumber(0x30+(0-wendua2)%100/10);
lcd1602_writenumber(0x30+(0-wendua2)%10);
lcd1602_writenumber(0xdf);
}
lcd1602_adr(0x46);
if(wendux>=0)
{
lcd1602_writenumber('+');
lcd1602_writenumber(0x30+wendux%1000/100);
lcd1602_writenumber(0x30+wendux%100/10);
lcd1602_writenumber(0x30+wendux%10);
lcd1602_writenumber(0xdf);
}
if(wendux<0)
{
lcd1602_writenumber(0x30+(0-wendux)%1000/100);
lcd1602_writenumber(0x30+(0-wendux)%100/10);
lcd1602_writenumber(0x30+(0-wendux)%10);
lcd1602_writenumber(0xdf);
}
if(moshi==0) lcd1602_writenumber(' ');
if(moshi==1) lcd1602_writenumber('<');
}
void ct()
{
if(moshi==0)
{
if(wendua1<=(wendux-3)){led3=0;bz1=1;}else {led3=1;bz1=0;}
if((wendua1<=(wendux-5))||(wendua1>=(wendux+5)))led1=0;else led1=1;
if(wendua2<=(wendux-3)){led4=0;bz2=1;}else {led4=1;bz2=0;}
if((wendua2<=(wendux-5))||(wendua2>=(wendux+5)))led2=0;else led2=1;
if( (wendua1<=(wendux-5))||(wendua1>=(wendux+5)) ||(wendua2<=(wendux-5))||(wendua2>=(wendux+5)) ){beerc();}
}
if(moshi==1)
{
led1=1;
led2=1;
led3=1;
led4=1;
}
}
void key()
{
if(key1==0){moshi=1;if(moshi==0)moshi=1;beerc();while(key1==0);}
if(moshi==1)
{
if(key2==0){if(wendux<100)wendux=wendux+1;while(key2==0);}
if(key3==0){if(wendux>(-50)) wendux=wendux-1;while(key3==0);}
}
if(key4==0){moshi=0;while(key4==0);}
}
void main()
{
lcd1602_init();
LCD1602_string(1,1,zifu0);
LCD1602_string(1,1,zifu0);
LCD1602_string(2,1,zifu1);
readds18();readds182();readds183();readds184();_delay_ms(500);
readds18();readds182();readds183();readds184();_delay_ms(500);
readds18();readds182();readds183();readds184();_delay_ms(200);
readds18();readds182();readds183();readds184();_delay_ms(200);
readds18();readds182();readds183();readds184();_delay_ms(200);
readds18();readds182();readds183();readds184();_delay_ms(200);
readds18();readds182();readds183();readds184();_delay_ms(200);
wendua1=(wendu1+wendu2)/2;
wendua2=(wendu3+wendu4)/2;
dis();
if(wendua1<=(wendux))led3=0;
if(wendua2<=(wendux))led4=0;
while((wendua1<=(wendux))||(wendua2<=(wendux)))
{
dis();
if(wendua1<=(wendux))led3=0; else led3=1;
if(wendua2<=(wendux))led4=0; else led4=1;
}
while (1)
{
dis();
ct();
key();
}
}
链接:https://pan.baidu.com/s/1jYSqQuPkiLHE8kztr9712A 提取码:p2fe
|