Exemple #1
0
void timer() {
	set_timer0(0x8ad0);

	if(DelayCount) {
		--DelayCount;
	}

	//Blink
	if(BlinkMode == 0) {
		if(cnt == 20) {
			output_toggle(LEDR);
			cnt = 0;
		}
		else {
			cnt++;
		}
	}

	//Chirp
	if(BlinkMode == 2) {
		if(!cnt) {
			output_low(LEDR);
		}
		else {
			cnt--;
		}
	}
}
void timer0_int()
{
   set_timer0 (Timerstartwert_K);          // Timer0 Interr. alle 1/100 sek
   --Down_B; 
   if (-- Presc_B == 0)
   {
      Presc_B = Preload_K;
      if (++Hsec_B == 100)
      {
         Hsec_B = 0;
         if (++Sec_B == 60)
         {
            Sec_B = 0;
            if (++Min_B == 60)
            {
               Min_B = 0;
               if (++Hour_B == 24)
               {
                  Hour_B = 0;
               }
            }
         }
      }
   }
}
Exemple #3
0
void main()
{
   //T1CONL=0x30;
   //T1CONH=0xA0;
   
   setup_timer_0 (RTCC_INTERNAL|RTCC_DIV_16);
   set_timer0(0);
   led_io=0;
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_io_dieukhien();
   Speaker_io=0;
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   lcd_init();
   delay_ms(10);
   init_DS1307();
   delay_ms(10);
   init_ext_eeprom();
   delay_ms(10);
   LED_LCD_IO=0;
   LED_LCD=1;
   Init_595();
   menu_system=0;
   load_eeprom();
   off_all_van();
   while(true)
   {
      switch_menu();
   }
}
//                        ** Grundinitialisierung **
void coldstart () 
{   
    setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
   setup_oscillator(OSC_8MHZ|OSC_INTRC);
   setup_comparator(NC_NC_NC_NC);
   output_a (0b00001000);
   output_b (0);
   output_c (0);
   output_d (0);
   output_e (0);
   set_tris_a (TRISA_INIT);               // Datenrichtung Port A
   set_tris_b (TRISB_INIT);               // Datenrichtung Port B
   set_tris_c (TRISC_INIT);
   set_tris_d (TRISD_INIT);
   set_tris_e (TRISE_INIT);
   port_b_pullups(TRUE);
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32|RTCC_8_BIT);
                                    // Timer0 intern, Takt 20.00/4/64 = 78.125 KHz
                                       // Interrupt alle 256/15.625 = 3.2768 ms (305Hz)
                                       // Korrekturwert für 10 ms: 156 Timerclicks
                                       // -> Timer wird auf 256-156=100 vorgestellt 
      set_timer0 (Timerstartwert_K);            // Timerwert auf Startwert setzen
      enable_interrupts(INT_TIMER0);
   setup_timer_1(T1_DISABLED);               // Nur Timer0 Interrupt
   delay_ms (200);
}            
void start_heartbeat()
{
   set_timer0(TIMER0_PRESET);     // Preset e.g. 3036 for 1.000000 sec intervals
   clear_interrupt(INT_TIMER0);
   enable_interrupts(INT_TIMER0);
   setup_wdt(WDT_ON);
}
Exemple #6
0
void trata_timer0() {
    set_timer0(131 + get_timer0());
    vtimer++;
    if (vtimer == 1) {
        vtimer = 0;
        segundos++; // incrementa os segundos

        if ((segundos % 60) == 0) { // quando fechar 1 minuto, o display é atualizado
            segundos = 0; // reinicia o contador
            incrementa_minutos(1);
            parar_alarme();

            // verifica se existe alarme configurado para exibir nesta hora
            if (var_alarme_configurado && (var_alarme_horas == temp_global_horas && var_alarme_minutos == temp_global_minutos)) {
                var_alarme_tocando = 1;
                output_high(PIN_A0); // pino alarme
            }

            // exibe apenas se o alarme nao estiver sendo configurado
            if (var_alarme_configurando == 0) {
                exibe_relogio(temp_global_horas, temp_global_minutos);
            }
        }
    }
}
Exemple #7
0
// Purpose:    Start our timeout timer
// Inputs:     Enable, used to turn timer on/off
// Outputs:    None
void modbus_enable_timeout(int1 enable) {
	disable_interrupts(INT_TIMER0);
	if (enable) {
		set_timer0(0);
		clear_interrupt(INT_TIMER0);
		enable_interrupts(INT_TIMER0);
	}
}
Exemple #8
0
void sch_wr500(void)
{ 
  set_timer0(64536);     //184  256-(0,0005/(4/1000000))=65036 -- (500 mks)       
 // RC6=~RC6;  	
  if (RC6==0)   RC6=1;  //RC6=~RC6;
	else  RC6=0; 
  //  set_timer0(131);     //184  65536-(0,0005/(4/1000000))=65036 -- (500 mks)      
}//@
void TIMER0_isr(void) {
    set_timer0 (0x00);
    cont_tiempo++;
    if (cont_tiempo == 2023) {
        output_toggle(PIN_D0);
        cont_tiempo = 0;
    }
}               //Se recarga el timer0
void Configurar_interrupciones() {
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);   //Configuración timer0
    set_timer0 (0x00);                 //Carga del timer0
    ext_int_edge(L_TO_H);         // Flag INTF si flanco de bajada / H_TO_L bajada
    enable_interrupts(INT_EXT);   // habilitar interrupcion del RB0 /INTE
    enable_interrupts(INT_RB);   // habilitar interrupcion del RB
    enable_interrupts(GLOBAL);
}
Exemple #11
0
/*********************************************************************
 * Function:        void TickInit(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          Tick manager is initialized.
 *
 * Side Effects:    None
 *
 * Overview:        Initializes Timer0 as a tick counter.
 *
 * Note:            None
 ********************************************************************/
void TickInit(void)
{
    setup_timer_0(RTCC_INTERNAL | RTCC_DIV_16);
    set_timer0(TICK_COUNTER);

    enable_interrupts(INT_TIMER0);
    enable_interrupts(GLOBAL);
}
Exemple #12
0
/** Special function for processing falling edge,
 * must be called from ISR
 * \param tmr Timer value at the moment of falling edge
 */
INLINE
void ProcessFallingEdge(uint16_t tmr)
{
 //save period value if it is correct. We need to do it forst of all to have fresh stroke_period value
 if (CHECKBIT(flags, F_VHTPER))
 {
  //calculate stroke period
  hall.stroke_period = tmr - hall.measure_start_value;
  WRITEBIT(flags, F_SPSIGN, tmr < hall.measure_start_value); //save sign
  hall.t1oc_s = hall.t1oc, hall.t1oc = 0; //save value and reset counter
 }
 SETBIT(flags, F_VHTPER);
 SETBIT(flags, F_STROKE); //set the stroke-synchronization event (устанавливаем событие тактовой синхронизации)
 hall.measure_start_value = tmr;

 if (!CHECKBIT(flags2, F_SHUTTER_S))
 {
  uint16_t delay;
#ifdef STROBOSCOPE
  hall.strobe = 1; //strobe!
#endif

  //-----------------------------------------------------
  //Software PWM is very sensitive even to small delays. So, we need to allow OCF2 and TOV2
  //interrupts occur during processing of this handler.
#ifdef COOLINGFAN_PWM
  _ENABLE_INTERRUPT();
#endif
  //-----------------------------------------------------

  //start timer for counting out of advance angle (spark)
  delay = (((uint32_t)hall.advance_angle * hall.stroke_period) / hall.degrees_per_stroke);
#ifdef COOLINGFAN_PWM
  _DISABLE_INTERRUPT();
#endif

  OCR1A = tmr + ((delay < 15) ? 15 : delay) - CALIBRATION_DELAY; //set compare channel, additionally prevent spark missing when advance angle is near to 60°
  TIFR1 = _BV(OCF1A);
  TIMSK1|= _BV(OCIE1A);

  //start timer for countiong out of knock window opening
  if (CHECKBIT(flags, F_USEKNK))
  {
#ifdef COOLINGFAN_PWM
   _ENABLE_INTERRUPT();
#endif
   delay = ((uint32_t)hall.knock_wnd_begin * hall.stroke_period) / hall.degrees_per_stroke;
#ifdef COOLINGFAN_PWM
   _DISABLE_INTERRUPT();
#endif
   set_timer0(delay);
   hall.knkwnd_mode = 0;
  }

  knock_start_settings_latching();//start the process of downloading the settings into the HIP9011 (запускаем процесс загрузки настроек в HIP)
  adc_begin_measure(_AB(hall.stroke_period, 1) < 4);//start the process of measuring analog input values (запуск процесса измерения значений аналоговых входов)
 }
}
Exemple #13
0
void main()
{
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
set_timer0(5);
while(True);
output_high(pin_B1);
}	
/*
   Restarts servicing of WD with timer0
*/
void restart_heartbeat()
{
   // pre-sets timer0, resets WDT, LED ON, clear t0 int
   set_timer0(TIMER0_PRESET);
   restart_wdt();
   clear_interrupt(INT_TIMER0);
   enable_interrupts(INT_TIMER0);
   setup_led_pulse();
}
Exemple #15
0
void interruption()
{
	set_timer0(6);
	Contador--;
	if(Contador == 0)
	{
		output_toggle(PIN_A0);
		Contador = 250;	
	}	
}
void Configurar_interrupciones(){
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);   //Configuración timer0
   set_timer0 (0x1B);                    //Carga del timer0
   enable_interrupts(INT_TIMER0);       //Habilita interrupción timer0

   enable_interrupts(INT_RB);       // Habilitando interrupcion RB /RB4-RB7
   //bit_clear(OPTION_REG,7);         // Habilita el Pull-UP de RB->OPTION_REG,RBPU
   RBPU=0;                            // Habilita el PullUP de RB 
   enable_interrupts(GLOBAL);       // Habilita las interrupciones
}
Exemple #17
0
void main() {
    segundos = 0;
    enable_interrupts(GLOBAL|INT_RB|INT_TIMER0); // habilita interrupção global, na porta B e do timer 0

    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);  // define uso do timer 0 com prescaler 16
    set_timer0(131); // inicia contagem do timer 0

    while(true) {
        // deixa programa executando
    }
}
void ACTIVE_MODE(void)
{
    disable_interrupts(INT_TIMER0);
    RC3 =1 ;
    wait(0x100);// so luyen: 01686269854
//   wait(0xffff);
    set_timer0(0);
    enable_interrupts(INT_TIMER0);
    set_timer1(0);
    enable_interrupts(INT_EXT);
    ext_int_edge( H_TO_L );   // higt to low
    pulse_count =0;
}
void  TIMER0_isr(void)
{
cpucounter++;
if(cpucounter<100)
IOpin.cpuLED=1;
else
IOpin.cpuLED=0;
if(cpucounter>=1000)
cpucounter=0;

set_timer0(5);
clear_interrupt(int_timer0);
}
Exemple #20
0
void main()
{
	set_tris_a(0xFE);
	output_low(PIN_A0);
	setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
	set_timer0(6);
	enable_interrupts(GLOBAL);
	enable_interrupts(INT_TIMER0);
	do
	{
		
	}while(TRUE);		
}	
Exemple #21
0
  void timers_isr(void)
{
   set_timer0(178);
   while(gtimers)
   {
   gtimers--;
      if(atimer[gtimers]!=0)
      {
         atimer[gtimers]--; 
      }
   }
   gtimers=N_TIMERS;

}
Exemple #22
0
void main (void)
{
   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   
   set_timer0(127);

    while(1)
   {
      delay_ms(200);
      puertoA = puertoA ^ (1<<5);
   } 
}
void TIMER0_isr(void) {
   Cont_TMR0++;
   if (Cont_TMR0 >= 1000){         //las sentencias del if se daran cada 100ms
      Cont_Tiempo_espera++;
      if (Cont_Tiempo_espera >= Tiempo_espera){    // se verifica que se paso solo el tiempo permitido
         if (Cont_Num_aplausos == Num_aplausos){   // se verifica que se tenga la cantidad de aplausos necesarios
            Estado_foco_ant = Estado_foco;         //se guarda el estado anterior del foco
            Estado_foco = 2;                       // se establece el foco en modo programacion
         }
         Cont_Tiempo_espera = 0;
      }
      Cont_TMR0 = 0;
   }
   //output_toggle(PIN_D1);
   set_timer0 (0x97);            //para que la interrupcion se de cada 100us
   }
Exemple #24
0
void trata_timer0() 
{ 
    set_timer0(131 + get_timer0());
    vtimer++; 
    if (vtimer == 10)
	{
       vtimer = 0; 
       seconds++;
	   if (seconds > 59)
	   {
			fireAlarmState = 0;
			output_low(PIN_B1);
			seconds = 0;
			minuteElapsed();
	   }
    }
} 
Exemple #25
0
int main( int argc, char *argv[] )
{
	int fd = 0;
	int i = 0;
	int retval = -1;	
	int interval = 1;
	
	if ((retval = arg_filter( argc, argv)) != 0) {
		return -1;
	}

	if ((fd = open("/dev/mem", O_RDWR)) < 0) {
		perror("open");
		return -1;
	}
	
	iobaseaddr = mmap( 0,
				0x100000,
				PROT_READ|PROT_WRITE,
				MAP_SHARED,
				fd,
				(unsigned int)0x1fd00000 );

	gpioaddr = iobaseaddr + SB_GPIO_BASE;

	time = atoi(argv[2]);

	// Register function to SIGALRM
	if ( !(strcmp(argv[1], "0")) ) {
		light_on();
		signal(SIGALRM, light_led_continuously);
		set_timer0( time );
	}
	else if ( !(strcmp(argv[1], "1")) ) {
		light_on();
		interval = 200000;
		signal(SIGALRM, light_led_blinking);
		set_timer1( interval );
	}

	while (count < time) {
		pause();
	}

	return 0;
}
Exemple #26
0
/**
 * main entry point
 */
void main(void)
{
    unsigned char   n;

    // hardware initialisieren
    restart_hw();

    // warten bis der BUS stabil ist
    for (n=0; n<50; n++)
    {
        set_timer0(0xFFFF);
        while(!TF0);
    }

    // Protokoll zurücksetzen
    restart_prot();

#ifdef DEBUG
    // serielle Schnittstelle für DEBUG Ausgaben initialisieren
    rs_init(576);
#endif

    // initialize/reset application
    restart_app();

    // main loop
    while (1)
    {
        if (!TR1) // check if TR1 is active -> send/receive finished
        {
            // applikation ausführen
            app_process();

            if (RTCCON>=0x80)
            {
                stop_rtc();
                rtc_process();  // Realtime clock Ueberlauf
                start_rtc(65);  // RTC mit 65ms neu starten
            }
        }

        // check program button
        check_prog_button();
    }
}
Exemple #27
0
// Frequency of interrupt (clock/(4*divisor)) / (256-reload) 
void mcu_init() 
{ 
   setup_oscillator(OSC_16MHZ); 
   setup_adc_ports(NO_ANALOGS); 
   setup_adc(ADC_OFF); 
   setup_comparator(NC_NC_NC_NC); 

 
   // Setup the TIMER0 Interrupt 
   set_timer0(0); 
   setup_timer_0(RTCC_INTERNAL | RTCC_8_BIT | RTCC_DIV_4); 
   enable_interrupts(INT_TIMER0); 
   enable_interrupts(GLOBAL); 

   set_tris_a(0);
   set_tris_b(0);
   set_tris_c(0);
}
void TIMER0_isr(void) {
   set_timer0 (0x00);      // Se recarga el TMR0  
      Btemp=PORTB;
         PORTB=0X0E;
         delay_ms(10);
         if(RBIF!=1){
             PORTB=0X0D;
             delay_ms(10);
            if(RBIF!=1){
             PORTB=0X0B;
             delay_ms(10);
               if(RBIF!=1){
                PORTB=0X07;
                delay_ms(10);
               }
            }
         }

   }
Exemple #29
0
void  TIMER1_isr(void) //pokud neni do definovaného okamziku vynulovan timer1, tak se resetuje napajeni odroidu
{
   if(timer1>3) //slouzí pro prodlouzeni casu
         {
         ODROID_OFF_1;           // odpojí relé
         delay_ms(1000);
         ODROID_OFF_0;
         ODROID_ON_1;           // pripojí relé
         delay_ms(10);
         ODROID_ON_0;
         ODROID_I=1;
         set_timer0(0);
         timer1=0;
         }
   else
   {
   timer1=timer1+1;      
   }
 }
Exemple #30
0
void ActivaLed() {
	Ticks++;

	if (Ticks==0) {
		//LedAzul=1;
		OUTPUT_HIGH(LedAzul);
		//LedRojo=1;
		OUTPUT_HIGH(LedRojo);
		//LedVerde=1;
		OUTPUT_HIGH(LedVerde);
	};
	if (Ticks==Rojo)
			OUTPUT_LOW(LedRojo);
	if (Ticks==Verde)
			OUTPUT_LOW(LedVerde);
	if (Ticks==Azul)
			OUTPUT_LOW(LedAzul);
	set_timer0(140);
}