用大佬的程序改的,怎么实现检测时未过压黄灯2分钟后亮?
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
//===========================
//ADC0809à¨
//===========================
#define ADC_DATA P1sbit ADC_EOC = P3^3; sbit ADC_CLK = P3^4; sbit ADC_START = P3^6; sbit ADC_OE = P3^7; //===========================//4à//===========================uchar code seg[10]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90 }; //0~9 uchar code seg_dot[10]={ 0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10 }; //0~9 #define SEG_DATA P2 //¨sbit SEG_SEL_0 = P0^3; //0¨sbit SEG_SEL_1 = P0^2; //1sbit SEG_SEL_2 = P0^1; //2sbit SEG_SEL_3 = P0^0; //3//===========================//±¨LED·ù÷//===========================sbit LED = P0^5; //sbit BEEP = P0^4; //ìsbit relay =P0^6;#define LED_ON LED=0#define LED_OFF LED=1#define BEEP_ON BEEP=1#define BEEP_OFF BEEP = 0//===========================//± AT89C51 & 12MHz//===========================void delayms(unsigned int ms){ unsigned char a,b,c; while(ms--) { for(c=1;c>0;c--) for(b=142;b>0;b--) for(a=2;a>0;a--); }}/*//===========================//± STC12C5A60S2 & 12MHz//===========================void delayms(unsigned int ms){ unsigned char a,b,c; while(ms--) { for(c=1;c>0;c--) for(b=222;b>0;b--) for(a=12;a>0;a--); }}*///===========================//¨±÷ADC0809±//===========================void timer_init(void){ //¨±÷0 ET0 = 1; TMOD &= 0xF0; TMOD |= 0x02; //¨±÷02××°¨±÷ TH0 = 200; //××° TL0 = 200; TR0 = 1; //¨±÷1 ET1 = 1; TMOD &= 0x0F; //¨±÷1¨±÷0 TMOD |= 0x10; //¨±÷1¨±÷0 TH1 = (65536 - 2000)/256; TL1 = (65536 - 2000)%256; TR1 = 1; EA = 1;}//===========================//¨±÷0ADC0809á[表情]±//===========================void timer0() interrupt 1{ ADC_CLK = ~ADC_CLK;}//============================//ADC0809 ×//============================uchar ADC0809_GET(void){ ADC_START = 0; ADC_OE = 0; ADC_START = 1; ADC_START = 0; while(ADC_EOC == 0); ADC_OE = 1; return ADC_DATA;}//============================//¨±÷1//============================uchar t1_flag = 0; //±êuchar seg0 = 0; //0 uchar seg1 = 1; //1 uchar seg2 = 2; //2 uchar seg3 = 3; //3 void timer1() interrupt 3{ TH1 = (65536 - 2000)/256; TL1 = (65536 - 2000)%256; SEG_SEL_0 = 0; SEG_SEL_1 = 0; SEG_SEL_2 = 0; SEG_SEL_3 = 0; SEG_DATA = 0xff; if(t1_flag == 0) { SEG_SEL_0 = 1; //¨0 SEG_SEL_1 = 0; SEG_SEL_2 = 0; SEG_SEL_3 = 0; SEG_DATA = seg_dot[seg0]; // } else if(t1_flag == 1) { SEG_DATA = seg[seg1]; SEG_SEL_0 = 0; SEG_SEL_1 = 1; //¨1 SEG_SEL_2 = 0; SEG_SEL_3 = 0; } else if(t1_flag == 2) { SEG_DATA = seg[seg2]; SEG_SEL_0 = 0; SEG_SEL_1 = 0; SEG_SEL_2 = 1; //¨2 SEG_SEL_3 = 0; } else if(t1_flag == 3) { SEG_DATA = seg[seg3]; SEG_SEL_0 = 0; SEG_SEL_1 = 0; SEG_SEL_2 = 0; SEG_SEL_3 = 1; //¨3 } t1_flag++; //×1 t1_flag = t1_flag%4; //t1_flag 03[表情]·}//============================//0~2550.000~5.000//============================uint print_volt(uchar num){ uint volt = 0; volt = num/255.0 * 5000 + 0.5; //255.0255ó±255.0á××float±volt/255=0+0.5á seg0 = volt/1000%10; seg1 = volt/100%10; seg2 = volt/10%10; seg3 = volt%10; return volt;}//============================//÷//============================void main(void){ uchar adc_num = 0; //ADC uint volt = 0; // 0~5000ú±í(0~5)V timer_init(); //¨±÷0¨±÷1 /*LED_OFF; BEEP_OFF; */ while(1) { adc_num = ADC0809_GET(); volt = print_volt(adc_num); //·0~5000·±¨ if(volt > 2500) { /*LED_ON;*/ BEEP_ON; relay=1; } else { LED_OFF; BEEP_OFF; } delayms(100); }} |