timer1 countdown

dasdas
mail@pastecode.io avatar
unknown
abc
a year ago
3.7 kB
6
Indexable
Never
#include <16f877a.h>
#use delay(crystal=4000000)
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD

#define LCD_RS_PIN PIN_B1
#define LCD_RW_PIN PIN_B2
#define LCD_ENABLE_PIN PIN_B0
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7

#use I2C(MASTER, I2C1, SLOW = 100000, STREAM = DS1307_STREAM)

#include <lcd.c>     // include LCD driver source file
#include <DSS1307.c>  // include DS1307 driver source file
#include <stdlib.h>
#use fast_io(a)
#use fast_io(c)



int sayi=0,i=65,ayr=0,durum=0,sadise=2,saniye=0,dakika=15,sadise1=2,saniye1=0,dakika1=16;

  
#int_TIMER1 //GERÇEK ZAMANLI SAYIM İÇİN TIMER1 KESMESİ
void  TIMER1_isr(void) 
{
set_timer1(15510);
sadise--;

}


void gerisayim()
{
if(input(pin_d1)&&ayr==0){
      setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
      durum=1;
      while(input(pin_d1));
      delay_ms(20);}
      //SAYDIRMA İŞa0LEMİNİ DURDURMAK İÇİN
      if(input(pin_c1)&&durum==1){
     setup_timer_1(T1_DISABLED);
      durum=0;
      while(input(pin_c1));}
      //RESETLEMEK a2İÇİN
      if(input(pin_d2)){
      setup_timer_1(T1_DISABLED);
      durum=0;
      sadise=1;
      saniye=0;
      dakika=15;
      
      while(input(pin_d2));}
      //DURUMLARIN HEPSİ AYNI OLDUGUNDA PROGRAMIN DURMASI
      if(dakika==0&&saniye==0&&sadise==0){
       setup_timer_1(T1_DISABLED);
      durum=0;
      }
      //SINIRLANDIRMALAR
      if(saniye==60)saniye=0;
      if(dakika==60)dakika=0;
}

void geri(){
   if(sadise==255){
   saniye--;
   sadise=7;
   }
      else if(saniye==255){
      dakika--;
      saniye=59;
      }
      lcd_gotoxy(35,1);
      printf(lcd_putc,"%02d:%02d"dakika,saniye); 
      }
           
 void geri2()
       {
   if(sadise1==255)
   {
   saniye1--;
   sadise1=7;   
   }   
      else if(saniye1==255)
      {
      dakika1--;
      saniye1=59;      
      }           
      lcd_gotoxy(35,2);
      printf(lcd_putc,"%02d:%02d"dakika1,saniye1);        
      }

void gerisayim2()
{
 
if(input(pin_d3)&&ayr==0){
      setup_timer_1(T1_INTERNAL|T1_DIV_BY_2); //sorun burada olabilir.
      durum=1;
      while(input(pin_d3));}
      //SAYDIRMA İŞa0LEMİNİ DURDURMAK İÇİN
      if(input(pin_d5)&&durum==1){
     setup_timer_1(T1_DISABLED);
      durum=0;
      while(input(pin_d5));}
      //RESETLEMEK a2İÇİN
      if(input(pin_d4)){
      setup_timer_1(T1_DISABLED);
      durum=0;
      sadise1=1;
      saniye1=0;
      dakika1=15;
      
      while(input(pin_d4));}
      //DURUMLARIN HEPSİ AYNI OLDUGUNDA PROGRAMIN DURMASI
      if(dakika1==0&&saniye1==0&&sadise1==0){
       setup_timer_0(T1_DISABLED);
      durum=0;
      }
      //SINIRLANDIRMALAR
      if(saniye1==60)saniye1=0;
      if(dakika1==60)dakika1=0;
     
   }

void ekran2()
{
lcd_putc('\f');
lcd_gotoxy(7, 1); 
 lcd_putc("GERISAYIM");
 lcd_gotoxy(7, 2);                            
 lcd_putc("PROGRAMI");
lcd_gotoxy(21,1);
printf(lcd_putc,"BLK-1:");
lcd_gotoxy(21,2);
printf(lcd_putc,"BLK-2:");
}


void main()
{
   lcd_init();   
   
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

   enable_interrupts(GLOBAL);

   set_tris_c(0x00);   // C portu komple çıkış

   set_tris_d(0x00);   // D portu komple çıkış

   set_tris_e(0x00);
   
   ekran2();
   
while(1)
{ 
   gerisayim();
   geri();
   gerisayim2();
   geri2();

}
}