nut7546
Joined: 08 Sep 2010 Posts: 2
|
about Timer0,1,2 for PIC16F877 |
Posted: Thu Jan 20, 2011 3:00 am |
|
|
From below code.
Have value of A,B,C are equal?
Code: |
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#include <stdlib.h> //library for input.c
#use delay(clock=20000000)
#define ADDR_DS1307 0xD0 //Address DS1307
#use I2C(master, sda=PIN_C4, scl=PIN_C3) //I2C Bus module
#include <lcd.c>
volatile unsigned int32 I=0,A=0,J=0,B=0,K=0,C=0,;
#INT_TIMER0
void Timer0_isr() {
if(I++>3) {
A++;
output_toggle(PIN_A0);
I = 0;
}
}
#INT_TIMER1
void Timer1_isr() {
if(J++>0) {
B++;
output_toggle(PIN_A1);
J = 0;
}
}
#INT_TIMER2
void Timer2_isr() {
if(K++>0) {
C++;
output_toggle(PIN_A2);
K = 0;
}
}
void main()
{
set_tris_b(0xFF);//port RB4 and RB5 input only
set_tris_d(0x00) ; //portd output only
set_tris_a(0x00) ;
lcd_init();
enable_interrupts (GLOBAL);
enable_interrupts (INT_TIMER0);
enable_interrupts (INT_TIMER1);
enable_interrupts (INT_TIMER2);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_64);
set_timer0(0);
output_low(PIN_A0);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
set_timer1(0);
output_low(PIN_A1);
setup_timer_2(T2_DIV_BY_16,0XFF,15);
set_timer2(0);
output_low(PIN_A2);
while (true)
{
;
}
} |
|
|