完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
13 个讨论
|
|
#include
#include #include #include #include #define uchar unsigned char #define uint unsigned int void delay(uint z); void dely_us(uint x); void buzl( ); void anjian(); void tiaozheng(); void chengxuxuanze(); void fare(); void display(uchar timebai,uchar timeshi,uchar timege,uchar temperebai,uchar tempereshi,uchar temperege); uchar timebai,timeshi,timege,st,temperebai,tempereshi,temperege,tempere1,tempere2,time,tempere,chengxu,leda,aa,bb,cc,shijian,dd,ee; ***it ELVD=IE^6; ***it k2 =P4^2; ***it k3 =P1^7; ***it k4 =P1^6; ***it k5 =P1^5; ***it k6 =P1^4; ***it k7=P1^3; ***it k8=P1^2; ***it k9=P1^1; ***it buz=P4^4; ***it heat=P4^0; ***it qqq=P4^1; ***it w1=P3^2; ***it w2=P3^3; ***it w3=P3^4; ***it w4=P3^5; ***it w5=P3^6; ***it w6=P3^7; //led ***it l0=P0^0; ***it l1=P0^1; ***it l2=P0^2; ***it l3=P0^3; ***it l4=P0^4; ***it l5=P0^5; ***it l6=P0^6; ***it l7=P0^7; bit ke,sf; void init(); uchar code table[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90}; uchar code ledtab[]={0XD1,0XD2,0XD4,0XD8,0XE1,0XE2,0XE4,0XE8,0XB1,0XB2,0XB4,0XB8,0X71,0X72,0X74,0X78} ; void dely_us(uint z) { uint x,y; for(x=z;x>0;x--) for(y=10;y>0;y--); } void buzl( ) { uint i; for(i=50;i>0;i--) { buz=1; dely_us(7); buz=0; dely_us(4); } } void main() { PCON=0x00; ke=0; P0M0=0x00; P0M1=0xff; P4M0 = 0x01; P4M1 = 0x00; qqq=1; p4sw=0xff; init(); // TMR0_ini(); //dely_x1mS(20); //stc_adc_ini(); while(1) { while(ee==0) { P3=0x00; P2=0xff ; anjian(); } anjian(); fare(); tiaozheng(); timebai=time/100; timeshi=time%100/10; timege=time%10; temperebai=tempere/100; tempereshi=tempere%100/10; temperege=tempere%10; display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); } } void init() //初始化 { aa=0; bb=0; cc=0; ee=0; TMOD=0x01;//方式1,16bit TH0=(65536-50000)/256; //FC1ms //11.0592M,STC12C TL0=(65536-50000)%256; //50mS/bit EA=1; ET0=1; TMOD=0x10; TH1=(65536-50000)/256; //FC1ms //11.0592M,STC12C TL1=(65536-50000)%256; //50mS/bit ET1=1; } void timer0() interrupt 1 using 0 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; shijian++; if(shijian==40) { shijian=0; time--; } } void timer1() interrupt 3 using 1 { TH1=(65536-50000)/256; TL1=(65536-50000)%256; DI1++; if(DI1==40) { tempere1=chk_tep();//只要是读取ADC按键就无效,如果不读取按键正常 tempere2=tempere1*1.8+32; DI1=0; } } void display(uchar timebai,uchar timeshi,uchar timege,uchar temperebai,uchar tempereshi,uchar temperege) { P2=table[timebai]; w4=1; delay(7); w4=0; // P2=0xff; P2=table[timeshi]; w5=1; delay(7); w5=0; // P2=0xff; P2=table[timege]; w6=1; delay(7); w6=0; // P2=0xff; P2=table[temperebai]; w1=1; delay(7); w1=0; // P2=0xff; P2=table[tempereshi]; w2=1; delay(7); w2=0; // P2=0xff; P2=table[temperege]; w3=1; delay(7); w3=0; // P2=0xff; } void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void anjian() { if(k4==0) {buzl( ); if(k4==0) { aa++; bb=0; cc=0; ee=1; if(aa>=5) { aa=1; } while(k4==0) { display(timebai,timeshi,timege,temperebai,tempereshi,temperege); } } switch(aa) { case 1: time=25; tempere=203; // delay(1); break; case 2: time=20; tempere=213; // delay(1); break; case 3: time=35; tempere=223; delay(1); break; case 4: time=45; tempere=233; // delay(1); break; } } if(k5==0) {buzl( ); if(k5==0) { bb++; aa=0; cc=0; ee=1; // buzl( ); if(bb>=5) { bb=1; } } while(k5==0) { display(timebai,timeshi,timege,temperebai,tempereshi,temperege); } } switch(bb) { case 1: time=25; tempere=203; // delay(1); break; case 2: time=20; tempere=213; // delay(1); break; case 3: time=35; tempere=223; // delay(1); break; case 4: time=45; tempere=233; // delay(1); break; } if(k6==0) {buzl( ); if(k6==0) { cc++; aa=0; bb=0; ee=1; // buzl( ); if(cc>=5) { cc=1; } while(k6==0) { display(timebai,timeshi,timege,temperebai,tempereshi,temperege); } } switch(cc) { case 1: time=25; tempere=203; // delay(1); break; case 2: time=20; tempere=213; // delay(1); break; case 3: time=35; tempere=223; // delay(1); break; case 4: time=45; tempere=233; // delay(1); break; } } } void tiaozheng() { if(k2==0) {buzl( ); if(k2==0) { if(tempere>0) tempere--; // buzl( ); while(k2==0) { display(timebai,timeshi,timege,temperebai,tempereshi,temperege); } } } if(k3==0) {buzl( ); if(k3==0) { tempere++; // buzl( ); while(k3==0) { display(timebai,timeshi,timege,temperebai,tempereshi,temperege); } } } if(k7==0) {buzl( ); if(k7==0) { if(time>0) time--; // buzl( ); while(k7==0) { display(timebai,timeshi,timege,temperebai,tempereshi,temperege); /* display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); timebai=time/100; timeshi=time%100/10; timege=time%10; temperebai=tempere/100; tempereshi=tempere%100/10; temperege=tempere%10; display(timebai,timeshi,timege,temperebai,tempereshi,temperege); display(timebai,timeshi,timege,temperebai,tempereshi,temperege); if(k7==0) { if(time>0) time--; }*/ } } } if(k8==0) {buzl( ); if(k8==0) { time++; // buzl( ); while(k8==0) { display(timebai,timeshi,timege,temperebai,tempereshi,temperege); } } } } void fare() { if(k9==0) {buzl( ); if(k9==0) { dd++; if(dd==2) { dd=0; } while(k9==0) { display(timebai,timeshi,timege,temperebai,tempereshi,temperege); } } } switch(dd) { case 0: TR0=0; //打开定时器 TR1=0; //打开定时器 heat=0; P0=0xf0; delay(1); break; case 1: TR0=1; //关闭定时器 TR1=1; //打开定时器 heat=1; P0=0xf0; P0=ledtab[15]; break; } } |
|
|
|
|
|
//ADC部分**********
#ifndef stc_adc_H #define stc_adc_H //----------------------- //sfr P1_ADC_EN = 0x97; sfr p1asf = 0x9d; sfr ADC_CONTR = 0xbc; sfr ADC_DATA = 0xbd; sfr ADC_ADTL2 = 0xBE; sfr PIM0 = 0x91; sfr PIM1 = 0x92; sfr P2M1 =0x96; sfr P2M0 =0x95; sfr P3M0 =0xB1; sfr P3M1 =0xB2; //-- void stc_adc_ini() //stc_adc初始 { //P1_ADC_EN = 0x01; //P1.0 为AD脚,上拉电阻断开 PIM0 = 0x01; PIM1 = 0x01; p1asf = 0x01; P1=P1&0x01; } //-- void nop_1mS(int x) { int i; for(;x>0;x--) { for(i=0;i<70;i++){} } } //--- unsigned int gat_adc(unsigned char channel) { unsigned char finished = 0,N=0; unsigned int E = 0; unsigned long M = 0; P1=P1&0x01; ADC_DATA = 0; ADC_CONTR = channel; //选通道 nop_1mS(5); //延时,等待电压平稳 ADC_CONTR |= 0x88; //启动A/D finished = 0; while(finished==0) //等转换结束 { finished = (ADC_CONTR & 0x10); } ADC_CONTR &= 0xF7; //关闭A/D //ADC_CONTR = 0x00; //关闭A/D E=ADC_DATA; E=E<<2; E=E|(ADC_ADTL2 & 0x03); return E; //1024bit } unsigned int che_ohm() //反回电阻单位为K*100, { unsigned long M,A,B; M=gat_adc(0); //--求Rx-- //Rx=10000*Vo/(1023-Vo) A=1000*M; B=1023-M; M=A/B; //(K*100) return M; } //---LNTK-103FF CODE- //(0 to 660) 0oC unsigned int code NTCcod[13]= { 2739, //0 //电阻单位R*100 1799, //10 1210, //20 831, //30 582, //40 416, //50 302, //60 223, //70 167, //80 126, //90 96, //100 74, //110 58, //120 }; //-------------- unsigned int che_tab(unsigned int x) //输入电阻单位为R*100,输出温度单位为oC*10 { unsigned long E,N,A,M,C,D; if(x>=2739) { return 0; } if(x<=58) { return 120; } for(N=0;N<13;N++) { E=NTCcod[N]; A=NTCcod[N+1]; if(A<=x) { break; } } C=E-x; D=(E-A)/10; E=C/D; M=(N*10)+E; //C return M; // } unsigned int chk_tep() { unsigned int E; E=che_ohm(); //反回电阻单位为K*100, E=che_tab(E); //输入电阻单位为R*100,输出温度单位为oC*10 return E; } //-------------- #endif |
|
|
|
|
|
只有小组成员才能发言,加入小组>>
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 01:03 , Processed in 0.660813 second(s), Total 69, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号