có ai biết nguyên nhân khi kích hoạt ngắt tbe của pic16f877a thì toàn bộ phần code phía sau ko chạy được?
code:
cần cao thủ chỉ giáo! thanks!
code:
Code:
#include "PIC_PID_LCD.h" #define LCD_ENABLE_PIN PIN_B1 //// #define LCD_RS_PIN PIN_B0 //// #define LCD_RW_PIN PIN_B6 //// #define LCD_DATA4 PIN_B2 //// #define LCD_DATA5 PIN_B3 //// #define LCD_DATA6 PIN_B4 //// #define LCD_DATA7 PIN_B5 #include <LCD.C> #define MAX_PWM 1023 #define MIN_PWM 0 #define Max_Temp 100 #define Min_Temp 0 #define K_PWM (float) (Max_PWM / Max_temp) #define K_TEMP (float) (500.0 / 1024.0) float KP,KI,KD; float P_term,I_term,D_term; float set_point,Temp_err,ACC_err; float real_Temp; unsigned int1 time_done,Rx_RCV_DONE; signed int32 PWM_OUT; char RX_Buffer[10],Rx_index,RX_Status,Tx_index; char my_str[20]; #int_RTCC void RTCC_isr(void) { } #int_tbe void TBE_isr() { //if( my_str[Tx_index] != 0) //putc(my_str[Tx_index++]); } #int_RDA void RDA_isr(void) { char c ; c = getch(); if(c == '$') {Rx_index = 0 ; RX_Status = 1;return;} if(c == 'A') {Rx_index = 0 ; RX_Status = 2;return;} if(c == 'B') {Rx_index = 0 ; RX_Status = 3;return;} if(c == 'C') {Rx_index = 0 ; RX_Status = 4;return;} if(c == 13) {RX_buffer[Rx_index] = 0; RX_RCV_DONE = 1;return;} if((Rx_status!= 0) && ( Rx_status < 5)) { RX_buffer[Rx_index++] = c; } } #int_TIMER1 void TIMER1_isr(void) { // 4us set_timer1(40536); // 100ms time_done = 1; } #include <stdlib.h> int16 adc_result,adc_val; void main() { setup_adc_ports(AN0); setup_adc(ADC_CLOCK_DIV_2); //setup_psp(PSP_DISABLED); // setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); setup_timer_2(T2_DIV_BY_4,249,1); setup_ccp1(CCP_PWM); set_pwm1_duty(1023); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); lcd_init(); //enable_interrupts(INT_RTCC); //enable_interrupts(INT_TBE); enable_interrupts(INT_TIMER1); enable_interrupts(int_tbe); enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); // LOI O DAY MAY BAC A // DO DÒNG " enable_interrupts(int_tbe);" // CÓ ai biết cách sửa ko ? //TODO: User Code // int16 adc_result,adc_val; float tam; set_adc_channel(0); KP = 0; KI = 0; KD = 0; char adc_count; printf(lcd_putc,"\fPID System..."); delay_ms(1000); adc_val = read_adc(); set_tris_c(0x0); set_tris_b(0x0); set_tris_a(0x01); rx_status = 0; while(true) { adc_result = 0; for(adc_count = 0; adc_count < 5; adc_count++) { adc_result += read_adc(); delay_us(20); } adc_val += adc_result ; adc_val /= 6; Real_temp = (float) adc_val * 500.0 / 1024.0; Temp_err = Set_Point - Real_temp; if(time_done) { time_done = 0; //P_term = (KP * (float)Temp_err ) * Max_PWM / Max_Temp; // P P_term = (KP * Temp_err ) * K_PWM; // P ACC_err += Temp_err; //I_term = (KI * (float)ACC_err )* Max_PWM / Max_Temp; I_term = (KI * ACC_err )* K_PWM; // I D_term = (KD * Temp_err) * K_PWM; // D PWM_OUT =(P_term + I_term + D_term); if(PWM_OUT > MAX_PWM ) PWM_OUT=MAX_PWM; if(PWM_OUT < MIN_PWM ) PWM_OUT=MIN_PWM; set_pwm1_duty(PWM_OUT); printf(my_str,"%4ldA%.2f\r",PWM_OUT,Real_Temp); //enable_interrupts(INT_TBE); Tx_index = 0; putchar(my_str[0]); lcd_gotoxy(1,1); printf(lcd_putc,"T: %3.1f",real_temp); } if(RX_RCV_DONE) { RX_RCV_DONE = 0; tam = atof(RX_Buffer); switch (RX_status) { case 1: Set_Point = tam; lcd_gotoxy(0,1); printf(lcd_putc,"SP: %3.2f",tam); break; case 2: KP = Tam; break; case 3: KI = Tam; break; case 4: KD = Tam; break; default: break; } } } }