سلام
من این برنامه رو واسه تایمر 1 نوشتم با این فرض که ( time=4*prescaler*(1/xtal)*(65536-value پس اگه در فرکانس 20 مگا هرتز و با پرسکالر 8 ما بخواهیم 0.1 ثانیه رو تولید کنیم باید عدد 3036 رو در تایمر لود کنیم و اگه هر 0.1 ثانیه ما یه متغیر رو یک افزایش بدیم تا 10 تا میشه 1 ثانیه اما برنامه کار نمی کنه جالب اینکه من برنامه رو با تایمر 0 تست کردم و درست کار میکرد (برای تایمر0 در فرکانس 1 مگا هرتر عدد 100 رو در تایمر لود کردم ) میشه ببینید مشکل من کجاست؟
این برنامه با تایمر 1
#include <16F877A.h>
#use delay(clock=20000000)
#include <LCD.c>
/////////////Main\\\\\\\\\\\\\\\\
//time=4*prescaler*(1/xtal)*(65536-value)
void main(){
unsigned int16 a=0,b=0,on_time=0,off_time=0;
lcd_init();
on_time=3036;
off_time=3036;
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
set_timer1(on_time);
while(true){
if(get_timer1()==0){set_timer1(on_time);a++;}
if(a==10){printf(lcd_putc,"\fSECOND=%lu ",b);b++;a=0;}
}
}
و اینم برنامه برای تایمر 0
#include <16F877A.h>
#use delay(clock=1000000)
#include <LCD.c>
/////////////Main\\\\\\\\\\\\\\\\
//time=4*prescaler*(1/xtal)*(65536-value)
void main(){
unsigned int16 a=0,b=0,on_time=0,off_time=0;
lcd_init();
on_time=100;
off_time=100;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);
set_timer1(on_time);
while(true){
if(get_timer0()==0){set_timer0(on_time);a++;}
if(a==10){printf(lcd_putc,"\fSECOND=%lu ",b);b++;a=0;}
}
}
من این برنامه رو واسه تایمر 1 نوشتم با این فرض که ( time=4*prescaler*(1/xtal)*(65536-value پس اگه در فرکانس 20 مگا هرتز و با پرسکالر 8 ما بخواهیم 0.1 ثانیه رو تولید کنیم باید عدد 3036 رو در تایمر لود کنیم و اگه هر 0.1 ثانیه ما یه متغیر رو یک افزایش بدیم تا 10 تا میشه 1 ثانیه اما برنامه کار نمی کنه جالب اینکه من برنامه رو با تایمر 0 تست کردم و درست کار میکرد (برای تایمر0 در فرکانس 1 مگا هرتر عدد 100 رو در تایمر لود کردم ) میشه ببینید مشکل من کجاست؟
این برنامه با تایمر 1
#include <16F877A.h>
#use delay(clock=20000000)
#include <LCD.c>
/////////////Main\\\\\\\\\\\\\\\\
//time=4*prescaler*(1/xtal)*(65536-value)
void main(){
unsigned int16 a=0,b=0,on_time=0,off_time=0;
lcd_init();
on_time=3036;
off_time=3036;
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
set_timer1(on_time);
while(true){
if(get_timer1()==0){set_timer1(on_time);a++;}
if(a==10){printf(lcd_putc,"\fSECOND=%lu ",b);b++;a=0;}
}
}
و اینم برنامه برای تایمر 0
#include <16F877A.h>
#use delay(clock=1000000)
#include <LCD.c>
/////////////Main\\\\\\\\\\\\\\\\
//time=4*prescaler*(1/xtal)*(65536-value)
void main(){
unsigned int16 a=0,b=0,on_time=0,off_time=0;
lcd_init();
on_time=100;
off_time=100;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);
set_timer1(on_time);
while(true){
if(get_timer0()==0){set_timer0(on_time);a++;}
if(a==10){printf(lcd_putc,"\fSECOND=%lu ",b);b++;a=0;}
}
}
دیدگاه