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)
-   -   Đếm với CCS (http://www.picvietnam.com/forum/showthread.php?t=1356)

nhnp0708 31-07-2007 05:47 PM

Đếm với CCS
 
Em dùng Timer0 và Timer1 đếm ngoài nhưng nó không chạy??? đã thử dùng Internal thì chạy vù vù. Các pác check dùm em nhé
code
Code:

#include "d:\code ccs\devices\16F877A.h"
#include "d:\code ccs\define\def_16F877A.h"
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#include "d:\code ccs\func\lcd_lib_4bit.c"

//Variable
int16 countA,countB;
int8 i,j;

//Interrupt
#INT_TIMER2
void isr_timer2()
{
        i = get_timer0();
        j = get_timer1();
        countA += i;
        countB += j;
        set_timer0(0);
        set_timer1(0);
}                   

void main()
{
          set_tris_a(0xFF);
        set_tris_c(0xFF);
        set_tris_d(0x00);
        lcd_init();
         
        setup_timer_0 (RTCC_EXT_H_TO_L);
        setup_timer_1 (T1_EXTERNAL);
        //setup_timer_0 (RTCC_INTERNAL);
        //setup_timer_1 (T1_INTERNAL);
        countA =0;
        countB =0;
        set_timer0(0);
        set_timer1(0);

        setup_timer_2 ( T2_DIV_BY_1, 0xFA, 1);                //10ms/interrupt
        enable_interrupts(INT_TIMER2);
          enable_interrupts(GLOBAL);
       
        while(true)
        {
        LCD_putcmd(Line_1);
        printf(LCD_putchar,"A: %lu",countA);
        LCD_putcmd(Line_2);
        printf(LCD_putchar,"B: %lu",countB);
        }
}



Múi giờ GMT. Hiện tại là 01:24 AM.

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