{
/*È·¶¨°´¼ü*/
if(Get_Bit(PIND,PD0)==0) {
delay_ms(20); key_flag=key_flag+1; while(!(Get_Bit(PIND,PD0)));//µÈ´ý°´¼üËÉ¿ª delay_ms(20); }
switch(key_flag) {
case 1://µ÷½ÚµçÁ÷NUM1 /*Ôö¼Ó°´¼ü*/
if(Get_Bit(PIND,PD1)==0) {
num_flag=1; delay_ms(10); num1++; if(num1==10) { num1=9; } WriteNum(2,0,ASCII[num1]); writecom(0xc0); while(!(Get_Bit(PIND,PD1)));//µÈ´ý°´¼üËÉ¿ª delay_ms(10); }
/*¼õÉÙ°´¼ü*/ if(Get_Bit(PIND,7)==0) {
num_flag=1; delay_ms(10); num1--; if(num1==0) { num1=1; } WriteNum(2,0,ASCII[num1]); writecom(0xc0); while(!(Get_Bit(PIND,PD7)));//µÈ´ý°´¼üËÉ¿ª delay_ms(10); }
break;
case 2://µ÷½ÚµçÁ÷NUM2 writecom(0xc2); /*Ôö¼Ó°´¼ü*/
if(Get_Bit(PIND,PD1)==0) {
num_flag=1; delay_ms(10); num2++; if(num2==10) { num2=9; } WriteNum(2,2,ASCII[num2]); writecom(0xc2); while(!(Get_Bit(PIND,PD1)));//µÈ´ý°´¼üËÉ¿ª
µÚ21Ò³ ¹²26Ò³
delay_ms(10); }
/*¼õÉÙ°´¼ü*/ if(Get_Bit(PIND,7)==0) {
num_flag=1; delay_ms(10); num2--; if(num2==0) { num2=1; } WriteNum(2,2,ASCII[num2]); writecom(0xc2); while(!(Get_Bit(PIND,PD7)));//µÈ´ý°´¼üËÉ¿ª delay_ms(10); }
break; case 3: key_flag=0; break; default: key_flag=0; } } }
#pragma interrupt_handler int0_isr:iv_INT0 void int0_isr(void) {
delay_ms(10); key_sol();
//while(!(Get_Bit(PIND,PD2)));//µÈ´ý°´¼üËÉ¿ª delay_ms(10); key_flag=0; flag=1; LcdInit(); }
void init_devices(void) {
//stop errant interrupts until set up CLI(); //disable all interrupts port_init(); timer1_init(); MCUCR = 0x02; GICR = 0x40;
TIMSK = 0x00; //timer interrupt sources SEI(); //re-enable interrupts
//all peripherals are now initialized }
uint AD_GetData(uint ad_input) {
ADMUX|=0x40; //ADC²Î¿¼µçѹAVcc ADCSRA|=0x87; //ʹÄÜADC£¬128·ÖƵ ADMUX=ad_input; //Ñ¡ÔñADת»»Í¨µÀ ADCSRA|=(1< while(!(ADCSRA&(1< µÚ22Ò³ ¹²26Ò³ ADCSRA&=0x0f; return ADC; } /*ϵͳÐÞÕý*/ void sys_comp() { while(1) { switch (delay_flag) { case 0: case 1: if(temp1int OCR1AL=OCR1AL+3; delay_flag=0; } if(temp1int>vol_exp) { OCR1AL=OCR1AL-3; delay_flag++; } break; default: if(temp1int OCR1AL=OCR1AL+1; } if(temp1int>vol_exp) { OCR1AL=OCR1AL-1; } delay_ms(1); } ad_get(); if(OCR1AL<2) { OCR1AL=2; delay_ms(20); if(temp1int>vol_exp) { delay_ms(30); if(temp1int>vol_exp) { err_flag=0; err_sol(); PORTD&=0xbf;//´ò¿ª¼ÌµçÆ÷ } } } if((temp2int>(num1*100+num2*10))&&(OCR1AL>150)) { err_flag=1; err_sol(); } } } µÚ23Ò³ ¹²26Ò³ void err_sol() { uchar cont3[]={\ uchar cont4[]={\ uchar cont5[]={\ switch (err_flag) { case 0: PORTD|=(1< WriteChar(1,0,14,cont4); WriteChar(2,0,14,cont5); OCR1AL =2;//³õʼ»¯AÕ¼¿Õ±È80% delay_flag=0; flag=0; while(!flag);//µÈ´ý²Ëµ¥°´¼ü°´Ï delay_ms(50); break; case 1: PORTD|=(1< WriteChar(1,0,14,cont3); // OCR1AL = 0x51;//³õʼ»¯AÕ¼¿Õ±È80% delay_flag=0; flag=0; while(!flag);//µÈ´ý²Ëµ¥°´¼ü°´Ï delay_ms(50); break; default: break; } } /*ad¶ÁÈ¡*/ void ad_get() { //uchar ASCII[]={\ uchar i; uchar t; uchar r; addata=AD_GetData(0x45); //»ñµÃͨµÀ5Êý×ÖÁ¿ for(i=0;i<9;i++) { addata=addata+AD_GetData(0x45); } temp1float=addata*0.0048828125; temp1float=temp1float/9.08; temp1int=((uint)(temp1float*100)+1); temp1[8]=ASCII[temp1int/100]; temp1[9]=ASCII[(temp1int0)/10]; temp1[11]=ASCII[temp1int]; while(!flag); WriteChar(1,0,17,temp1); addata=AD_GetData(0x46); //»ñµÃͨµÀ6µÄÊý×ÖÁ¿ for(i=0;i<9;i++) { addata=addata+AD_GetData(0x46); } temp2float=addata*0.0048828125; µÚ24Ò³ ¹²26Ò³ temp2float=temp2float/21.0; temp2int=(uint)(temp2float*100); temp2[8]=ASCII[temp2int/100]; temp2[10]=ASCII[(temp2int0)/10]; temp2[11]=ASCII[temp2int]; while(!flag); WriteChar(2,0,17,temp2); r++; if(r==30) { //LcdInit(); } /* addata=AD_GetData(0x47); //»ñµÃͨµÀ7µÄÊý×ÖÁ¿ for(i=0;i<9;i++) { addata=addata+AD_GetData(0x47); } temp3float=addata*0.0048828125; temp3float=temp3float/21.0; temp3int=(uint)(temp3float*100); temp3[2]=ASCII[temp3int/100]; temp3[4]=ASCII[(temp3int0)/10]; temp3[5]=ASCII[temp3int]; while(!flag); WriteChar(2,8,7,temp3); */ //WriteChar(2,0,?,temp3);//ÏÔʾռ¿Õ±È delay_ms(1); } /*Ö÷º¯Êý*/ void main(void) { SREG|=0x80; DDRA=0xff; PORTA=0xff; init_devices(); LcdInit(); while(1) { sys_comp(); } } µÚ25Ò³ ¹²26Ò³