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
}
Example #2
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);
   }
   
}
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);
   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);
            }
      }
   }
}
Example #5
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);
}
Example #6
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
   
   }
}
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)
   {
   }

}
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);
   }

}
Example #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');
      }      
   }
}
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;

}
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);
      }
   }
}
Example #12
0
void main()
{
	char reponse='a';
	int flag=255;
	int id1=23;	
	int id2=12;

	int value1=15;
	int value2=16;
	int value3=17;
	
	//initialisation du PIC 
	setup_adc(ADC_OFF);  		//on gère toutes les entrées comme étant de type analogique et on mesure les tensions par rapport à une ref 5V


	enable_interrupts(INT_TIMER2);      //configuration des interruptions
	enable_interrupts(INT_AD);
	enable_interrupts(GLOBAL);

	setup_timer_2(T2_DIV_BY_4,250,5);   //setup up timer2 to interrupt every 0,1ms
	can_init();							//initialise le CAN
	can_set_baud();						//obsolète à priori à tester
	restart_wdt();

	#ifdef DEBUG
	   // Mise en évidence d'un problème lié au Watchdog
   	   switch ( restart_cause() )
       {
          case WDT_TIMEOUT:
          {
             printf("\r\nRestarted processor because of watchdog timeout!\r\n");
             break;
          }
          case NORMAL_POWER_UP:
          {
             printf("\r\nNormal power up! PIC initialized \r\n");
             break;
          }
       }
       restart_wdt();
    #endif


	//  BOUCLE DE TRAVAIL
	while(TRUE)
	{
		putc(flag);
		putc(id1);
		putc(value1);
		putc(flag);
		putc(id1);
		putc(value2);
		putc(flag);
		putc(id2);
		putc(value3);
	}
}
Example #13
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;
}
Example #14
0
void main()
{
   setup_timer_2(T2_DIV_BY_16,255,1);      //4.0 ms overflow, 4.0 ms interrupt

   setup_ccp1(CCP_PWM);
   setup_ccp2(CCP_PWM);
   set_pwm1_duty((int16)200);
   set_pwm2_duty((int16)200);

   enable_interrupts(INT_SSP);
   enable_interrupts(GLOBAL);
   
   SET_TRIS_B(0);
   stop();
   //delay_ms(500); 
   
   while(TRUE)
   {
      
      if(hasCommand)
      {
         hasCommand= FALSE;
         if(buffer[0] == 's'){
            show();
         }
         
         else
            switch(buffer[1]) 
            { 
               case 1: 
                 go_forward();
                 break;
               case 2:
                 go_backward();
                 break;
               case 3:
                 turn_right();
                 break;
               case 4:
                 turn_left();
                 break;
               case 5:
                 stop();                            
                 break;
               default : 
                  break;
            }
      }
   }

}
Example #15
0
void setup_motors() //initialize PWM
{
    //setup_timer_2(T2_DIV_BY_1, 255, 16);
    setup_timer_2(T2_DIV_BY_16, SPEED, 16);
    //setup_timer_2(T2_DIV_BY_4, 63, 16); 
    
    // 5Mz instruction cycle, pwm cycle every 4*64 cycles (19.5khz)
    // interrupt every 16th of that (not used)
    setup_ccp1(CCP_PWM);
    // PWM output on CCP1/RC2, pin 17

    setup_ccp2(CCP_PWM);
    // PWM output on CCP2/RC1, pin 16.  PWM2 can be moved to pin 36; see ServoSkeleton
}
Example #16
0
void pwm_init (int1 enabled)
{
    set_tris_c (0);             /* CCP1 is RC2, CCP2 is RC1 */
    pwm_enabled = enabled;
    if (enabled) {
        setup_ccp1 (CCP_PWM);
        setup_ccp2 (CCP_PWM);
        setup_timer_2 (T2_DIV_BY_16, 255, 1); // 88 is 2.8 KHz
    }
    else {
        setup_ccp1 (CCP_OFF);
        setup_ccp2 (CCP_OFF);
    }
}
Example #17
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();
         }
      
   }
}
Example #18
0
void main()
{
   setup_adc_ports(ALL_ANALOG);        //Les ports sont analogiques, RA3 (+5V) est la référence...

   enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);

   setup_timer_2(T2_DIV_BY_4,79,16);   //setup up timer2 to interrupt every 1ms
   can_init();
   can_set_baud();

   //  BOUCLE DE TRAVAIL
   while(TRUE)
   {
      internalLogic();
      manageCAN();
   }
}
Example #19
0
void main()
{
	setup_adc_ports(NO_ANALOGS);

	enable_interrupts(INT_TIMER2);
	enable_interrupts(GLOBAL);

	setup_timer_2(T2_DIV_BY_4,79,16);   //setup up timer2 to interrupt every 1ms
	can_init();
	can_set_baud();

	//  BOUCLE DE TRAVAIL
	while(TRUE)
	{
		internalLogic();
		manageCAN();
	}
}
Example #20
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;             
}
Example #21
0
void PowerOnSetProc()
{		 	
	port_b_pullups(TRUE);	output_b(0xff); output_c(0xff);		
	
	set_tris_A(0b00000011);	set_tris_B(0b01111111);

	set_tris_D(0b00000000);	set_tris_E(0b00000000);
	
	set_tris_C(0b10010000);
	
	setup_adc_ports(NO_ANALOGS);
	setup_adc(ADC_OFF);

	setup_comparator(NC_NC_NC_NC);
	setup_vref(FALSE);
	setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

	setup_timer_2(T2_DIV_BY_4,250,2);		 // 8,000,000 / (4 * 8 * (249 +1)) = 1,000 = 1/1000 sec
	set_timer2(0);
	enable_interrupts(INT_TIMER2);
	
	// LCD 초기화 하기 전에 대기 없으면 이상한 현상이 생김  
	delay_ms(100); 

	LCD_Initialization();				

	setup_psp(PSP_DISABLED);	
	delay_ms(250);
	SerialPortSetup();	

	LCD_Clear();
	enable_interrupts(INT_RDA);	
	enable_interrupts(GLOBAL);	

             //"01234567890123456789"
	strcpy(st, "DIGITAL OPERAT      "); PrintLCD(0,0,st);
	strcpy(st, "[EwDo-21] v2.60     "); PrintLCD(1,0,st);
	strcpy(st, "EunWho Power Electic"); PrintLCD(2,0,st);
	strcpy(st, "TEL 82-51-262-7532  "); PrintLCD(3,0,st);
	delay_ms(3250);
	delay_ms(3250);
}
//**** Funciones genericas ***************************************************
void Inicio(void){ 
   //--- ini: mPaP -----------------------------------------------------------
   numPulsosX=numPulsosY=numPulsosZ=numPulsosE=0;
   periodoPulsosX=periodoPulsosY=periodoPulsosZ=periodoPulsosE=0;
   //--- ini: PID ------------------------------------------------------------
   min=0.0; max=1023 ; //valor Anti-windup    
   i1=0;e1=0;d1=0;   
   Kd=8; Kp=8; Ki=0.02915;
   T=5;       //Tiempo de muestreo  tr/6 < T < tr/20
   Kpz=Kp; Kiz=Ki*T/2; Kdz=Kd/T;
   
   //--- ini: CCP ---------------------------------------------------------
   //--- Pre=16 PR2=249 Pos=1, PWMF=3kHz,PWMT=300us con Fosc(clock)=48MHz
   setup_timer_2(T2_DIV_BY_16,249,1); 
   setup_ccp1(ccp_pwm);               //Configurar modulo CCP1 en modo PWM
   set_pwm1_duty(0);  
   
   //--- ini: ADC ---------------------------------------------------------  
   setup_adc_ports(AN0|VSS_VDD );     
   setup_adc(ADC_CLOCK_INTERNAL); 
   //setup_adc(ADC_CLOCK_DIV_8); //respetar el Tad>1.6us 
                                 //Tad=8/Fosc=8/20Mhz=400ns
   set_adc_channel(0);           //Seleccionar Canal(0)=AN0=A0 para ADC
   
   //--- ini: TIMER0 for OS_Timer() ---------------------------------------                                  
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);  //config Timer0, Pre=1=RTCC_DIV_1
   //set_timer0(0xF63B);   //carga del Timer0, clock=20MHz, Fout=1kHz=0xF63B
   set_timer0(0xE88F);     //carga del Timer0, clock=48MHz, Fout=1kHz=0xE88F
   
   //--- ini: Interrupts --------------------------------------------------
   //enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER0);            //habilita interrupcion Timer0
   //enable_interrupts(INT_TIMER2);
   
   //--- ini: USB ------------------------------------------------------------
   usb_init();                   //inicializamos el USB
   usb_task();                   //habilita periferico usb e interrupciones
   usb_wait_for_enumeration();   //esperamos hasta que el PicUSB 
                                 //sea configurado por el host
   delay_ms(50);   
}
void main()
{

set_tris_D(0);

setup_timer_2(T2_DIV_BY_1,249,16);      //50.0 us overflow, 800 us interrupt
  // setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_EXT1);
   enable_interrupts(INT_EXT2);
   enable_interrupts(GLOBAL);
   
   while(true)
   {
   output_high(pin_D3);
   delay_ms(10);
   output_low(pin_D3);
   delay_ms(10);
   }
}
void main()
{
   int i, seq[10] = {n0, n1, n2, n3, n4, n5, n6, n7, n8, n9}, tensao;

   setup_adc_ports(AN0|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_8);
   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_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   set_adc_channel(0);

   //TODO: User Code
   while(TRUE)
   {
      tensao = read_adc();
      if(tensao >= 127)
      {
         for(i = 1; i < 10; i++)
         {
            output_D(seq[i]);
            delay_ms(1000);
         }
      }
      else
      {
         for(i = 9; i >= 1; i--)
         {
            output_D(seq[i]);
            delay_ms(1000);
         }
      }
   }

}
Example #25
0
File: MICROPF.c Project: mr3m/MICRO
//Incluye las cabeceras antes descritas
void main(){                           //Rutina principal
    output_high(LED);                  //Enciende el LED indicador
    lcd_init();                         
    //Rutina de incializacion del LCD
    lcd_putc("\fListo      \n");        
    //Despliega el mensaje "Listo" en el LCD
    setup_adc_ports(AN0);               
    //Fija el pin 0 del puerto A como entrada analogica
    setup_adc (adc_clock_internal);     
    //El tiempo para la conversion AD esta dado por el oscilador 
    //interno
    set_adc_channel(0);                 //El puerto AD activo es el 0
    enable_interrupts(INT_EXT);        
    //Habilita la interrupcion externa en RB0
    ext_int_edge(L_to_H);
    //Fija la interrupcion por flanco de subida.
    setup_timer_2(T2_DIV_BY_16,129,16);
    //El tiempo de oscilacion del timer 2 sirve tanto para la
    //interrupcion por timer2 como para el PWM. 
    setup_ccp1(CCP_PWM);              
    //Da de alta el modulo CCP1 como PWM 
    //y lo inicializa en duty cycle 0
    set_pwm1_duty(0);
    setup_ccp2(CCP_PWM);
    //Da de alta el modulo CCP2 como PWM 
    //y lo inicializa en duty cycle 0
    set_pwm2_duty(0);
    enable_interrupts(GLOBAL);          
    //Habilita las interrupciones globales
    output_low(LED);        //Apaga el led antes encendido.
    
    while(TRUE){           
        //Esta rutina espera a la interrupcion y parpadea el LED
        //indicador
        output_low(LED);
        delay_ms(100);
        output_high(LED);
        delay_ms(100);
    }
   }
Example #26
0
void main()
{
	//initialisation du PIC
	setup_adc_ports(NO_ANALOGS);        //on gère toutes les entrées comme étant de type numérique

	enable_interrupts(INT_TIMER2);      //configuration des interruptions
	enable_interrupts(GLOBAL);

	setup_timer_2(T2_DIV_BY_4,250,5);   //setup up timer2 to interrupt every 1ms
	can_init();							//initialise le CAN
	restart_wdt();

	#ifdef DEBUG
	   // Mise en évidence d'un problème lié au Watchdog
   	   switch ( restart_cause() )
       {
          case WDT_TIMEOUT:
          {
             printf("\r\nRestarted processor because of watchdog timeout!\r\n");
             break;
          }
          case NORMAL_POWER_UP:
          {
             printf("\r\nNormal power up! PIC initialized \r\n");
             break;
          }
       }
       restart_wdt();
    #endif



	//  BOUCLE DE TRAVAIL
	while(TRUE)
	{
		restart_wdt();
		listenCAN();
	}
}
Example #27
0
//------------------------------------------------------------------------------
void main(){
   int i;
   
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2|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);
   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);
   disable_interrupts(INT_TIMER0);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF);

   output_low(PIN_C5);
	
   while(TRUE){

      if(f_process){
         f_process=0;
         output_toggle(PIN_C5);
         disable_interrupts(INT_RDA);
			printf("\n\r");
         for(i=0;i<(cont-2);i++){
         	printf("vector[%u]=%c\n\r",i,p[i]); //muestro los datos recibidos
         }
         procesar_guardar();
         cont=0;
         printf("Fin programacion\n\r");
         enable_interrupts(INT_RDA);
      }
   }
}
Example #28
0
void main()
{
    int8    val;
    char car;

    // Initialization
    delay_ms(400);
    disable_interrupts(global);
    disable_interrupts(int_timer1);
    disable_interrupts(int_timer2);
    disable_interrupts(int_ext);
    setup_adc_ports(NO_ANALOGS|VSS_VDD);
    setup_adc(ADC_OFF|ADC_TAD_MUL_0);
    setup_spi(FALSE);
    setup_wdt(WDT_OFF);
    setup_timer_0(RTCC_INTERNAL);
    setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
    setup_timer_2(T2_DIV_BY_1,2,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(False);
    delay_ms(400);
    
    while(1)
    {
        val = input(PIN_B0);
        if (val == 0)
        {
            output_a(0);
        }
        else if (val == 1)
        {
            output_a(255);
        }
    }
}
Example #29
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(0x00);
set_tris_b(0x24); 
set_tris_c(0x80);
set_tris_d(0x00);                                      
set_tris_e(0x15);     
set_tris_f(0x58);
set_tris_g(0x10);
output_a(0x00);
output_b(0x00);
output_c(0x00);
output_d(0x00);
output_e(0x00);
output_f(0x00);
output_g(0x00);
// RF Modul and PA/LNA activation
 
   IOpin.modulepower=0;
   IOpin.moduleCTX=1;
   IOpin.moduleCPS=0;
   IOpin.modulePWRUP=1;
   
}
Example #30
0
void in_init()
{
	output_low(PI_CHARLIEPLEX_SWITCH_1_PIN);
	output_low(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_low(PI_CHARLIEPLEX_SWITCH_3_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_1_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_2_PIN);
	output_float(PI_CHARLIEPLEX_SWITCH_3_PIN);
	output_float(PI_ENCODER_A_PIN);
	output_float(PI_ENCODER_B_PIN);

	RBPU = 0; //Enable pull-up resistors on PORT B
	WPUB = PI_BUTTON_PULLUP_RESISTORS; //Enable pull-ups for buttons
	
	//At 4Mhz instruction frequency (ClockF=16Mhz/4): it increments every 4us
	//	With post scaler: generate an interrupt every 16 periods:
	//		Resolution: 64us
	//		Min period: 64us (15.625 KHz) 
	//		Max period: 255*64us = 16.320 ms (61Hz)
	//	For 30 counts period, it interrupts every ~ 2ms
	setup_timer_2( T2_DIV_BY_16, (IN_ENCODER_SCAN_PERIOD_US/64)-1, 16 );
	enable_interrupts(INT_TIMER2);
}