Пример #1
0
//-----------------------------------------------------------------------
//	init_ADNS2051()
//-----------------------------------------------------------------------
//
void init_ADNS2051() {
int i;	

// Initialisation
	setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);

	posX = 0;
	posY = 0;

	DeltaX = 0;
	DeltaY = 0;

	teller = 0;
	teller1 = 0;

	for(i=0;i<DELTA_LOG_SIZE;i++){
		lastX[i] = 0;
		lastY[i] = 0;
	}

// Init ADNS-2051 pins
	output_high(SDIO);
	output_high(SCLK);
	output_low(PD);	
	delay_ms(2);

// Resync 
	output_high(PD);
	delay_ms(2);
	output_low(PD);
}
Пример #2
0
int main(void) {
	m_clockdivide(0);
	setup_pins();
	if ( RF_debug) {setupUSB();}
	setup_timer_1();
	setup_timer_3();
	m_bus_init();
	m_rf_open(chan,RX_add,p_length);

	int timer_3_cnt = 0;

	//sei();
	set_motors(0,0);
	while (1){
		if (check(TIFR3,OCF3A)){
			set(TIFR3, OCF3A);
			timer_3_cnt++;
			if ( timer_3_cnt % 10 ==0 ) {
				timer_3_cnt=0;
				m_green(TOGGLE);
			}
			if ( timer_3_cnt == 1000){ timer_3_cnt=0;}
		}
		if(new){
			switch ( receive_buffer[11] ) {
				case Single_Joy: single_joystick(); break;
				case Double_Joy: double_joystick(); break;
				case Tank_Mode: tank_driving(); break;
				case Mario_Kart: Mario_Drive(); break;
				default : set_motors(0,0); m_green(2);
			}
			if(RF_debug){ debug_rf(); }
		}
	}
}
void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

while (TRUE) {

      printf("\r\nSinyali Baslatmak icin B tusuna basiniz");
      if (getchar() == 'b')         //eðer b tuþuna basarsan
      {
         printf("\n1 hz sinyal aktif edildi\r");
            while (1) {
               output_high(PIN_B0);
               delay_ms(500);
               output_low(PIN_B0);
               delay_ms(500);
            }
      }
   }
}
void init_pic()
{
   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_DIV_32);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

   EXT_INT_EDGE(L_TO_H);

   OUTPUT_B(0);
   OUTPUT_C(0);

   SET_TRIS_B(0b01000111);   //pins B0, B1, B2 and B6 are set to give inputs. B0 is the external interuupt pin
                             //B0, B1 & B2 are used for people counting. B6 for zero crossing detection in fan controlling
   SET_TRIS_C(0b00000000);
   SET_TRIS_D(0b00000000);   //D port except D0 pin, is used for lcd panel

   set_adc_channel(0);            //the next read_adc call will read channel 0
}
void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32|RTCC_8_bit);   //RTCC_DIV_32 -> 122 Hz ou 30 Hz por nivel
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_EXT1);
   enable_interrupts(GLOBAL);

   
   set_tris_a (0b11110000);
   set_tris_c (0b00000000);
   set_tris_d (0b00000000);
   
   
   while(1){
	delay_ms(10);
   }

}
Пример #6
0
void main()
{
   int16 valor;
   float tensao;
   lcd_init();



   setup_adc_ports(AN0|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_16);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   set_adc_channel(0);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!

   while(1)
   {
      valor = read_adc();
      tensao = valor*5.0/1024.0;
      printf("ADC = %04ld",valor);
      printf("    Tensao = %.3fV\r", tensao);
      printf(lcd_putc,"\fADC = %ld",valor);
      printf(lcd_putc,"\nTensao = %.3fV",tensao);
      delay_ms(250);
   }
   
}
Пример #7
0
//=============================================================================
void init_prog(void)
{
setup_wdt(WDT_OFF);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);                                                
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_BIT);// TIMER0
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);                                           
setup_vref(FALSE);
setup_low_volt_detect(FALSE);              
setup_oscillator(OSC_32MHZ);                                        

set_tris_a(0xFF);//7F
set_tris_b(0xFF); //FF
set_tris_c(0x94);//94
set_tris_d(0xFF); //02                                     
set_tris_e(0xF0);  //f0   
set_tris_f(0xFF);//ff
set_tris_g(0xFC); //04
output_a(0x00);
output_b(0x00);
output_c(0x00);
output_d(0x00);
output_e(0x00);
output_f(0x00);
output_g(0x00);
}
Пример #8
0
void main(){
   
   //CHAR letA[]="A";
   //CHAR letB[]="B";
   //CHAR letC[]="C";
   //CHAR espera[]="teste";
   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);

   glcd_init(ON);   //inicializa o display
   glcd_fillScreen(0); //limpa display inteiro
   
   //glcd_text57(34, 55, letA, 1, 1);
   //glcd_rect(46,53,60,63,1,1);
   //glcd_text57(48,  55, letB, 1, 0);

   while(TRUE){
   
   glcd_imagem(1);
   delay_ms(3000);
   glcd_fillScreen(0); //limpa display inteiro
   glcd_imagem(2);
   delay_ms(3000);
   glcd_fillScreen(0); //limpa display inteiro
   
   }
}
Пример #9
0
void main()
{
   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   TX = 0;
   RX = 1;
   
   TRIS_B = 0x00;
   
   while(1)
   {
      //putc(getc());
      LED = 1;
      delay_ms(300);
      
      LED = 0;
      delay_ms(300);
      
      if(verificaFlag())
      {
         if(recebeByte())
            enviaByte('T');
      }      
   }
}
Пример #10
0
//                        ** 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 init_pic()
{
   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_DIV_32);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

   EXT_INT_EDGE(L_TO_H);

   OUTPUT_B(0);
   OUTPUT_C(0);

   SET_TRIS_B(0b01000111);   //pins B0, B1 and B2 are set to give inputs. b0 is the external interuupt pin
   SET_TRIS_C(0b00000000);
   SET_TRIS_D(0b00000000);

   set_adc_channel(0);            //the next read_adc call will read channel 0
}
Пример #12
0
void main()
{
    setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
    // enable_interrupts(INT_EXT);
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); //32.7 ms overflow
    enable_interrupts(INT_TIMER0);
    enable_interrupts(INT_RDA);
    //enable_interrupts(INT_TIMER1);
    enable_interrupts(GLOBAL);

//  setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//128ms overflow

    ext_int_edge( H_TO_L );   // Sets up EXT
    setup_timer_1 (T1_DISABLED );
    printf("NguyenHung \n \r DT5 - K53 - DHBKHN \n \r");
    printf("Ready to use !! \n\r ");
    TC3 = 0;
    RC3 = 1;

    while(true)
    {
        if(get_timer1() > MAX_PULSE_WIDTH)
        {
            if(pulse_count>FILTER_VALUE)
            {
                printf("W");
                IDLE_MODE();
            }
        }
    }
}
void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16|RTCC_8_bit);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_EXT1);
   enable_interrupts(GLOBAL);
   
   set_tris_a (0b11110000);
   set_tris_b (0b00000000);
   set_tris_c (0b00000000);
   
   cubeLevelC0 = 0xFF;
   cubeLevelC1 = 0x00;
   cubeLevelC2 = 0xFF;
   cubeLevelC3 = 0x00;
   
   cubeLevelD0 = 0x00;
   cubeLevelD1 = 0xFF;
   cubeLevelD2 = 0x00;
   cubeLevelD3 = 0xFF;

}
Пример #14
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
   }

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

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_EXT);
   ext_int_edge(L_to_H);
   enable_interrupts(GLOBAL);
   output_low(PIN_B7);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!
   
   while(TRUE)
   {
   }

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

   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!
   
      set_adc_channel(0);            // set ref valus
      delay_ms(100);
      ref_0 =read_adc();
      delay_ms(100);
      
      set_adc_channel(3);            // set ref valus
      delay_ms(100);
      ref_3 =read_adc();
      delay_ms(100);
   
   output_b(0b11111111);
   delay_ms(700);
   output_b(0);
   
   while(1){
      set_adc_channel(0);
      delay_ms(20);                        // take readings
      adc_val_0 =read_adc();
      delay_ms(20);
      if(adc_val_0 > ref_0+cons){
         l_0 =1;
         output_high(pin_d7);
         delay_ms(500);
      }
      else{
         l_0=0;
         output_low(pin_d7);
     //    delay_ms(500);
      }
      
      set_adc_channel(3);
      delay_ms(20);                        // take readings
      adc_val_3 =read_adc();
      delay_ms(20);
      if(adc_val_3> ref_3+cons){
         l_3 =1;
         output_high(pin_d6);
         delay_ms(500);
      }
      else{
         l_3=0;
         output_low(pin_d6);
      }
   }
}
Пример #17
0
void main()
{
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
set_timer1(5);
while(True);
}
Пример #18
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;
}
Пример #19
0
int main(void) { 

	m_disableJTAG();
	m_clockdivide(2);
	setup_pins();
	if (debug_fire|| RF_debug) {setupUSB();}
	setup_timer_1();
	setup_timer_3();
	m_bus_init();
	m_rf_open(chan,RX_add,p_length);

	int timer_3_cnt = 0;

	//sei();
	set_motors(0,0);
	while (1){
		if (check(TIFR3,OCF3A)){
			set(TIFR3, OCF3A);
			timer_3_cnt++;
			
			if(fired){
				since_fired++;
				if (debug_fire){
					m_usb_tx_string(" its been\t");
					m_usb_tx_int(since_fired);
					m_usb_tx_string(" milisec\n\r");
				}
			}
			if (since_fired>10){ 
				clear(PORTF,5);
				since_fired=0;
				fired = false;
				if (debug_fire){m_usb_tx_string(" its been 100 sec\n\r");}
			} 
			if ( fire && check(PINB,3)){ 
				fire=false; 
				fired=true; 
				since_fired=0;
				if (debug_fire){m_usb_tx_string(" portb 3 is high\n\r");}
			}
			
//			m_rf_open(chan,RX_add,p_length);
			m_green(TOGGLE);
			m_rf_init();
			if ( timer_3_cnt == 10){
				m_red(2);
				timer_3_cnt=0;
				m_rf_open(chan,RX_add,p_length);
			}
		}
		if(new){ turretDrive();
			if(RF_debug){ debug_rf(); }
			if ((receive_buffer[0] == 1 || receive_buffer[1]==1) && !fire){FIRE();}
		}
		//TODO fill in timer code for the firing mechanism
	}
}
Пример #20
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);
	
}	
Пример #21
0
/*======================= configuracon de dispositivos =======================*/
void setup_devices(){
	//int myerror = 0;
   /*========================= configuracion del USB =========================*/
   myerror = COM_init();
   /*========================= configuracion del MMA7455 =====================*/
   //myerror += MEMORIA_init_hw();
   //myerror += MEMORIA_init();
   
   /*========================= conversor analogo/digital =====================*/
   // myerror = AD_init_adc();
   
   /*========================= modulo CPP ====================================*/
   //myerror = CP_init_ccp();
   
   /*========================= configuracion del Reloj Digital ===============*/
   //ds1307_init(DS1307_OUT_ON_DISABLED_HIHG | DS1307_OUT_ENABLED | DS1307_OUT_1_HZ);
   //ds1307_set_date_time(0x0d, 0x01, 0x0d, 0x00, 0x0a, 0x2a, 0x00);
   
   
   
   /*-------------------------------------------------------------------------*/
   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   #ifndef CAPTURA_FRECUENCIA_H
	setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
	setup_ccp1(CCP_OFF);
   #endif
   
   /*-------------------------------------------------------------------------*/
   
   /*===================para los indicadores========================*/
   set_tris_e(0x00);
   set_tris_b(0x00);
   set_tris_c(0x80);		//configuracion para el modulo de memoria
   set_tris_d(0x48);
   output_bit(INDICADOR_USB, 0);
   output_bit(INDICADOR_AMARILLO, 1);
   ////////////////////////////////
   output_low(SPI_SCL);
   output_high(SPI_SS);
   output_low(SPI_MOSI);
   output_high(SPI_MISO);
   ////////////////////////////////
   //delay_ms(3000);
   /*===============================================================*/
   return;
}
void main()
{
   delay_ms(500);
                            
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);

   while(1)
   {  
      Ultras();
      printf(" Distancia 1 = %2.2f     Distancia 2= %2.2f \n\r", distancia, distancia2 );

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

   printf("\r\nHigh time (sampled every second):\r\n");
   setup_ccp1(CCP_CAPTURE_RE);    // Configure CCP1 to capture rise
   setup_ccp2(CCP_CAPTURE_FE);    // Configure CCP2 to capture fall
   setup_timer_1(T1_INTERNAL);    // Start timer 1

   enable_interrupts(INT_CCP2);   // Setup interrupt on falling edge
   enable_interrupts(GLOBAL);

   while(TRUE) {
      delay_ms(1000);
      printf("\r%lu us      ", pulse_width/5 );
   }

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


   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_low_volt_detect(FALSE);


    //Setup_Oscillator parameter not selected from Intr Oscillotar Config tab
    //intitSerie(31);

   set_tris_a(0b00101111);
   set_tris_c(0b11111101);
   Set_tris_D(0b11100000); // port D : Led
   
   lectureTrame();
   
   while(true){
   
         if(truc=='c'){
         clignotement();
         }
         if(truc=='j'){
         johnson();
         }
         if(truc=='t'){
         compteur();
         }
         if(truc=='h'){
         chenillard();
         }
      
   }
}
Пример #25
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);
	                                         }}
Пример #26
0
void main()
{
                                                                                                                                                                                 
setup_psp(PSP_DISABLED);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);

set_tris_b(0x00);
set_tris_d(0b00000001);
set_tris_a(0x00);


output_b(0x00);


   start:
    if (input(pin_a0)==true)
    { 
    while(1==1){
      for(a=pin_b0; a<=pin_b5; a++)
      {
         output_high(a);
         delay_ms(100);
         output_low(a);
      
      }
      for( b=a; b>=pin_b0; b--)
      {
         output_high(b);
         delay_ms(100);
         output_low(b);
       
      }
 
    }
    a=0;
    b=0;
    }
     goto start;             
}
Пример #27
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);
    }
    
}
Пример #28
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);
  }
}
Пример #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
void setup_peripherals()
{

	setup_adc( ADC_CLOCK_INTERNAL );

	setup_adc_ports( sAN0 | sAN9 );

	set_adc_channel(0);

	setup_timer_0(T0_INTERNAL|T0_DIV_64);

	setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);

	setup_timer_3(T3_DISABLED | T3_DIV_BY_1);
   	setup_timer_4(T4_DISABLED,0,1);
   	setup_timer_5(T5_DISABLED | T5_DIV_BY_1);
   	setup_timer_6(T6_DISABLED,0,1);

	setup_wdt(WDT_OFF); 

}