em check mãi mà chả biết cái code này nó sai cái gì ? mấy bác kiểm tra giúp em với
em cám ơn !
em cám ơn !
Code:
#include <16f877a.h> #include <def_877a.h> #fuses XT, NOWDT, NOPROTECT, NOLVP #device PIC16F877a*=16 ADC=8 #use delay(clock=4000000) #use fast_io(C) #define tr RC5 #define ch RC6 #define dv RC7 int a, tram , chuc , dvi , SL_ngat ; int16 tocdo ; int16 soxung ; const char maled[10] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90 }; #int_timer0 void tmr0_isr() { SL_ngat++ ; set_timer0(0); } void hien_thi() { // hien thi ra LCD if(!bit_test(PIN_C5)) // hang chuc hien thi { output_high(PIN_C5); output_low(PIN_C6); portD=maled[chuc]; output_high(PIN_C7); delay_ms(5); } else { if ( !bit_test(PIN_C6) ) // hang don vi hien thi { output_high(pin_c6); output_low(dv); portD = maled[dvi]; output_high(pin_c5); delay_ms(5); } else // hang tram hien thi { output_high(pin_c7); output_low(pin_c5); portD= maled[tram]; output_high(pin_c6); delay_ms(5); } } } void main() { int value ; int temp=get_timer0() ; int temp1 ; //a=input(pin_B1); // thiet lap vao ra// set_tris_c(0x00) ; set_tris_a(0xff) ; SET_TRIS_B(0x01) ; set_tris_D(0x00); // Tinh so vong cua dong co soxung=(SL_ngat)*256 + temp ; (tocdo)=(soxung)/100 ;// 1 vong = 100 xung tram=tocdo/100; temp1=tocdo%100; chuc=temp1/10 ; dvi=temp1%10; // Thiet lap PWM// setup_timer_2(T2_DIV_BY_4,62,1); setup_ccp1(CCP_PWM); set_pwm1_duty(128) ; // thiet lap ADC setup_adc_ports(ALL_ANALOG) ; setup_adc(ADC_CLOCK_INTERNAL) ; set_adc_channel(0) ; delay_us(10); // cai dat timer0 setup_timer_0(RTCC_ext_h_to_l); // output_high(pin_b1); a= 0; tram=0 ; chuc=0 ; dvi=0 ; SL_ngat=0; output_low(tr); // cai dat ngat ngoai enable_interrupts(INT_EXT); ext_int_edge(H_to_L); enable_interrupts(GLOBAL) ; while(1) { if(input(pin_b0)==0) { while(input(pin_b0)==0) ; if(a==0) { a=1; output_low(pin_b1); // khi nhan B0 thi dao chieu dong co } else { output_high(pin_b1); a=0; } } value = read_adc(); delay_ms(5); set_pwm1_duty(value); hienthi(); } }
Comment