![]() |
|
Tài trợ cho PIC Vietnam |
Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC |
![]() |
|
Ðiều Chỉnh | Xếp Bài |
|
![]() |
#1 |
Đệ tử 2 túi
Tham gia ngày: Feb 2011
Bài gửi: 45
: |
kiem tra ho e voi
tình hình là e đang làm đồ án đo hiển thị nhiệt độ điều khiển toc đôc DC motor dùng phương pháp fuzzy!e đã làm và text rất nhiều lần rồi mà kết quả hông như ý!nhờ các cao thủ giúp tìm ra lỗi cho e với!các ae chú ý doạn này nhé!!
tong=(tempv1+tempv2+tempv3+tempv4+tempv5+tempv6+te mpv7+tempv8+tempv9+tempv10+tempv11+tempv12+tempv13 ); xung_can_tinh1=(5*tempv1+10*tempv2+20*tempv3+30*te mpv4+40*tempv5+50*tempv6+60*tempv7+70*tempv8+80*te mpv9+90*tempv10+100*tempv11+110*tempv12+115*tempv1 3); // xung_can_tinh=(int8) (xung_can_tinh1/tong); // value_PWM=rat_thap_T1(value0); xung_can_tinh=(int8)(xung_can_tinh1/tong); // value_PWM=(5*tempv1+10*tempv2+20*tempv3+30*tempv4+ 40*tempv5+50*tempv6+60*tempv7+70*tempv8+80*tempv9+ 90*tempv10+100*tempv11+110*tempv12+115*tempv13)/(tempv1+tempv2+tempv3+tempv4+tempv5+tempv6+tempv7+ tempv8+tempv9+tempv10+tempv11+tempv12+tempv13); //value_PWM=xung_can_tinh; value_PWM=(int8)(xung_can_tinh); dáng lẽ ra ết quả của e có value_PWM luôn luôn lớn hơn 5 mà e đã text thấy sai!! đây là code của e,nhờ các cao thu giúp e với!!thanks!!! code[ //================================================= ======= // Ten chuong trinh : Mach do nhiet do // Nguoi thuc hien : dinhnambkhn@gmail.com // Ngay thuc hien : 9/03/2011 // Phien ban : 1.0 // Mo ta phan cung : Dung PIC16F877A - thach anh 20MHz // : Led7seg giao tiep voi PORTD // : Dau ra LM335 1,2 dua vao chan AN0,AN1 //---------------------------------------------------------------- // Chu thich : // : dung che do Power On Reset //================================================= ======= #include <16F877A.h> #include <def_877a.h> #device *=16 adc=10 #FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT,NOLVP, NOCPD, NOWRT #use delay(clock=1000000) #define speak PIN_B2 #use fast_io(d) #byte portd=0x8 int min,max,i,j,low1,high1; int T1,T2; int temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,te mp9,temp10; int tempv1,tempv2,tempv3,tempv4,tempv5,tempv6,tempv7,t empv8,tempv9,tempv10,tempv11,tempv12,tempv13; int32 xung_can_tinh1; int xung_can_tinh; int mang[25]; const char led7seg[12]={0xC0,0xcf,0xa4,0xb0,0x99,0x92,0x83,0xf8,0x80,0x9 0,0x8e,0xc6}; const char quet[2]={0x01,0x02}; int value_PWM; long tong=0; void convert_bcd(int x); void tinh_toan_xung(); int rat_thap_T1 (int T1); int thap_T1(int T1); int vua_T1(int T1); int cao_T1(int T1); int rat_cao_T1(int T1); int rat_thap_T2 (int T2); int thap_T2(int T2); int vua_T2(int T2); int cao_T2(int T2); int rat_cao_T2(int T2); int min2(int x0,int y0); int max2(int x2,int y2) ; int max3(int x3,int y3,int z3); //----------------------------------------------------------------- void main(void) { float value0,value1;//gia tri nhiet do cho cam bien o va 1 value_PWM=0; min = 15; //nhiet do min max = 35; //nhiet do max i = 10 ; set_tris_d(0); trisa = 0xFF; trisb = 0x00; portd=0xff; output_low(speak); //=========== Khoi tao che do cho bo ADC===================================== setup_adc_ports(RA0_RA1_RA3_ANALOG); setup_adc(ADC_CLOCK_INTERNAL); //khoi tao che do PWM SETUP_CCP1(CCP_PWM);//set CCP1(RC2) to PWM mode SETUP_TIMER_2(T2_DIV_BY_4,124,1); //set the PWM frequency to[(20MHz/4)/1]/255=16.9KHz set_PWM1_duty(value_PWM); ///////////////////////////// delay_us(10);// Lay mau nhiet do lan dau tien cho AN0 set_adc_channel(0); value0 =read_adc(); value0 = (value0 - 558.5)/2.048; // For 5V supply // value = (value - 754.8)/2.048; // For 3.7V Supply // value = (value - 698.2)/2.048; // For 4V supply convert_bcd((int)value0); // Tach so tram, chuc, donvi de hien thi len LED 7 ///////////////lay mau nhiet do cho cong AN1 // delay_ms(500); delay_us(10); set_adc_channel(1); value1 =read_adc(); value1 = (value1 - 558.5)/2.048; // For 5V supply // value1 = (value1 - 754.8)/2.048; // For 3.7V Supply // value1 = (value1 - 698.2)/2.048; // For 4V supply // convert_bcd((int)value1); // Tach so tram, chuc, donvi de hien thi len LED 7 delay_ms(500); while(TRUE) { if (i==10) { //------------------------set cho cong AN0 set_adc_channel(0); value0 = read_adc(); value0 =(value0-558.5)/2.048; value0=(int)(value0); convert_bcd(value0); //-------------------------set cho cong AN1 set_adc_channel(1); value1 = read_adc(); value1 =(value1-558.5)/2.048; value1=(int)(value1); // tinh_toan_xung(); temp1 = rat_thap_T1(value0); temp2 = thap_T1(value0); temp3 = vua_T1(value0); temp4 = cao_T1(value0); temp5 = rat_cao_T1(value0); temp6 = rat_thap_T2(value1); temp7 = thap_T2(value1); temp8 = vua_T2(value1); temp9 = cao_T2(value1); temp10 = rat_cao_T2(value1); /////////// //tinh theo MIN mang[0]=min2(temp1,temp6); mang[1]=min2(temp1,temp7); mang[2]=min2(temp1,temp8); mang[3]=min2(temp1,temp9); mang[4]=min2(temp1,temp10); mang[5]=min2(temp2,temp6); mang[6]=min2(temp2,temp7); mang[7]=min2(temp2,temp8); mang[8]=min2(temp2,temp9); mang[9]=min2(temp2,temp10); mang[10]=min2(temp3,temp6); mang[11]=min2(temp3,temp7); mang[12]=min2(temp3,temp8); mang[13]=min2(temp3,temp9); mang[14]=min2(temp3,temp10); mang[15]=min2(temp4,temp6); mang[16]=min2(temp4,temp7); mang[17]=min2(temp4,temp8); mang[18]=min2(temp4,temp9); mang[19]=min2(temp4,temp10); mang[20]=min2(temp5,temp6); mang[21]=min2(temp5,temp7); mang[22]=min2(temp5,temp8); mang[23]=min2(temp5,temp9); mang[24]=min2(temp5,temp10); ////////////// //quy luat max theo bang luat(rule) tempv1= max2(mang[0],mang[1]); tempv2= max2(mang[2],mang[5]); tempv3= max3(mang[3],mang[6],mang[10]); tempv4= max3(mang[4],mang[7],mang[11]); tempv5= max3(mang[8],mang[12],mang[15]); tempv6= max2(mang[9],mang[16]); tempv7= max2(mang[13],mang[20]); tempv8= max2(mang[14],mang[17]); tempv9= mang[18]; tempv10= mang[21]; tempv11= mang[22]; tempv12= max2(mang[19],mang[23]); tempv13= mang[24]; ////////////////////////// tong=(tempv1+tempv2+tempv3+tempv4+tempv5+tempv6+te mpv7+tempv8+tempv9+tempv10+tempv11+tempv12+tempv13 ); xung_can_tinh1=(5*tempv1+10*tempv2+20*tempv3+30*te mpv4+40*tempv5+50*tempv6+60*tempv7+70*tempv8+80*te mpv9+90*tempv10+100*tempv11+110*tempv12+115*tempv1 3); // xung_can_tinh=(int8) (xung_can_tinh1/tong); // value_PWM=rat_thap_T1(value0); xung_can_tinh=(int8)(xung_can_tinh1/tong); // value_PWM=(5*tempv1+10*tempv2+20*tempv3+30*tempv4+ 40*tempv5+50*tempv6+60*tempv7+70*tempv8+80*tempv9+ 90*tempv10+100*tempv11+110*tempv12+115*tempv13)/(tempv1+tempv2+tempv3+tempv4+tempv5+tempv6+tempv7+ tempv8+tempv9+tempv10+tempv11+tempv12+tempv13); //value_PWM=xung_can_tinh; value_PWM=(int8)(xung_can_tinh*10); //------------------------------------------- for(j=0;j<25;j++) { PORTD=led7seg[high1]; portb=quet[0]; delay_us(2500); portd=0xff; delay_us(1); Portd=led7seg[low1]; portb=quet[1]; delay_us(2500); portd=0xff; delay_us(1); } //-------------------------------------------- set_PWM1_duty(value_PWM); if( ( (int)value0 > max ) || ( (int)value0 < min) ) { output_high(speak); } if( ( (int)value0 < max ) && ( (int)value0 > min) ) { output_low(speak); } i=0; } i++; } } //The End=============================================== ======================== void convert_bcd(int x) { low1=x%10; //chia lay phan du, so hang don vi high1=x/10; //tach hang tram va hang chuc } //mo hoa dau vao T1 int rat_thap_T1 (int T1) { if(T1<=10) return(100); else if(T1>=15) return(0); else if((T1>10)&&(T1<15)) return((int) (20*(15-T1))); } int thap_T1(int T1) { if(T1<=10) return(0); else if((T1>10)&&(T1<=15)) return((int) (20*(T1-10))); else if((T1>15)&&(T1<20)) return((int) (20*(-T1+20))); else if(T1>=20) return(0); } int vua_T1(int T1) { if(T1<=15) return(0); else if((T1>15)&&(T1<=20)) return((int) (20*(T1-15))); else if((T1>20)&&(T1<25)) return((int) (20*(-T1+25))); else if(T1>=25) return(0); } int cao_T1(int T1) { if(T1<=20) return(0); else if((T1>20)&&(T1<=25)) return((int) (20*(T1-20))); else if((T1>25)&&(T1<30)) return((int) (20*(-T1+30))); else if(T1>=30) return(0); } int rat_cao_T1(int T1) { if(T1<=25) return(0); else if(T1>=30) return(100); else if((T1>25)&&(T1<30)) return((int) (20*(T1-25))); } //mo hoa dau ra int rat_thap_T2 (int T2) { if(T2<=5) return(100); else if(T2>=15) return(0); else if((T2>5)&&(T2<15)) return((int) (10*(15-T2))); } int thap_T2(int T2) { if(T2<=5) return(0); else if((T2>5)&&(T2<=15)) return((int)(10*(T2-5))); else if((T2>15)&&(T2<25)) return((int)(10*(25-T2))); else if(T2>=25) return(0); } int vua_T2(int T2) { if(T2<=15) return(0); else if((T2>15)&&(T2<=25)) return((int) (10*(T2-15))); else if((T2>25)&&(T2<35)) return((int) (10*(-T2+35))); else if(T2>=35) return(0); } int cao_T2(int T2) { if(T2<=25) return(0); else if((T2>25)&&(T2<=35)) return((int) (10*(T2-25))); else if((T2>35)&&(T2<45)) return((int) (10*(-T2+45))); else if(T2>=45) return(0); } int rat_cao_T2(int T2) { if(T2<=35) return(0); else if(T2>=45) return(100); else if((T2>35)&&(T2<45)) return((int) (10*(T2-35))); } int min2(int x0,int y0) { if(x0<y0) return(x0); else if(x0>=y0) return(y0); } int max2(int x2,int y2) { if(x2<y2) return(y2); else if(x2>=y2) return(x2); } int max3 (int x3,int y3,int z3) { int temp; temp=max2( x3,y3); return(max2(temp,z3)); } ] thay đổi nội dung bởi: dinhnambkhn, 21-03-2011 lúc 08:05 PM. Lý do: nham |
![]() |
![]() |
![]() |
#2 |
Đệ tử 2 túi
Tham gia ngày: Feb 2011
Bài gửi: 45
: |
nho cac a kiem tra ho e voi!
doan chuong trinh cua minh nhu tren tong=(tempv1+tempv2+tempv3+tempv4+tempv5+tempv6+te mpv7+tempv8+tempv9+tempv10+tempv11+tempv12+tempv13 ); xung_can_tinh1=(5*tempv1+10*tempv2+20*tempv3+30*te mpv4+40*tempv5+50*tempv6+60*tempv7+70*tempv8+80*te mpv9+90*tempv10+100*tempv11+110*tempv12+115*tempv1 3); // xung_can_tinh=(int8) (xung_can_tinh1/tong); // value_PWM=rat_thap_T1(value0); xung_can_tinh=(int8)(xung_can_tinh1/tong); // value_PWM=(5*tempv1+10*tempv2+20*tempv3+30*tempv4+ 40*tempv5+50*tempv6+60*tempv7+70*tempv8+80*tempv9+ 90*tempv10+100*tempv11+110*tempv12+115*tempv13)/(tempv1+tempv2+tempv3+tempv4+tempv5+tempv6+tempv7+ tempv8+tempv9+tempv10+tempv11+tempv12+tempv13); //value_PWM=xung_can_tinh; value_PWM=(int8)(xung_can_tinh*10); thi value_PWM it nhat cung phai lon hon 5 ma trong mo phong thi no chay sai!minh da text tren visual C khi thay doi value 0 va value 1 thi no chay rat dung!khong hieu tai sao chay tren CCS thi lai chay sai!!! nhờ a e giúp m với!!thanks a e nha!!! |
![]() |
![]() |
![]() |
|
|