Ðề tài: Đếm với CCS
View Single Post
Old 31-07-2007, 05:47 PM   #1
nhnp0708
Đệ tử 1 túi
 
nhnp0708's Avatar
 
Tham gia ngày: May 2005
Nơi Cư Ngụ: HCM
Bài gửi: 23
:
Đế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);
	}
}
__________________
Largo Winch
nhnp0708 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn