|
Tài trợ cho PIC Vietnam |
Đóng góp ý kiến Nơi tiếp nhận những ý kiến đóng góp của thành viên |
|
Ðiều Chỉnh | Xếp Bài |
15-06-2011, 01:39 PM | #4 |
Nhập môn đệ tử
Tham gia ngày: Oct 2010
Bài gửi: 2
: |
anh em giup do minh cai ..thanhks nhieu
minh dang viet ve de tai ung dung logic mo trong do nhiet do dung pic 16f887 nhung minh viet no bi bao loi hoai ..anh e iup minh sua cai nhen...
code: #include <htc.h> #include<stdio.h> //#include<stdlib.h> //thu vien dung cho printf #include "lcd.h" #include <string.h> #include<math.h> //#include<isntrin.h> //thu vien dung cho LCD __CONFIG(INTIO & WDTDIS & PWRTEN & MCLREN & UNPROTECT & DUNPROTECT & BORDIS & IESODIS & FCMDIS & LVPDIS); #define _XTAL_FREQ 4000000 unsigned long adc_val=0; unsigned int ResA0 ; //unsigned char count; unsigned int SetTemp =30,CurrentTemp; int dt,dm,DATA,muy =50; unsigned int dCycle=0,dCycleC=0xFFFF; float dtemp; void ClearDisplay(void); void BeginOne(void); void BeginTwo(void); int am_nhieu(int error); int am_it(int error); int bang_khong(int error); int duong_it(int error); int duong_nhieu(int error); void inference(void); void refuzzy(void); int min(int x0,int y0); int max2(int x0,int y0); int max5(int x1,int x2,int x3,int x4,int x5); unsigned int khong[101],nho[101],trung_binh[101],lon[101],rat_lon[101]; unsigned int R1[101],R2[101],R3[101],R4[101],R5[101],R[101]; int count=0; void interrupt isr() { unsigned char temp; if(RBIE&&RBIF) { RBIF = 0; // CCP1CON = 0x0C; // CCP1CON = 0x0C; ClearDisplay(); BeginOne(); printf("Set: %d C\n",SetTemp); printf("Set Up Down Ok"); do { temp = PORTB & 0x07; _delay(3000); if(temp==0x06) { if(SetTemp < 130) { SetTemp++; } // khong che settemp khong vuot qua 130 if(SetTemp>130) { SetTemp=130; } ClearDisplay(); BeginOne(); printf("Set: %d C\n",SetTemp); printf("Set Up Down Ok"); } //khong che settemp khong nho hon 30 if(temp == 0x05) { if(SetTemp > 30) { SetTemp--; } if(SetTemp<30) { SetTemp=30; } ClearDisplay(); BeginOne(); printf("Set: %d C\n",SetTemp); printf("Set Up Down Ok"); } } while(temp!=0x03); } } void main() { /*khoi tao */ //1.Khoi tao IO port ANSEL = ANSELH = 0; //Tat ca cac chan la Digital, (dung LCD) ANS0 =1; ANS5 = 0; // Chan motor enable la digital IO TRISE0 = 0; // Chan motor enable la digital output RE0 = 1; // logic 1, cho phep motor chaY TRISC1 = 0; // chan CCP2 la output TRISC2 = 0; // chan CCP1 la output /* INTF=0; // INTE=1; // INTEDG=0;*/ WPUB=0x03; //noi dien tro pullup vao RB0 RBPU=0; //cho phep pull up tich cuc muc thap nam trong thanh ghi OPTION_REG IOCB=0x03; //cho phep ngat tren 3 chan RB012 RBIF=0; //Xoa co ngat RBIE=1; //2.Khoi tao LCD lcd_init(); // ANS3=1; //3.Khoi tao VA CAU HINH ADC //+Chon nguon xung Clock ADCS0=ADCS1=1; //Chon Frc //+Chon dien ap tham chieu Vref+ = 5V, Vref- = 0: AD 10-bit, chia muc 5V = 1024 muc VCFG0 = VCFG1=0; //+Chon kenh can do CHS0 = CHS1 = 0; //Ban dau chon kenh 0 CHS2 = CHS3=0; //+Canh phai ket qua ADFM = 1; // //+Cho phep module AD hoat dong ADON = 1; // cau hinh timer 2 T2CON = 0; // prescaler = 1:1; postscaler = 1:1 TMR2ON = 1; PR2 = 99; // Thoi gian timer tran: T = Tosc * prescaler * (PR2+1) // = 1us * 1 * 200 = 200us // => tan so PWM = 1/T = 5KHz //4.Chuong trinh chinh, vong lap vo han GIE=1; //ngat toan cuc while(1) { //+Tien hanh do kenh 0 CHS0 = 0; //Chon kenh 0 GODONE = 1; //Yeu cau Module ADC chuyen doi;o09j,/ while(GODONE); //Lap tai day chung nao GODONE van con bang 1 //Nghia la GODONE bi xoa thi thoat khoi vong lap (GODONE bi xoa khi AD chuyen doi xong) //+Lay ket qua do tu kenh 0 ResA0 = (ADRESH<<8); ResA0 += ADRESL; CurrentTemp= 0.49*ResA0; dt = SetTemp-CurrentTemp; inference(); refuzzy(); /* muy = muy + dm; if(muy>99) { muy=99; } if(muy<1) { muy=1; } dtemp = ((float) (muy*65535))/100; dCycle = (unsigned int)(dtemp); dCycle = ~dCycle;*/ // CHS0=0; __delay_us(5); // cho ADC lay mau GODONE = 1; while(GODONE); adc_val = ADRESL; adc_val |= ((unsigned int)ADRESH << 8);//X256 adc_val = adc_val* 200/ 1023; if(adc_val<200){ CCP1CON = 0x0C; // cau hinh CCP1 la PWM CCP2CON = 0; // tat CCP2, chan RC1 do PORTC dieu khien CCPR1L =50-adc_val; // set duty cho CCP1 }else{ CCP2CON = 0x0C; // cau hinh CCP2 la PWM CCP1CON = 0; // tat CCP1, chan RC2 do PORTC dieu khien CCPR2L =adc_val-50; // set duty cho CCP2 } ClearDisplay(); BeginOne(); // lcd_gotoxy(0,0); printf("set:%dC\n",SetTemp); printf("\nCurrent:%dC",CurrentTemp); // sendchar(CurrentTemp); // request(); // _delay(100000); } } int am_nhieu(int error) { if(error<= -120) return(100); if((error>-120)&&(error<-60)) return((int) (5*(-60-error)/3)); if(count>= -60) return(0); } int am_it(int error) { if(error<= -120) return(0); if((error>-120)&&(error<=-60)) return((int) (5*(error+120)/3)); if((error>-60)&&(error<0)) return((int) (5*(-error)/3)); if(count>= 0) return(0); } int bang_khong(int error) { if(error<= -60) return(0); if((error>-60)&&(error<=0)) return((int) (5*(error+60)/3)); if((error>0)&&(error<60)) return((int) (5*(60-error)/3)); if(error>= 60) return(0); } int duong_it(int error) { if(error<= 0) return(0); if((error>0)&&(error<=60)) return((int) (5*(error)/3)); if((error>60)&&(error<120)) return((int) (5*(120-error)/3)); if(error>= 120) return(0); } int duong_nhieu(int error) { if(error<= 60) return(0); if((error>60)&&(error<120)) return((int) (5*(error-60)/3)); if(count>= 120) return(100); } void inference(void) { int temp1,temp2,temp3,temp4,temp5; temp1 = am_nhieu(dt); temp2 = am_it(dt); temp3 = bang_khong(dt); temp4 = duong_it(dt); temp5 = duong_nhieu(dt); for(count =0;count<100;count++) { R1[count]=min(temp1,rat_lon[count]); R2[count]=min(temp2,lon[count]); R3[count]=min(temp3,trung_binh[count]); R4[count]=min(temp4,nho[count]); R5[count]=min(temp5,khong[count]); } for(count =0;count<100;count++) { R[count]= max5(R1[count],R2[count],R3[count],R4[count],R5[count]); } } void refuzzy(void) { long int temp1 =0,temp2=0; for(count =0;count<100;count++) { temp1+=count*R[count]; temp2+=R[count]; } dm =(int) ((float) temp1/temp2 - 50); } void delay(long int wait) { unsigned int count; for(count=0;count<wait;count++); } int max2(int x0,int y0) { if(x0<y0) return(y0); if(x0>=y0) return(x0); } int max5(int x1,int x2,int x3,int x4,int x5) { int temp1,temp2,temp3; temp1 = max2(x1,x2); temp2 = max2(x3,x4); temp3 = max2(temp1,temp2); return(max2(temp3,x5)); } int min(int x0,int y0) { if(x0<y0) return(x0); if(x0>=y0) return(y0); } void BeginOne(void) { DATA = 0x80; // ExeLCD(); lcd_init(); } void BeginTwo(void) { DATA = 0xC0; // ExeLCD(); lcd_init(); } void ClearDisplay(void) { DATA = 0x01; // ExeLCD(); lcd_init(); BeginOne(); } /* * Ham nay phuc vu xuat du lieu cho ham printf */ void putch(char c) { lcd_putc(c); } ----------------------------------------- loi bao : Executing: "C:\Program Files\HI-TECH Software\PICC\9.80\bin\picc.exe" --pass1 "D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c" -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" Warning [356] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 152.24 implicit conversion of float to integer Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 207.1 implicit return at end of non-void function Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 218.1 implicit return at end of non-void function Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 229.1 implicit return at end of non-void function Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 240.1 implicit return at end of non-void function Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 249.1 implicit return at end of non-void function Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 292.1 implicit return at end of non-void function Warning [343] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 305.1 implicit return at end of non-void function Executing: "C:\Program Files\HI-TECH Software\PICC\9.80\bin\picc.exe" --pass1 "D:\nhiet do pic\chuong trinh\New Folder (3)\lcd.c" -q --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" Executing: "C:\Program Files\HI-TECH Software\PICC\9.80\bin\picc.exe" -o16f8873.cof -m16f8873.map --summary=default,-psect,-class,+mem,-hex --output=default,-inhx032 16f8873.p1 lcd.p1 --chip=16F887 -P --runtime=default,+clear,+init,-keep,+osccal,-download,-resetbits,-stackcall,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 --double=24 --float=24 --addrqual=ignore -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" (1273) Omniscient Code Generation not available in Lite mode (warning) HI-TECH C Compiler for PIC10/12/16 MCUs (Lite Mode) V9.80 Copyright (C) 2010 Microchip Technology Inc. Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 32. could not find space (202 bytes) for variable _khong Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 32. could not find space (202 bytes) for variable _nho Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 32. could not find space (202 bytes) for variable _trung_binh Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 32. could not find space (202 bytes) for variable _lon Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 32. could not find space (202 bytes) for variable _rat_lon Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R1 Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R2 Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R3 Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R4 Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R5 Error [1250] D:\nhiet do pic\chuong trinh\New Folder (3)\16f8873.c; 33. could not find space (202 bytes) for variable _R Advisory[1] too many errors (11) ********** Build failed! ********** |
|
|