Пример #1
1
void Prd_kn(void)  //По SPI перед. сост. ПП и прин сообщения от STM
{
// set_timer1(63036);  //65536-(0,01/(4/1000000))=65536-10000=63036 -- (10ms)  

 while (!(sspstat&0x01))  {}
  buf_prm=SSPBUF;            //чтение буфера SPI
  kod=buf_prm&0x7f;

  if (( kod > 0)&&( kod <4))  //Kan1,Kan2,Sinchr,
     {
      //зажигаем или гасим светодиод:
      if  (buf_prm & (1 << 7))
          portc=portc ^ (1 << (kod -1));  //bit=0   
      else 
          portc=portc | (1 << (kod -1));  //bit=1
     }

  if ( kod ==4)
     if  (buf_prm & (1 << 7))
          pit_bkl();
     else
          pit_bykl();

  sspcon1=sspcon1&0x7f;   //сброс бита конфликта
    //Буфер готов к передаче:   
    SSPBUF=buf_per;
    buf_per=0;

 set_timer1(45536);  //65536-(0,01/(4/8000000))=20000 -- (10ms)  

}//@
Пример #2
0
void timer1_handler() 
{
/* Set interrupt rate */
   set_timer1(65535 - 62500);  // 0.1 sec 

/* Increment interrupt counter */
   teller++;

/* Check if there was a motion */
	adns2051[MOTION] = read_ADNS2051(MOTION);
	
	if( (adns2051[MOTION] & MOTION_OCCURED) ){
	/* Read ADNS2051 delta X and Y registers */
		DeltaX = read_ADNS2051(DELTA_X);
		DeltaY = read_ADNS2051(DELTA_Y);
	
	/* Log delta's */
		lastX[teller1] = DeltaX;
		lastY[teller1] = DeltaY;

		teller1++;
		if(teller1 == DELTA_LOG_SIZE){
			teller1=0;
		}

	/* Calculate new position */
		posX = posX + DeltaX;	
		posY = posY + DeltaY;
	}	
}
Пример #3
0
void baseTime( void )
{
static unsigned long int cnt1s = 0;
set_timer1( TIMER_CONFIGURATIONS + get_timer1() );
//Se o laço 1 tiver sido acionado, começo a contar o tempo

}
Пример #4
0
void baseTime( void )
{
static unsigned long int cnt1s = 0;
set_timer1( TIMER_CONFIGURATIONS + get_timer1() );
//Se o laço 1 da via 1 tiver sido acionado, começo a contar o tempo
   if( via1.flgs.laco == 1 )
   {
      via1.flgs.tempo++;
   }
//se o laço 2 da via 1 tiver sido acionado, paro de contar o tempo e indico a máquina principal que a velocidade deve ser mostrada
   else if( via1.flgs.laco == 2 )
   {
      via1.flgs.laco = 3;
   }

//Se o laço 1 da via 2 tiver sido acionado, começo a contar o tempo
   if( via2.flgs.laco == 1 )
   {
      via2.flgs.tempo++;
   }
//se o laço 2 da via 2tiver sido acionado, paro de contar o tempo e indico a máquina principal que a velocidade deve ser mostrada
   else if( via2.flgs.laco == 2 )
   {
      via2.flgs.laco = 3;
		printf("\n\rFINAL \n\r");
   }

}
Пример #5
0
main() {

   setup_ccp1(CCP_COMPARE_CLR_ON_MATCH);     // Configure CCP1 in COMPARE mode
   setup_timer_1(T1_INTERNAL);               // Set up timer to instruction clk

   while(TRUE) {

       while(input(PIN_B0)) ;                // Wait for keypress


       setup_ccp1(CCP_COMPARE_SET_ON_MATCH); // Configure CCP1 to set
       CCP_1=0;                              // C2 high now
       set_timer1(0);

       CCP_1 = 500;                          // Set high time limit
                                             // to 100 us
                                             // limit is time/(clock/4)
                                             // 500 = .0001*(20000000/4)

       setup_ccp1(CCP_COMPARE_CLR_ON_MATCH); // Configure CCP1 in COMPARE
                                             // mode and to pull pin C2
                                             // low on a match with timer1

       delay_ms(1000);                       // Debounce - Permit only one pulse/sec
   }

}
Пример #6
0
void baseTime( void )
{
    static unsigned long int cnt1s = 0;
    set_timer1( 34285 + get_timer1() );
    cnt1s++;

    //Para testes, coloquei a base de tempo para contar somente 1 segundo. O valor correto da comparação abaixo deve ser
    // 1200
    if( cnt1s >= 20 )
    {
        cnt1s = 0;
        Clock.time.minuto++;

        if( Clock.time.minuto > 59 )
        {
            Clock.time.minuto = 0;
            Clock.time.hora++;

            if( Clock.time.hora > 23 )
            {
                Clock.time.hora = 0;
            }
        }
    }
}
Пример #7
0
void main()
{
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
set_timer1(5);
while(True);
}
Пример #8
0
//enable timer1 int, clear t1 int, pre-set timer
void setup_led_pulse()
{
   set_timer1(0);
   output_high(BOARD_LED);                // LED is turned OFF by timer1_isr()
   if(nv_product==AWS)output_high(PANEL_LED); 
   clear_interrupt(INT_TIMER1);
   enable_interrupts(INT_TIMER1);
}
Пример #9
0
void IDLE_MODE(void)
{
    disable_interrupts(INT_TIMER1);
//   disable_timer1();
    set_timer1(0);
    setup_timer_1 ( T1_DISABLED );
    pulse_count =0;
    // pulse_buff =0;
}
Пример #10
0
void  CCP1_isr(void) 
{
	//calculate the duration between two consecutive Hall signals
   sigHall_timer = ((int32)timer1_overflow * 0xFFFF + CCP_1);
   timer1_overflow = 0;
   set_timer1(0);
   //set trigger for start revolution
   circle_trigger = 1;
}
void  TIMER1_isr(void) 
{   
	set_timer1(timer1StartValue);
	//output_toggle(PIN_B7);

	
	
	if(stateControl < 3){
		stateControl++;
	}else{
		stateControl = 0;
	}
	
	
	switch (modeControl){
		case 0:
			cubeLevelC0 = Mode1_CubeLevelC0[stateControl];
			cubeLevelC1 = Mode1_CubeLevelC1[stateControl];
			cubeLevelC2 = Mode1_CubeLevelC2[stateControl];
			cubeLevelC3 = Mode1_CubeLevelC3[stateControl];
			cubeLevelD0 = Mode1_CubeLevelD0[stateControl];
			cubeLevelD1 = Mode1_CubeLevelD1[stateControl];
			cubeLevelD2 = Mode1_CubeLevelD2[stateControl];
			cubeLevelD3 = Mode1_CubeLevelD3[stateControl];

		break;
		
		case 1:
			cubeLevelC0 = Mode2_CubeLevelC0[stateControl];
			cubeLevelC1 = Mode2_CubeLevelC1[stateControl];
			cubeLevelC2 = Mode2_CubeLevelC2[stateControl];
			cubeLevelC3 = Mode2_CubeLevelC3[stateControl];
			cubeLevelD0 = Mode2_CubeLevelD0[stateControl];
			cubeLevelD1 = Mode2_CubeLevelD1[stateControl];
			cubeLevelD2 = Mode2_CubeLevelD2[stateControl];
			cubeLevelD3 = Mode2_CubeLevelD3[stateControl];

		break;
		
		case 2:
			cubeLevelC0 = rand ();
			cubeLevelC1 = rand ();
			cubeLevelC2 = rand ();
			cubeLevelC3 = rand ();
			cubeLevelD0 = rand ();
			cubeLevelD1 = rand ();
			cubeLevelD2 = rand ();
			cubeLevelD3 = rand ();
		break;

	}
	
	output_toggle(PIN_B7);
}
Пример #12
0
void isr_tmr1() {
	clear_interrupt(INT_TIMER1);
	set_timer1(0x7FFF);
	output_toggle(pos_slv);
	if (!ctrlFusoE)
		if (slv_sobe)
			fuso_slv++;
		else
			fuso_slv--;
	ctrlFusoE = !ctrlFusoE;
}
Пример #13
0
void OFF_MODE(void)
{
    disable_timer1 ();
    disable_interrupts(INT_TIMER1);
    disable_interrupts(INT_EXT);

    set_timer1(0);
    pulse_count =0;

    RC3 =0 ;
}
Пример #14
0
void main()
{
	enable_interrupts(INT_CCP1);
	enable_interrupts(global);
	setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);	
	setup_ccp1(CCP_COMPARE_SET_ON_MATCH);
	set_timer1(500);
	ccp_1=40000;
	while(1);
	
}	
void timeproc()
{
    set_timer1(get_timer1() + 15536); // 10msec at 20MHz
    dcfpulsetime++;
    dcfdeltatimer++;
    timeout10msec = 1;

    if (!(--timer400msec)) {
        timer400msec = 40;
        timeout400msec = 1;
    }
}
Пример #16
0
void TIM1_isr(void)
{
   tim1 += 1;
   uh++;
   if(tim1>25)
   {
      output_low(PIN_LED);
      tim1 = 0;
      set_timer1(0);
   }

}
Пример #17
0
void  TIMER1_isr(void) 
{
	// This will run the System Status every 2 sec to make sure nothing has changed 
	statCounter += 1;
	//printf("\r\nStatCounter = %x\n", statCounter);
	if (statCounter == 10) {
		//printf("\r\nSystem Status Update\n");
		SystemStatus();
		set_timer1(0);
		clear_interrupt(INT_TIMER1);
		statCounter = 0;
	}
}
Пример #18
0
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;
}
Пример #19
0
/** 
* 
*
*
* @return
*/
unsigned char get_byte(void)
{
  bit rbit,parity,ph;			
  unsigned char n,m,fbb;
  						
  EX1=0;				// Interrupt 1 sperren
  ET1=0;				// Interrupt von Timer 1 sperren
  
  set_timer1(380);		// Timer setzen um 1. Bit zu treffen (320-440)
#ifdef HAND
  REFRESH				//refresh
#endif   
  ph=0;					// Paritybit wird aus empfangenem Byte berechnet
  parity_ok=0;
  while(!TF1);			// warten auf Timer 1
  set_timer1(360);		// Timer 1 neu setzen fuer 2.Bit (300-420)
  rbit=FBINC;			// 1.Bit einlesen
  for(m=0;m<5;m++) rbit&=FBINC;		// zur Steigerung der Fehlertoleranz mehrfach lesen
  fbb=rbit;
  if(rbit) ph=!ph;		// Paritybit berechnen 

  for (n=2;n!=0;n=n<<1) {
    while(!TF1);
    set_timer1(350);	// Timer 1 setzen fuer Position 2.-9.Bit (342-359)
    rbit=FBINC;
    for(m=0;m<5;m++) rbit&=FBINC;	// zur Steigerung der Fehlertoleranz mehrfach lesen
    if (rbit) {
    	fbb+=n;			// Bit in Byte schreiben
    	ph=!ph;			// Paritybit berechnen
    }
  }  
  while(!TF1);				
  TR1=0;
  parity=FBINC;			// Paritybit lesen
  for(m=0;m<5;m++) parity&=FBINC;	// zur Steigerung der Fehlertoleranz mehrfach lesen
  if(parity==ph) parity_ok=1;
  return (fbb);	
}
void Ultras(){
      output_high(trig);                   
      delay_us(20);                       
      output_low(trig);
      while(!input(echo))                     
      {}
      set_timer1(0);                         
      while(input(echo))                     
      {}
      tiempo=get_timer1();
      distancia=(tiempo*10)/(58.0);
      

      output_high(trig2);                   
      delay_us(20);                       
      output_low(trig2);
      while(!input(echo2))                     
      {}
      set_timer1(0);                         
      while(input(echo2))                     
      {}
      tiempo2=get_timer1();
      distancia2=(tiempo2*10)/(58.0);     
}
Пример #21
0
void LockServo()
{
	set_timer1(0);
	set_timer5(0);
	prev_t1count 		= 0;
	prev_t5count 		= 0;
	servo_cmd			= 0;

	cmd_pos				= mposition;
	STATUS.pid_lock 	= true;
	STATUS.halt_index 	= false;
	STATUS.error 		= false;
	STATUS.move_in_prog = false;
	ypwm				= 0;
	mode 				= e_hold_mode;
}
Пример #22
0
main(){
clock_int_4MHz();

enable_interrupts (global); // Possibilita todas interrupcoes
enable_interrupts (int_timer1); // Habilita interrupcao do timer 1
//enable_interrupts (int_ext); // Habilita interrupcao externa 0 no pino B0
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8);// configura o timer 1 em 8 x 62500 = 0,5s
set_timer1(3036);		// Conta 62.500us x 8 para estourar= 0,5s

while (TRUE)
{

output_high(pin_B0); // Pisca Led na função principal
delay_ms(500);
output_low(pin_B0);
delay_ms(500);
	                                         }}
Пример #23
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;
}
Пример #24
0
void main( void )
{
  
    setup_adc_ports( NO_ANALOGS );
	set_tris_a(0b00000000 );
    set_tris_b( 0b11110000 );
    set_tris_c( 0x00 );
    set_tris_d( 0x00 );
	set_tris_e( 0x03 );
    portc = 0;
    //Habilito os displays
    output_low( PIN_B2 );
    //Faço o setup do timer1 para clock interno e com prescaler de 8. A base de tempo é de 1/( 20MHz/4/8 )= 1.6uS
    setup_timer_1( T1_INTERNAL | T1_DIV_BY_8 );
    //Carrego o timer com 34285 de forma que ele conte ( 65535 - 34285 ) = 31250*1.6uS = 50ms.
    set_timer1( TIMER_CONFIGURATIONS );
    //Habilito as interrupções do timer1 e da porta b
    enable_interrupts( global );
    enable_interrupts( int_timer1 );
    enable_interrupts( int_rb );
	
	printf("Hello Asfalto\n\r");

//dois semaforos em vermelho
	output_high( vermSem1 );
	output_low( amarSem1 );
	output_low( verdeSem1 );
	
	output_high( vermSem2 );
	output_low( amarSem2 );
	output_low( verdeSem2 );

	via1.sema.enable = 1;
	via2.sema.enable = 0;

    while( 1 )
    {

	  handlerControleVel();
	  handlerSemaforo();	
      delay_ms(50);
    }
    
}
Пример #25
0
void ResetServo()
{
	set_timer1(0);
	set_timer5(0);
	prev_t1count 	= 0;
	prev_t5count 	= 0;
	servo_cmd		= 0;

	POSCNT			= 0;
	prev_count		= 0;
	velact.ul		= 0;
	mposition.ul	= 0;
	cmd_pos.ul		= 0;
	mode 			= e_hold_mode;
	
	STATUS.halt_index 	= false;
	STATUS.error 		= false;
	STATUS.move_in_prog = false;
}
Пример #26
0
void ngat_timer1()
{
   //Do toc do
vantoc = (float)xung*6;
ek = Vdat - vantoc;
uik = ampe2 - volts_ampe;
   udk2 = udk2 + kp*ek + ki*ek2 + kpi*uik + kii* uik2;
   ek2 = ek;
   uik2 = uik;
   ampe2 = volts_ampe;
temp_V = 255/kd;
if (udk2 >temp_V) udk2 = temp_V;
if (udk2 < 1) udk2 = 1;
   udk3 = udk2 * kd;
udk = (int8)udk3;
   DAC = ~udk;
xung = 0;
   set_timer1(3036);
}
Пример #27
0
//======================================
//Chuong trinh chinh
//======================================
void main()
{
enable_interrupts(int_rda); //Cai datngattruyen thong
ext_int_edge( H_TO_L );
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); //Cai dat bo chia Timer 1
enable_interrupts(INT_TIMER1); //Timer1 65536
   set_timer1(3036); //Cai dat Timer 1 ngat trong 0.1s
enable_interrupts(INT_EXT);
enable_interrupts(global);
   //Datcac gia tri ban dau cho cacbien
xung = 0;
vantoc = 0;
Vdat = 0;
kp = 0;
ki = 0;
kpi = 0;
kii = 0;
kd = 0; //Bien TG khoi dong
//Cai dat vao ra
set_tris_a(0xFF);
set_tris_b(0xFF);
set_tris_c(0xc0);
set_tris_d(0x00);
delay_ms(50);
   //Cai dat ADC
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(RA0_ANALOG);
set_adc_channel(0);
setup_comparator(NC_NC_NC_NC); 
setup_vref(FALSE); 
delay_ms(50);
while(1)
   {
   //Do dong dien
do_dong();
delay_ms(50); 
do_dong();
delay_ms(50);
   //Xuat len may tinh
printf("!%4.0f|%1.3f@",(float)vantoc,(float)ampe);
  }
}
Пример #28
0
/************************************************************************
*                                                                       *
*  Purpose:    Read the state of the buttons to turn on the GLCD led    *
*                                                                       *
*  Proposito:  Lee el estado de los botones para encender la luz GLCD   *
*                                                                       *
*  Passed:     None                                                     *
*  Argumento:  Nada                                                     *
*  Returned:   None                                                     *
*  Retorno:    Nada                                                     *
*  Note:                                                                *
*                                                                       *
*                                                                       *
************************************************************************/
void lightbuttons(void)
{   
   up = input(PIN_UP);
   down = input(PIN_DOWN);
   left = input(PIN_LEFT);
   right = input(PIN_RIGHT);
   enter = input(PIN_ENTER);
   if ((up==PRESSED)||(down==PRESSED)||(enter==PRESSED)||(left==PRESSED)||(right==PRESSED))
   {      
      up=!PRESSED;
      down=!PRESSED;
      left=!PRESSED;
      right=!PRESSED;
      enter=!PRESSED;
      tim1 = 0;   
      output_high(PIN_LED);
      set_timer1(0);
   }        
       
}
Пример #29
0
void main(void)
{
  long time;
  float a, b, c;
  a = 5;
  b = 100;

  setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
  set_timer1(0);
  
  c = a * b;

  //printf("test");


  time = get_timer1();
  time -= 2;
  printf("\r\n The program takes %lu clock cycles", time);
  printf("\r\n Each clock cycle is %lu microseconds \r\n", (time+2)/5);
  printf("\r\n Total time is %lu microseconds \r\n", time * (time+2)/5);
}
Пример #30
0
/************************************************************************
*                                                                       *
*  Purpose:    Read the state of the buttons                            *
*                                                                       *
*  Proposito:  Lee el estado de los botones                             *
*                                                                       *
*  Passed:     None                                                     *
*  Argumento:  Nada                                                     *
*  Returned:   None                                                     *
*  Retorno:    Nada                                                     *
*  Note:                                                                *
*                                                                       *
*                                                                       *
************************************************************************/
void readbuttons(void)
{
    while (button==!PRESSED)
    {
        lastup = up;
        lastdown = down;
        lastleft = left;
        lastright = right;
        lastenter = enter;
        up = input(PIN_UP);
        down = input(PIN_DOWN);
        left = input(PIN_LEFT);
        right = input(PIN_RIGHT);
        enter = input(PIN_ENTER);
        if ((up!=lastup)||(down!=lastdown)||(enter!=lastenter)||(lastleft!=left)||(lastright!=right))
        {
            button = PRESSED;
            set_timer1(0);
            tim1 = 0;
            output_high(PIN_LED);
        }
    }
}