PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Các ngôn ngữ lập trình khác (CCS C, HT PIC,...) (http://www.picvietnam.com/forum/forumdisplay.php?f=12)
-   -   Lỗi ccs timer2 pic 16f886 (http://www.picvietnam.com/forum/showthread.php?t=29740)

minh_thanh 25-07-2012 11:48 AM

Lỗi ccs timer2 pic 16f886
 
1 Attachment(s)
Mình đang lập trình quét led 7 thanh bằng timer2
file mô phỏng trong file đính kèm.
trong đoạn code in đậm khi hiển thị led 7thanh tham số "gio_dvi" cứ tăng lên đến 4 thì lại reset lại =0; trong khi ý đồ lập trình của mình là nó phải tăng lên đến 9 rồi mới reset lại =0;
code như sau:


#include <16F886.h>
#device adc=8

#FUSES WDT //Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES NOPUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=4000000)
#use fast_io(B)
#use fast_io(A)
#use fast_io(C)
Unsigned char Ma_led[10]={0x05,0xDD,0x46,0x54,0x9C,0x34,0x24,0x5D,0x04,0x1 4};
Unsigned char Ma_ledc[10]={0x01,0xD9,0x42,0x50,0x98,0x30,0x20,0x59,0x00,0x1 0};
int8 giay,phut,sau_phut,gio_dvi,gio_chuc,gio_tram,dem;
//int16 dem;
#int_TIMER2
Void Dinh_thoi()
{
dem++;
while(dem==10)
{
if(sau_phut<10){sau_phut++;dem=0;}
else
{
sau_phut=0;
if(gio_dvi<10){gio_dvi++;}
else {gio_dvi=0;}



}
}
////////////////////Quet 3 led, gio hien tai/////////
///////////////////Quet led 1% gio(LED23)////////////////
output_C(0xFC);
output_B(Ma_led[sau_phut]);
delay_us(2800);
///////////////////Quet led hang gio(Led22)///////////
output_C(0xFB);
output_B(Ma_ledc[gio_dvi]);
delay_us(2800);
///////////////////Quet led hang chuc gio(Led21)///////////
output_C(0xF7);
output_B(Ma_led[gio_chuc]);
delay_us(2800);
/////////////////////Quet 4 led, gio tong///////////
////////////////////////////////////////////////////////////
////////////////////quet led hang 1% gio/////////////
output_C(0x7F);
output_B(Ma_led[sau_phut]);
delay_us(2800);
//////////////////quet led hang gio/////////////////
output_C(0xBF);
output_B(Ma_ledc[gio_dvi]);
delay_us(2800);
///////////////////Quet led hang chuc gio//////////////////
output_C(0xDF);
output_B(Ma_led[gio_chuc]);
delay_us(2800);
//////////////////Quet led hang tram gio//////////
output_C(0xEF);
output_B(Ma_led[gio_tram]);
delay_us(2800);

}


void main()
{

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1 (T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,124,10);
setup_oscillator(False);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
set_tris_A(0x00);
set_tris_B(0x00);
set_tris_C(0x00);
sau_phut=0;gio_dvi=0;gio_chuc=0;gio_tram=0;dem=0,g iay=0;phut=0;
while(1)
{
}
}

Rất mong ae chỉ giáo!!!!!
Xin chân thành cảm ơn.

bnthang 25-07-2012 03:53 PM

Vòng lắp else của if thiếu phần reset biến dem=0; biến đem chỉ bị reset trong phần if(sau_phut<10)


Múi giờ GMT. Hiện tại là 02:36 PM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam