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

}
Пример #2
0
void main (void)
   {
   
       set_tris_c(0xff);
       set_tris_e(0xff);
       
       while(1)
       
         { 
           leds = lee_microsw();
           output_a(leds);
           printf("%u\n",leds);    
           delay_ms(200);
           
          if(leds==valor)
            {
              valor=lee_microsw();
            }
           else
            {
              valor=lee_microsw();
              leds = lee_microsw();
              printf("%u\n",leds);    
              
            }
             delay_ms(200);
         }
   
   }
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;

}
Пример #4
0
void EXT_isr(void)                                
{ 
unsigned int8 c,d;

set_tris_c(0x82);// RX modul DATA için giriþ yap
IOpin.moduleCLK=0;
//resetcounter=0;
//reinitnrfcounter=0;
//reinitikeycounter=0;

for(d=0;d<PAYLOADSIZE;d++)
{
   for(c=0;c<8;c++)
   {
      ShiftReg=ShiftReg<<1;
      ShiftRegLSB=IOpin.moduleDATA;
      IOpin.moduleCLK=1;
      IOpin.moduleCLK=1;
      IOpin.moduleCLK=0;
      IOpin.moduleCLK=0;
   }

RXBuffer[d]=ShiftReg;
}

IOpin.comled^=1;

//set_CHID();
//init_nrf24();
//IOpin.antled1^=1;
//IOpin.antled2=0;
clear_interrupt(int_ext2);
}
Пример #5
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);
}            
Пример #6
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);
}
Пример #7
0
void main(void){
   int count = 0;
   InitialChip();
   delay_ms(200);
   SHTConReset(); 
   set_tris_c(0b00011001);
   init();
   
   //Pressure_init();
   output_low(PIN_A0);
   
  //1 setup_adc_ports(NO_ANALOGS|VSS_VDD);
  //2 setup_adc(ADC_CLOCK_DIV_2);
   //setup_spi(SPI_SS_DISABLED);
  //3 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  //4 setup_timer_1(T1_DISABLED);
  //5 setup_timer_2(T2_DISABLED,0,1);
  //6 setup_ccp1(CCP_OFF);
  //7setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard

   enable_interrupts(INT_SSP);
   enable_interrupts(GLOBAL);
   
    
   if (gblTimeToUpdateScreen) 
   {
      gblTimeToUpdateScreen = 0;
      updateScreen();
   }
   
   while(true)
   {               
     float temp, humid;
     //int16 sonic;
     float sonic;
     
     int error = oa_Temp_n_Humid(temp, humid);
     if (error) continue;
     //temp =3265;
     //humid =6532;
     show_temp(temp);
     show_humid(humid);
     
     //PC commented to change to Float
     //sonic = oa_Sonic();
     //show_sonic(sonic);
     
     
     sonic = foa_Sonic();
     //sonic = 6000/16-sonic;
     show_sonic(sonic);
     
     
     vTemp = temp;
     vHumid = humid;
     vSonic = sonic;
   }
}
Пример #8
0
void port_configure()
{
set_tris_c(0b10011000);
output_low(pin_c6);
led_spp_on;             // Led visualizaçao Arranque correcto
delay_ms(200);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
led_spp_off;
}
Пример #9
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;
}
Пример #10
0
  void bsp_init(void)
  {
    set_tris_c(0xff);
    set_tris_e(0xff);
    set_tris_a(0x00);
    output_a(0);
    set_tris_a(0);//configurado como salida
    set_tris_e(1); //configurado como entrada
    SETUP_ADC_PORTS(sAN5); // este pin es analogo
    SET_ADC_CHANNEL(5); // el canal que usaremos y de cual obtendremos la señal es el 5
    setup_adc(ADC_CLOCK_DIV_32);
    lcd_init();
 
  }
Пример #11
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);
    }
}
Пример #12
0
void main(void)
   {
       int8 leds;
       set_tris_c(0xff);
       set_tris_e(0xff);
       set_tris_a(0);
       
      
       while(1)
       
       {
           leds = lee_microsw();
           output_a(leds);
           delay_ms(200);
       }
   }
Пример #13
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();
         }
      
   }
}
Пример #14
0
//PROGRAMA PRINCIPAL
void main ()
{
   int8 DisNumbs[10] = {   //Este arreglo guarda los códigos para la representación de los números en el display.
      0b00111111, //0
      0b00000110, //1
      0b01011011, //2
      0b01001111, //3
      0b01100110, //4
      0b01101101, //5
      0b01111101, //6
      0b00000111, //7
      0b01111111, //8
      0b01101111  //9
   };
//Parámetros de Timer0.
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);
//Habilitación de interrupciones.
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);
//Parámetros del ADC.
   setup_adc_ports(RA0_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
   delay_us(10);   //Se requiere un pequeño delay para estabilizar la señal al cambiar de canal.
//Puertos usados para displays en salida.
   set_tris_b(0x00);
   set_tris_c(0x00);
   set_tris_d(0x00);
   output_b(0x00);
   output_c(0x00);
   output_d(0x00);

   while (true) {
   //Se le da salida a los números calculados de acuerdo al display al que están conectados.
      if (readSens){
         readSens=false;
         ValAnalog = read_adc();   //Se lee y convierte el valor analógico a digital.
         Temperatura = (float)ValAnalog * (0.48875);   //Se convierte el valor digital a ºC
         Calcs();
      }
      output_b(DisNumbs[Decena]);
      output_c(DisNumbs[Unidad]);
      output_d(DisNumbs[Decimal]);
   }
}
Пример #15
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);
}
Пример #16
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);
    }
    
}
Пример #17
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);
  }
}
Пример #18
0
// see usb_hw_layer.h for documentation
void usb_detach(void)
{
   UCON = 0;  //disable USB hardware
   UIE = 0;   //disable USB interrupts
   UCFG = __UCFG_VAL_DISABLED__;
   
   // set D+/D- to inputs
  #if defined(__USB_87J50__)
   set_tris_f(get_tris_f() | 0x18);
  #elif defined(__USB_K50__)
   set_tris_a(get_tris_a() | 0x3);
  #else
   set_tris_c(get_tris_c() | 0x30);
  #endif
  
   usb_state = USB_STATE_DETACHED;
   
   usb_token_reset();              //clear the chapter9 stack
   //__usb_kbhit_status=0;
}
Пример #19
0
void main ()
{

set_tris_a(0xff);
set_tris_c(0x00);
set_tris_b(0x00);

output_c(0x00);
output_b(0x00);

setup_adc_ports(RA0_ANALOG);
set_adc_channel(0);
setup_adc(ADC_CLOCK_DIV_32);

enable_interrupts(int_rtcc);
enable_interrupts(GLOBAL);
set_timer0(0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);


while (true)
{
if(con==9){
cif = read_adc();
cif *= .488281;   //por que Vref / 1024 = 0.004882  x 100

aux=floor(cif); //floor me regresa el entero de cif en aux
dec=cif-aux;

d1=floor(aux/10);
aux-=d1*10;

d2=floor(aux);
d3=floor(dec/0.1);
d4=(floor(dec/0.01))-(d3*10);
con=0;
}

}

}
Пример #20
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;
   
}
//-----------------------------------------------------------------//
// Programa Principal ---------------------------------------------//
//-----------------------------------------------------------------//
void main() {
   int i;
  set_tris_a(0xFF);      // Puerto A todo entradas
  port_b_pullups(FALSE); // Resistencias de polarización
  set_tris_b(0x38);      //
  set_tris_c(0x00);      // Puerto C todo salidas
  set_tris_d(0x00);     // Puerto D todo salidas

  //Configuro los canales del ADC
  SETUP_ADC_PORTS(AN0_AN1_AN2_AN3_AN4);
  SETUP_ADC(ADC_CLOCK_DIV_8 );
  SETUP_VREF(VREF_HIGH | 6 );


  //Habilito interrupciones
  //enable_interrupts(int_rda);
  //enable_interrupts(global);

  while(1){
  realizar_ensayo();
  //printf("%4ld \r",md);
  }
 }
Пример #22
0
void main()
{
   setup_adc_ports(NO_ANALOGS);        //TODO : vérifier s'il existe des entrées analogiques pour le TdB
   set_tris_a(0b00110001);
   set_tris_c(0b00010100);
   set_tris_d(0b01110001);
   set_tris_e(0b00000001);

   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

   setup_timer_2(T2_DIV_BY_4,79,16);    //Le Timer 2 reprend à zéro toutes les millisecondes environ.

   can_init();
   can_set_baud();

   //  BOUCLE DE TRAVAIL
   while(TRUE)
   {
      internalLogic();
      manageCAN();
   }
}
Пример #23
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);
   
   PORT_C.6 = 0;
   PORT_C.7 = 1;
   
   set_tris_c(X);
   
   while(1)
   {
      printf("RS 232");
      getc();
      putc(getc());
   }
}
Пример #24
0
void main ()
{
disable_interrupts(GLOBAL);   //общее запрещение прерываний
setup_oscillator(OSC_8MHZ);  //|OSC_INTRC
 
set_tris_a(0x00);   //выходы
set_tris_b(0xff);   //входы
set_tris_c(0x10);   //выходы, RC4-вход(данные от STM)

//output_c(0x4f);
portc=0x4f;
porta=0x7f;
portb=0xff;

//set_tris_c(0x10);   //выходы, RC4-вход(данные от STM)
//output_a(0x7f);
//output_b(0xff);

pit_bykl();
pr_wkl_pit=0;   //пр. вкл. питания (исп. для 1-го нажатия кн. "Питание")

delay_ms(1000);  //для настройки STM

//Инициализация модуля MSSP(режим SPI)
SSPCON1=0x31;
SSPSTAT=0;    //0x80;
SSPBUF=0x55;

//иниц. таймеров:
//t0con=0xc8; //8-ми разр
t0con=0x88; //16-ми разр счетчик
T1CON=0x85;
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);  

set_timer1(62286);
set_timer0(64536); 

//enable_interrupts(INT_TIMER2);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);

//СОСТОЯНИЕ кнопок и ручек по ВКЛЮЧЕНИЮ:
//----------------------------------------
for (ii=0; ii<6;ii++) 
 {
   du_pA=porta&0xc0|mask[ii];
   output_a(du_pA);   
   pr_state_rb[ii] = input_b();
 }

while(1)
{
   for (ii=0; ii<6;ii++) 
 {
   pr_ruk=0;
  // output_a(mask[ii]);              //SL... -> PORTA
   du_pA=porta&0xc0|mask[ii];
   output_a(du_pA); 
   tek_state_rb[ii] = input_b();
   if (pr_state_rb[ii] ^ tek_state_rb[ii])
    //возможно  нажатие или вращение ?
   {
    if ((tek_state_rb[ii]&mask_kn[ii])!=mask_kn[ii])  //если это кнопка, то отрабат. дребезг
       { //кнопка
	    delay_ms(1);
	    tek1_state_rb = input_b();
	    delay_ms(1);
	    tek2_state_rb = input_b();
	    delay_ms(1);
	    tek3_state_rb = input_b();
	
	//    if (tek_state_rb[ii] == tek3_state_rb)  //дребезг зак.-есть нажатие/отжатие или вращение!
       }
     else  //ручка
       {
         tek3_state_rb=tek_state_rb[ii];

       }

       if (tek_state_rb[ii] == tek3_state_rb)  //дребезг зак.-есть нажатие/отжатие или вращение!

       switch(ii)   //номер сигнала SL0,SL1,SL2,SL3,SL4,SL5
			{
              case 0:  //SL0
                //Кнопки K1, Ser:
				if (!(tek3_state_rb & (1 << 0)))  { buf_per=0x81;  //№1-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 0)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x01;  //№1-отж.
                                                    break; 
                                                  }
                  if (!(tek3_state_rb & (1 << 5))) { buf_per=0x82;  //№2-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 5)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x02;  //№2-отж.
                                                    break; 
                                                  }

                //Ручки -B_K1, +B_K1 -Sm_K1, +Sm_K1:
                //***********************************
                
              if  ((tek3_state_rb & 0x02)&&(tek3_state_rb & 0x04))  //RB1 & RB2==1
                    { 
                     for (ib=0; ib<2;ib++) 
                     {
                       if ((tek3_state_rb & (0x02 << ib)) && (!(pr_state_rb[ii] & (0x02 << ib))))
                            
                            switch(ib)
			                {
                               case 0: 
                                pr_ruk=1;
                                buf_per=0x14;  //№20-влево 
                               break;

                               case 1:
                                pr_ruk=1;  
                                buf_per=0x94;  //№20-вправо
                               break;
                            }//switch 
                     } //for  ib    
                   } //if

          //    else
          //     {                 
               if  ((tek3_state_rb & 0x08)&&(tek3_state_rb & 0x10)&& (!pr_ruk))   //RB3 & RB4==1 & pr_ruk=0
                 {
                     for (ib=0; ib<2;ib++) 
                   {

                     if ((tek3_state_rb & (0x08 << ib)) && (!(pr_state_rb[ii] & (0x08 << ib))))
                             
                            switch(ib)
			                {
                               case 0: 
                               {
                                buf_per=0x15;  //№21-влево 
                                break;
                               }

                               case 1: 
                               {
                                buf_per=0x95;  //№21-вправо
                               break;
                               }
                            }//switch ib
                     } //for
                   
                   } //if
         //      } //else
              pr_state_rb[ii]=tek3_state_rb;
              pr_ruk=0;
			  break;
                               
              case 1:    //SL1
               //Кнопки K2, DISP:
				if (!(tek3_state_rb & (1 << 0))) { buf_per=0x83;  //№3-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 0)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x03;  //№2-отж.
                                                    break; 
                                                  }
                  if (!(tek3_state_rb & (1 << 5))) { buf_per=0x84;  //№4-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 5)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x04;  //№4-отж.
                                                    break; 
                                                  }

                //Ручки -B_K2, +B_K2 -Sm_K2, +Sm_K2:
                //***********************************
                
              if  ((tek3_state_rb & 0x02)&&(tek3_state_rb & 0x04))  //RB1 & RB2==1
                    { 
                     for (ib=0; ib<2;ib++) 
                     {
                       if ((tek3_state_rb & (0x02 << ib)) && (!(pr_state_rb[ii] & (0x02 << ib))))
                             
                            switch(ib)
			                {
                               case 0: 
                                pr_ruk=1;
                                buf_per=0x16;  //№22-влево
                               break;

                               case 1: 
                                pr_ruk=1;
                                buf_per=0x96;  //№22-вправо
                               break;
                            }//switch 
                     } //for      
                   } //if

           //   else
           //    {                 
               if  ((tek3_state_rb & 0x08)&&(tek3_state_rb & 0x10) && (!pr_ruk))   //RB3 & RB4==1 & (!pr_ruk)
                 {
                     for (ib=0; ib<2;ib++) 
                   {

                     if ((tek3_state_rb & (0x08 << ib)) && (!(pr_state_rb[ii] & (0x08 << ib))))
                             
                            switch(ib)
			                {
                               case 0: 
                               {
                                buf_per=0x17;  //№23-влево
                                break;
                               }

                               case 1: 
                               {
                               buf_per=0x97;  //№23-вправо
                               break;
                               }
                            }//switch 
                     } //for
                   
                   } //if
           //    } //else
//              pr_state_rb[ii]=tek3_state_rb;
              pr_ruk=0;
						 		                        
			  break;
      
              case 2: //SL2
               //Кнопки Raz, Pam:
				if (!(tek3_state_rb & (1 << 0))) { buf_per=0x85;  //№5-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 0)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x05;  //№5-отж.
                                                    break; 
                                                  }
                  if (!(tek3_state_rb & (1 << 5))) { buf_per=0x86;  //№6-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 5)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x06;  //№6-отж.
                                                    break; 
                                                  }
                //Ручки -T, +T -Del, +Del:
                //***********************************
                
              if  ((tek3_state_rb & 0x02)&&(tek3_state_rb & 0x04))  //RB1 & RB2==1
                    { 
                     for (ib=0; ib<2;ib++) 
                     {
                       if ((tek3_state_rb & (0x02 << ib)) && (!(pr_state_rb[ii] & (0x02 << ib))))
                             
                            switch(ib)
			                {
                               case 0: 
                                pr_ruk=1;
                                buf_per=0x18;  //№24-влево
                               break;

                               case 1: 
                                pr_ruk=1;
                                buf_per=0x98;  //№24-вправо
                               break;
                            }//switch 
                     } //for      
                   } //if

           //   else
               {                 
               if  ((tek3_state_rb & 0x08)&&(tek3_state_rb & 0x10) && (!pr_ruk))   //RB3 & RB4==1 & (!pr_ruk)
                 {
                     for (ib=0; ib<2;ib++) 
                   {

                     if ((tek3_state_rb & (0x08 << ib)) && (!(pr_state_rb[ii] & (0x08 << ib))))
                             
                            switch(ib)
			                {
                               case 0: 
                               {
                                buf_per=0x19;  //№25-влево
                                break;
                               }

                               case 1: 
                               {
                               buf_per=0x99;  //№25-вправо
                               break;
                               }
                            }//switch 
                     } //for
                   
                   } //if
               } //else
//              pr_state_rb[ii]=tek3_state_rb; 
			  pr_ruk=0;			 		                        
			  break; 

              case 3:  //SL3

               //Кнопки Sinch, Pusk, Kurs, Izm:
				if (!(tek3_state_rb & (1 << 0))) { buf_per=0x87;  //№7-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 0)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x07;  //№7-отж.
                                                    break; 
                                                  }
                if (!(tek3_state_rb & (1 << 3))) { buf_per=0x88;  //№8-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 3)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x08;  //№8-отж.
                                                    break; 
                                                  }
                if (!(tek3_state_rb & (1 << 4))) { buf_per=0x89;  //№9-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 4)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x09;  //№9-отж.
                                                    break; 
                                                  }
                if (!(tek3_state_rb & (1 << 5))) { buf_per=0x8A;  //№10-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 5)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x0A;  //№10-отж.
                                                    break; 
                                                  }

                //Ручки -Ur, +Ur :
                //****************
                
              if  ((tek3_state_rb & 0x02)&&(tek3_state_rb & 0x04))  //RB1 & RB2==1
                    { 
                     for (ib=0; ib<2;ib++) 
                     {
                       if ((tek3_state_rb & (0x02 << ib)) && (!(pr_state_rb[ii] & (0x02 << ib))))
                             
                            switch(ib)
			                {
                               case 0: 
                                buf_per=0x1A;  //№26-влево
                               break;

                               case 1:
                               buf_per=0x9A;  //№26-вправо
                               break;
                            }//switch 
                     } //for      
                   } //if
//			    pr_state_rb[ii]=tek3_state_rb; 			 		                        
			  break;

              case 4: // SL4
              //Кнопки Pit, Sbor:
				if (!(tek3_state_rb & (1 << 0)))  { buf_per=0x8B;  //№11-наж.
                                                    if (pr_wkl_pit==0)
                                                      {
                                                       pit_bkl();
                                                       
                                                      } 
                                                    break; 
                                                  }
                  if (!(tek3_state_rb & (1 << 5))) { buf_per=0x8C;  //№12-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 5)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x0C;  //№12-отж.
                                                    break; 
                                                  }


                //Ручки -Ur, +Ur :
                //****************
                
              if  ((tek3_state_rb & 0x02)&&(tek3_state_rb & 0x04))  //RB1 & RB2==1
                    { 
                     for (ib=0; ib<2;ib++) 
                     {
                       if ((tek3_state_rb & (0x02 << ib)) && (!(pr_state_rb[ii] & (0x02 << ib))))
                             
                            switch(ib)
			                {
                               case 0: 
                                buf_per=0x1B;  //№27-влево
                               break;

                               case 1: 
                                buf_per=0x9B;  //№27-вправо
                               break;
                            }//switch 
                     } //for      
                   } //if
//			     pr_state_rb[ii]=tek3_state_rb; 			 		                        
			  break; 

              case 5: //SL5 
               //Кнопки Men,"1", "2", "3", "4", "5":
				if (!(tek3_state_rb & (1 << 0))) { buf_per=0x8D;  //№13-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 0)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x0D;  //№13-отж.
                                                    break; 
                                                  }
                if (!(tek3_state_rb & (1 << 1))) { buf_per=0x8e;  //№14-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 1)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x0e;  //№14-отж.
                                                    break; 
                                                  }
                if (!(tek3_state_rb & (1 << 2))) { buf_per=0x8f;  //№15-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 2)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x0f;  //№15-отж.
                                                    break; 
                                                  }
                if (!(tek3_state_rb & (1 << 3))) { buf_per=0x90;  //№16-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 3)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x10;  //№16-отж.
                                                    break; 
                                                  }
                if (!(tek3_state_rb & (1 << 4))) { buf_per=0x91;  //№17-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 4)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x11;  //№17-отж.
                                                    break; 
                                                  }
                if (!(tek3_state_rb & (1 << 5))) { buf_per=0x92;  //№18-наж.
                                                    do
                                                     tek3_state_rb = input_b(); 
                                                    while (!(tek3_state_rb & (1 << 5)));
                                                    //отжатие произошло
                                                    while (buf_per!=0) {}
                                                     buf_per=0x12;  //№18-отж.
                                                    break; 
                                                  }

  
                pr_state_rb[ii]=tek3_state_rb; 						 		                        
			  break;

            }//switch(ii) 
    pr_state_rb[ii]=tek3_state_rb;         
   }//if
     
 }//for (ii)

}//while(1)
//output_bit(PIN_C3,1);
//BUF_CAP[i-1]=input(PIN_C4);
//output_bit( PIN_B2, 0);  //Ldac  в 0

//level = input_state(pin_A3);

}  //main
Пример #25
0
//*****************************************************************************************
//*****************************************************************************************
//P RO G R A M A     P R I N C I P A L
//*****************************************************************************************
//*****************************************************************************************
void main(){
   float32* fltPtr;
   float32 varX,varY,varZ;
   float32 Xp,Yp;
   float32 fx,fy,fz;
   float incX;
   float incY;
   
   char x,y,z;
   char posicion;

   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_spi2(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_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   set_tris_a(0x00);
   set_tris_b(0x00);
   set_tris_c(0xC0);
   set_tris_d(0x00);
   set_tris_e(0x00);

   DELAY_MS(200);

   output_b(0xFF);

   GLCD_init(1);

   DELAY_MS(500);

   output_b(0x00);

   //Setear propiedades de la grafica.
   graph.x1=0.0;
   graph.y1=0.0;
   graph.x2=127.0;
   graph.y2=63.0;

   graph.minX=-1.0;
   graph.maxX=1.0;
   graph.minY=-1.0;
   graph.maxY=1.0;

   graph.minViewX=-2.5;
   graph.maxViewX=2.5;
   graph.minViewY=-1.25;
   graph.maxViewY=1.25;

   printf("Hecho por Bruno Fascendini @ 2009 para uControl y Todopic\r\ncomo parte de proyecto calculadora cientifica con PIC del foro uControl\r\n");
   printf("Parseador version: %s Evaluador version: %s\r\n",ParserVer,EvaluadorVer);
   //menú:
   printf("Ingrese la superficie a graficar: ");

   posicion=0;
   do{
      EquIn[posicion]=getc();
      if(posicion>0 && EquIn[posicion]==8) posicion--; else posicion++;      //delete if delete key pressed...
      if(posicion==BUFFER_SIZE) break;
   }while(EquIn[posicion-1]!=13);
   EquIn[posicion]='\0';

   printf("Ha pedido que se grafique la ecuacion: %s",EquIn);

   printf("Ingrese valor minimo de x: ");
   posicion=0;
   do{
      temp[posicion]=getc();
      if(posicion>0 && temp[posicion]==8) posicion--; else posicion++;      //delete if delete key pressed...
      if(posicion==BUFFER_SIZE) break;
   }while(temp[posicion-1]!=13);
   temp[posicion]='\0';
   graph.minX=atof(temp);
   
   printf("Ingrese valor maximo de x: ");
   posicion=0;
   do{
      temp[posicion]=getc();
      if(posicion>0 && temp[posicion]==8) posicion--; else posicion++;      //delete if delete key pressed...
      if(posicion==BUFFER_SIZE) break;
   }while(temp[posicion-1]!=13);
   temp[posicion]='\0';
   graph.maxX=atof(temp);

   printf("Ingrese valor minimo de y: ");
   posicion=0;
   do{
      temp[posicion]=getc();
      if(posicion>0 && temp[posicion]==8) posicion--; else posicion++;      //delete if delete key pressed...
      if(posicion==BUFFER_SIZE) break;
   }while(temp[posicion-1]!=13);
   temp[posicion]='\0';
   graph.minY=atof(temp);
   
   printf("Ingrese valor maximo de y: ");
   posicion=0;
   do{
      temp[posicion]=getc();
      if(posicion>0 && temp[posicion]==8) posicion--; else posicion++;      //delete if delete key pressed...
      if(posicion==BUFFER_SIZE) break;
   }while(temp[posicion-1]!=13);
   temp[posicion]='\0';
   graph.maxY=atof(temp);

   graph.minViewX=graph.minX;
   graph.maxViewX=graph.maxX;
   graph.minViewY=graph.minY;
   graph.maxViewY=graph.maxY;

   //Calculating centers...
   graph.centerX= (graph.x2-graph.x1)/2;
   graph.centerY= (graph.y2-graph.y1)/2;

   incX=(graph.maxX-graph.minX)/50;       //set step cuantity for X axis
   incY=(graph.maxY-graph.minY)/50;       //set step cuantity for Y axis

   printf("Graficando...\r\n");

   //////////////////////////////////////////////////
   //PROCESO..............
   //comienzo del parseado de la ecuacion ingresada...
   //////////////////////////////////////////////////

   strlwr(EquIn);                        //1) PASAR EQUACION A MINUSCULAS

   //printf("Cadena en minusculas: %s\r\n",EquIn); 
                                        
   strCodificar(EquIn);                   // 2) REDUCIR ECUACION PARA OPTIMIZAR PROCESADO POSTERIOR

   printf("Cadena codificada: %s\r\n",EquIn);

   strPosFijar(EquIn,EquIn);              // 3) Pasar a notación PostFija

   printf("Cadena en notacion postfija: %s\r\n",EquIn);

   //cut unuseful zones...
   //if(graph.minX<graph.minViewX) graph.minX=graph.minViewX;
   //if(graph.maxX>graph.maxViewX) graph.maxX=graph.maxViewX;
   //if(graph.minY<graph.minViewY) graph.minY=graph.minViewY;
   //if(graph.maxY>graph.maxViewY) graph.maxY=graph.maxViewY;

/*
//Ejes!
   varx=0.0;
   varz=0.0;
   for(vary=0.0;Xp>=0;vary+=0.4){
      Xp = RAIZ2SOBRE2 * (varX - varY) + CentroX;
      Yp = -(RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY)) + CentroY;
      GLCD_pixel((int8)Xp,(int8)Yp,1);
   }

   vary=0.0;
   varz=0.0;
   for(varx=0.0;Xp<Radius+CentroX;varx+=0.4){
      Xp = RAIZ2SOBRE2 * (varX - varY) + CentroX;
      Yp = -(RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY)) + CentroY;
      GLCD_pixel((int8)Xp,(int8)Yp,1);
   }

   varx=0.0;
   vary=0.0;
   for(varz=0.0;Yp>0;varz+=1.0){
      Xp = RAIZ2SOBRE2 * (varX - varY) + CentroX;
      Yp = -(RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY)) + CentroY;
      GLCD_pixel((int8)Xp,(int8)Yp,1);
   }
*/


/*
//2D:
for(varX=graph.minX;varX<graph.maxX;varX+=0.1){
   fltPtr=strEvaluar(EquIn,StackNum,&varX,NULL,NULL);
   printf("X: %f Y: %f\r\n",varX,*fltPtr);

   Xp=varX+graph.centerX;
   Yp=graph.centerY-(*fltPtr);

   //ensure that pixel belongs to actual graph section...else do not show it!(out of bounds)
   if(Xp>=graph.x1 && Xp<=graph.x2 && Yp>=graph.y1 && Yp<=graph.y2) GLCD_pixel((int8)Xp,(int8)Yp,1);
}

printf("HECHO!\r\n");
while(1);
*/

//Proyeccion Isométrica...
   for(varY=graph.minY;varY<graph.maxY;varY+=incY){
      for(varX=graph.minX;varX<graph.maxX;varX+=incX){
         //indicate no error...
         errno=0;
         fltPtr=strEvaluar(EquIn,StackNum,&varX,&varY,NULL);
         //if errors during calculating...do not bother at all..
         if(errno) continue;
         
         //calculate isometric proyection
         varZ = *fltPtr;
         Xp = RAIZ2SOBRE2 * (varX - varY);
         Yp = (RAIZ2TERCIOS * varZ - UNOSOBRERAIZ6 * (varX + varY));
            
         //ensure that values are inside drawing zone...
         if(Xp>=graph.minViewX && Xp<=graph.maxViewX && Yp>=graph.minViewY && Yp<=graph.maxViewY){
            //printf("X: %f Y: %f Z: %f\r\n",varX,varY,varZ);
         
            //now let´s ubicate them inside actual graphic bounds...
            Xp=(Xp-graph.minViewX)*(float32)(graph.x2-graph.x1)/(graph.maxViewX-graph.minViewX)+(float32)graph.x1;
            Yp=(float32)graph.y2-((Yp-graph.minViewY)*(float32)(graph.y2-graph.y1)/(graph.maxViewY-graph.minViewY))+(float32)graph.y1; 

            //printf("XP: %f YP: %f\r\n",Xp,Yp);
            if(Xp>=graph.x1 && Xp<=graph.x2 && Yp>=graph.y1 && Yp<=graph.y2) GLCD_pixel((int8)Xp,(int8)Yp,1);            
         }
      }
   }

   printf("Proceso de graficacion finalizado.\r\n");

/*
//polares
  for(varY=-PI/2;varY<PI/2;varY+=PI/63){
      for(varX=-PI;varX<PI;varX+=2*PI/31){
         fX=Radius*cos(varX)*cos(varY);
         fY=Radius*cos(varX)*sin(varY);
         fZ=Radius*sin(varX);

         Xp=Sqrt(2.0) / 2.0 * (fX - fY) * Distance + CentroX;
         Yp = (Sqrt(2.0 / 3.0) * fZ - (1.0 / Sqrt(6.0)) * (fX + fY)) * Distance + CentroY;
         GLCD_pixel((int8)Xp,(int8)Yp,1);
       //printf("Xp: %f Yp: %f\r\n",Xp,Yp);
      }
  }
*/  
  
 //printf("EL resultado de la ecuacion es: %9f\r\n",*fltPtr);
   while(1);
}
Пример #26
0
void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   //port_b_pullups(TRUE);
   set_timer0(131);
   // TODO: USER CODE!!

andares[0] = 0;
andares[1] = 0;
andares[2] = 0;
andares[3] = 0;
sinal = 0;

   set_tris_a(0x00); //saída de dados
   set_tris_b(0xfe); //entrada de dados,menos bit 0
   set_tris_c(0xbf); //saída de dados, menos bit 6
   
   while(TRUE){
    conta = 0;
    
         if(andares[0] != 0){
            if(andares[0] == 1) TMP1 = 0; 
            if(andares[0] == 2) TMP1 = 100;
            if(andares[0] == 3) TMP1 = 200;
            if(andares[0] == 4) TMP1 = 300;
            
          if(TMP2 < TMP1) motor_passo_frente(TMP1-TMP2);
          else motor_passo_tras(TMP2-TMP1);
     
          conta = 0;
          sinal = 1;
          parar_motor_passo();
          printf("Você está no andar %d",andares[0]);
          tira_andar(andares);
          while(conta != 125);
          sinal = 0;

         }else{
          parar_motor_passo();
          sinal = 1;
        }

    TMP2 = TMP1;
     
    if(!parada){
    while(!parada){
    delay_ms(30);
    parou = 1;
    }
    }

       if(parou){
           printf("Opa!parada de emergência");
           sinal = 0; 
           
       TMP2 = TMP1;
   
            do{
            parar_motor_passo();
            
            if(!parada){
            while(!parada){
            delay_ms(30);
            parou = 0;
            }
            }while(!parou);
            printf("Prosseguindo...");
            sinal = 1;
        }    

        if(!andar1 || !andar2 || !andar3 || !andar4){
          while(!andar1 || !andar2 || !andar3 || !andar4){
            delay_ms(30);
            if(!andar1) botao = 1; 
            if(!andar2) botao = 2;
            if(!andar3) botao = 3;
            if(!andar4) botao = 4;
            insere_andar(andares,i);
            ordena(andares);
          }
        }

debug();
         
               
   }

}

}
Пример #27
0
void main( void )
{
    unsigned char stateSem1 = vermelho;
    unsigned char stateSem2 = verde;
    unsigned char cntTimeSem1 = 0;
    unsigned char cntTimeSem2 = 0;
    unsigned char flgEnableSem1 = 0;
    unsigned char flgEnableSem2 = 0;
    setup_adc_ports( NO_ANALOGS );
    setup_adc( ADC_OFF );
    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 );
    set_tris_c( 0x00 );
    //Inicializando os semáforos no estado conhecido.
    output_high( vermSem1 );
    output_high( verdeSem2 );

    while( 1 )
    {
        //máquina de estados do semáforo 1.
        switch( stateSem1 )
        {
        case vermelho:

            //Quando estiver no vermelho, se o flgEnableSem1 for verdadeiro, conto dois segundos antes de comutar para o estado verde.
            if( flgEnableSem1 == 1 )
            {
                cntTimeSem1++;

                if( cntTimeSem1 > 2 )
                {
                    cntTimeSem1 = 0;
                    stateSem1 = verde;
                    flgEnableSem1 = 0;
                    output_low( vermSem1 );
                    output_low( amarSem1 );
                    output_high( verdeSem1 );
                }
            }

            break;

        case amarelo:
            //Quando estiver no amarelo, conto 5 segundos antes de comutar para o vermelho. Observando que o estado amarelo de Sem1 habilita o flgEnableSem2, propiciando a
            //passagem de vermelho pra verde do semáforo2.
            cntTimeSem1++;

            if( cntTimeSem1 > 5 )
            {
                flgEnableSem2 = 1;
                stateSem1 = vermelho;
                cntTimeSem1 = 0;
                output_high( vermSem1 );
                output_low( amarSem1 );
                output_low( verdeSem1 );
            }

            break;

        case verde:
            //Quanto estiver no verde, aguardo 30 segundos antes e mudar para o vermelho.
            cntTimeSem1++;

            if( cntTimeSem1 > 30 )
            {
                cntTimeSem1 = 0;
                stateSem1 = amarelo;
                output_low( vermSem1 );
                output_high( amarSem1 );
                output_low( verdeSem1 );
            }

            break;
        }

        //máquina de estados do sem2
        switch( stateSem2 )
        {
            //Quando estiver no vermelho, se o flgEnableSem2 for verdadeiro, conto dois segundos antes de comutar para o estado verde.
        case vermelho:
            if( flgEnableSem2 == 1 )
            {
                cntTimeSem2++;

                if( cntTimeSem2 > 2 )
                {
                    stateSem2 = verde;
                    cntTimeSem2 = 0;
                    flgEnableSem2 = 0;
                    output_low( vermSem2 );
                    output_low( amarSem2 );
                    output_high( verdeSem2 );
                }
            }

            break;

        case amarelo:
            //Quando estiver no amarelo, conto 5 segundos antes de comutar para o vermelho. Observando que o estado amarelo de Sem1 habilita o flgEnableSem1, propiciando a
            //passagem de vermelho pra verde do semáforo1.
            cntTimeSem2++;

            if ( cntTimeSem2  > 5 )
            {
                cntTimeSem2 = 0;
                flgEnableSem1 = 1;
                stateSem2 = vermelho;
                output_high( vermSem2 );
                output_low( amarSem2 );
                output_low( verdeSem2 );
            }

            break;

        case verde:
            //Quanto estiver no verde, aguardo 30 segundos antes e mudar para o vermelho.
            cntTimeSem2++;

            if ( cntTimeSem2 > 30 )
            {
                cntTimeSem2 = 0;
                stateSem2 = amarelo;
                output_low( vermSem2 );
                output_high( amarSem2 );
                output_low( verdeSem2 );
            }

            break;
        }

        //Loop do programa será de 1segundo, que é a unidade mínima de contagem de tempo.
        delay_ms( 1000 );
    }
}
Пример #28
0
void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   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_TIMER0);
   enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   set_tris_a(0b00000011);
   set_tris_b(0b00000000);
   set_tris_c(0b10110011);
   set_tris_d(0b11110000);
   set_tris_e(0b00000100);
   
   while(1)
   {
  
      // waits for B1 to go high
      while ( !input(PIN_B1) )
      {}




   
      //PE-
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //tit
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //pa-
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //pa
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Noe-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //el
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Quand
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tu
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //Des-
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //cen-
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //dras
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //du
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //ciel
      playSound(NOTE_MI4,TEMPS_BLANCHE);
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //A-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //vec
      playSound(NOTE_DO4,TEMPS_NOIRE);
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tes
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //jou-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //ets
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //par
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //mi-
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //liers
      playSound(NOTE_SOL3,TEMPS_BLANCHE);
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //N'ou-
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //blie
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //pas
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      delay_us(WAIT);
      //mon
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //pet-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tit
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //pa-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //nier
      playSound(NOTE_RE4,TEMPS_BLANCHE);
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Mais
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //a-
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //vant
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //de
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //par-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //tir
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //il
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //fau-
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //dra
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //bien
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //te
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //cou-
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //vrir
      playSound(NOTE_MI4,TEMPS_BLANCHE);
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //De-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //hors
      playSound(NOTE_DO4,TEMPS_NOIRE);
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //il
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //fait
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //dé-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //jà
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //bien
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //froid
      playSound(NOTE_SOL3,TEMPS_BLANCHE);
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //C'est
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //un
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //peu
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      delay_us(WAIT);
      //a
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //cau-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //se
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //de
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //Moi
      playSound(NOTE_DO4,TEMPS_RONDE);
      delay_us(WAIT);
      //--------------------------------
      //Il
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //me
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //tar-
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //de
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //tant
      playSound(NOTE_LA3,TEMPS_NOIRE);
      delay_us(WAIT);
      //que
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //le
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //jour
      playSound(NOTE_DO4,TEMPS_NOIRE);
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //se
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //lè-
      playSound(NOTE_LA3,TEMPS_NOIRE);
      delay_us(WAIT);
      //ve
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //Pour
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //voir
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //si
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tu
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //m'as
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //ap-
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //por-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //té
      playSound(NOTE_RE4,TEMPS_RONDE);
      delay_us(WAIT);
      //--------------------------------
      //tous
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //les
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //beaux
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //jou-
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //joux
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //que
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //je
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //vois
      playSound(NOTE_FA4,TEMPS_NOIRE);
      playSound(NOTE_FA4,TEMPS_CROCHE);
      delay_us(WAIT);
      //en
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //re-
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //ve
      playSound(NOTE_SI3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //et
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //que
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //je
      playSound(NOTE_MI4,TEMPS_CROCHE);
      delay_us(WAIT);
      //t'ai
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //com-
      playSound(NOTE_FA4,TEMPS_CROCHE);
      delay_us(WAIT);
      //man-
      playSound(NOTE_FA4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //de
      playSound(NOTE_SOL4,TEMPS_BLANCHE);
      playSound(NOTE_SOL4,TEMPS_BLANCHE);
      delay_us(WAIT);
       //PE-
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //tit
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //pa-
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //pa
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Noe-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //el
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Quand
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tu
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //Des-
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //cen-
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //dras
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //du
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //ciel
      playSound(NOTE_MI4,TEMPS_BLANCHE);
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //A-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //vec
      playSound(NOTE_DO4,TEMPS_NOIRE);
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tes
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //jou-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //ets
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //par
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //mi-
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //liers
      playSound(NOTE_SOL3,TEMPS_BLANCHE);
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //N'ou-
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //blie
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //pas
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      delay_us(WAIT);
      //mon
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //pet-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //tit
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //pa-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //nier
      playSound(NOTE_RE4,TEMPS_BLANCHE);
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //Mais
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //a-
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //vant
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //de
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //par-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //tir
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      //il
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //fau-
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //dra
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //bien
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //te
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //cou-
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //vrir
      playSound(NOTE_MI4,TEMPS_BLANCHE);
      playSound(NOTE_MI4,TEMPS_NOIRE);
      delay_us(WAIT);
      //De-
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      //hors
      playSound(NOTE_DO4,TEMPS_NOIRE);
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //il
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //fait
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //dé-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //jà
      playSound(NOTE_SI3,TEMPS_CROCHE);
      delay_us(WAIT);
      //bien
      playSound(NOTE_LA3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //froid
      playSound(NOTE_SOL3,TEMPS_BLANCHE);
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //C'est
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //un
      playSound(NOTE_SOL3,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //peu
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      delay_us(WAIT);
      //a
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //cau-
      playSound(NOTE_DO4,TEMPS_CROCHE);
      delay_us(WAIT);
      //se
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //de
      playSound(NOTE_RE4,TEMPS_CROCHE);
      delay_us(WAIT);
      //--------------------------------
      //Moi
      playSound(NOTE_DO4,TEMPS_BLANCHE);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      
      playSound(NOTE_SOL3,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      playSound(NOTE_LA3,TEMPS_NOIRE);
      delay_us(WAIT);
      playSound(NOTE_DO4,TEMPS_NOIRE);
      delay_us(WAIT);
      playSound(NOTE_RE4,TEMPS_NOIRE);
      delay_us(WAIT);
      playSound(NOTE_FA4,TEMPS_NOIRE);
      delay_us(WAIT);
      //--------------------------------
      playSound(NOTE_SOL4,TEMPS_RONDE);
      delay_us(WAIT);
   }
   
   
   
}
Пример #29
0
void main()
{
    setup_adc_ports(NO_ANALOGS);
    setup_adc(ADC_CLOCK_DIV_2);
    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_DIV_BY_16,155,1);
    setup_ccp1(CCP_PWM);
    setup_ccp2(CCP_PWM);
    set_pwm1_duty(312); // Inicia el Ciclo de Trabajo PWM1 en 50%.
    set_pwm2_duty(312); // Inicia el Ciclo de Trabajo PWM2 en 50%.
    setup_comparator(NC_NC_NC_NC);
    setup_vref(FALSE);

    set_tris_a(0b11100000); // 
    set_tris_c(0b10000000); //Pone RC7 como input y RC6 como output (y de 5 a 0 también)
    set_tris_b(0b00000000); // Habilita como salidas los pines B0, B1,...,B7
    set_tris_e(0b010);



    // ************************ CONFIGURACIÓN PWM1 y PWM2: ************************
    int32 brillo=0;
    int32 exposicion=500;   //Tiempo de exposición de la cámara en [ms]
    int32 der_steps=0;
    int32 izq_steps=0;
    int32 led=0;
    int32 motor=0;
    int32 direccion=0;
    int32 pasos=0;
    int32 velocidad=0;
    char leido_pantalla[5];

    output_low(PIN_B0);
    output_low(PIN_B1);
    output_low(PIN_B2);
    output_low(PIN_B3);
    output_low(PIN_B4);
    output_high(PIN_B6); // Siempre en 5V para conectar pull up 10kOhm de RA4 para SLEEP MOTOR 3 (altura)

    set_pwm1_duty(0); // Mantiene Ciclos en 0 para reducir consumo al iniciar.
    set_pwm2_duty(0);

    //*************** INICIO ***************



    while(true)
    {

        char seleccionar=0;
        output_low(PIN_A2);
        output_low(PIN_A3);
        output_low(PIN_A4);


        printf("Set parameters: e=exposicion(%Ld), v=velocidad(%Ld)\n\r",exposicion,velocidad);
        printf("                b=brillo(%Ld), d=direccion(%Ld), p=pasos(%Ld)\n\r",brillo,direccion,pasos);
        printf("                l=led(%Ld), m=motores(%Ld) \n\r",led,motor);
        seleccionar=getc();

        switch(seleccionar)
        {

            case 'v':
                printf("Ingrese Velocidad en [ms] y [ENTER]\n\r");
                fgets(leido_pantalla);
                velocidad=atoi32(leido_pantalla);
                break;

            case 'e': 
                printf("Ingrese tiempo de exposicion en [ms] y [ENTER]\n\r");
                fgets(leido_pantalla);
                exposicion=atoi32(leido_pantalla);
                break;

            case 'b':
                printf("Ingrese Ciclo de Trabajo para PWM1 (0-100) (brillo) y [ENTER]:\n\r");
                fgets(leido_pantalla);
                brillo=atoi(leido_pantalla);
                set_pwm1_duty(brillo*20000000/(100*2000*16));
                set_pwm2_duty(brillo*20000000/(100*2000*16));
                break;

            case 'l':
                printf("Ingrese Led a encender: 0 a 7 y [ENTER]\n\r");
                fgets(leido_pantalla);
                led=atoi32(leido_pantalla);
                break;

            case 'd':
                printf("Ingrese direccion 1=Derecha, 0=Izquierda y [ENTER]\n\r");
                fgets(leido_pantalla);
                direccion = atoi32(leido_pantalla);               
                break;

            case 'p':
                printf("Ingrese el numero de pasos a utlizar y [ENTER]\n\r");
                fgets(leido_pantalla);
                pasos = atoi32(leido_pantalla);               
                break;

            case 'm':
                printf("Ingrese el numero de motor a utlizar: 1,2 o 3 y [ENTER]\n\r");
                fgets(leido_pantalla);
                motor = atoi32(leido_pantalla);               
                break;

            case '1':
                led_on(led);
                break;

            case '2':
                led_off();
                break;

            case '3':
                motor_move(motor,pasos,direccion);
                break;

            case '4':
                led_on_off(led,exposicion);
                break;

            case '5': 
                int32 pasos_restantes;
                int32 steps;
                int dir;
                dir = direccion;
                steps = pasos;
                pasos_restantes = pasos;
                motor_on(motor); 
                while(pasos_restantes > 0){
                    printf("pasos_restantes: %Ld\n\r",pasos_restantes);
                    delay_us(200);
                    steps = motores4(pasos_restantes,dir,velocidad);
                    pasos_restantes = pasos_restantes - steps;
                    if (pasos_restantes <=0)
                        break;
                    delay_us(200);
                    dir = (dir == 0)?1:0;
                    motores2(2000,dir);
                }
                break;

            case '6': 
                int32 pasos_restantes2;
                int32 steps2;
                int dir2;
                dir2 = direccion;
                steps2 = pasos;
                pasos_restantes2 = pasos;
                motor_on(motor); 
                while(true){
                    printf("pasos restantes: %Ld\n\r",pasos_restantes2);
                    delay_us(200);
                    steps2 = motores4(pasos_restantes2,dir2,velocidad);
                    delay_us(200);
                    dir2 = (dir2 == 0)?1:0;
                    motores2(2000,dir2);
                    pasos_restantes2 = pasos_restantes2 - steps2;
                    if (pasos_restantes2 <=0)
                        pasos_restantes2 = pasos;
                }
                break;

            case '7':
                int32 steps3; 
                motor_on(motor); 
                steps3 = motores4(pasos,direccion,velocidad);
                if (steps3 - pasos < 0){
                    direccion = (direccion == 0)?1:0;
                    motores2(2000,direccion);
                    delay_us(200);
                    motores3(2147483640,direccion);
                    direccion = (direccion == 0)?1:0;
                    motores2(2000,direccion);
                }
                break;

            case '8': 
                printf("Setup Calibracion Quick\n\r");
                motor_on(motor); 
                motores3(2147483640,DERECHA);
                delay_us(200);
                motores2(2000,IZQUIERDA);
                delay_us(200);
                izq_steps = motores3(2147483640,IZQUIERDA);
                delay_us(200);
                motores2(2000,DERECHA);
                delay_us(200);
                der_steps = motores3(2147483640,DERECHA);
                printf("izq_steps ->%Ld<-  \n\r",izq_steps);
                printf("der_steps ->%Ld<-  \n\r",der_steps);
                while(true){
                    motores2(izq_steps,IZQUIERDA);
                    delay_us(200);
                    motores2(der_steps,DERECHA);
                    delay_us(200);
                }

            case '9': 
                printf("Setup Velocidad ...\n\r");
                output_high(PIN_A4); 
                motores2(2000,IZQUIERDA);
                delay_us(200);
                izq_steps = motores3(2147483640,IZQUIERDA);
                delay_us(200);
                motores2(2000,DERECHA);
                delay_us(200);
                der_steps = motores3(2147483640,DERECHA);
                printf("izq_steps ->%Ld<-  \n\r",izq_steps);
                printf("der_steps ->%Ld<-  \n\r",der_steps);

                motores4(izq_steps,IZQUIERDA,velocidad);
                delay_us(200);
                motores4(der_steps,DERECHA,200);
                delay_us(200);
                break;

        }

    }



}  //FIN MAIN
Пример #30
0
void InitialChip(void)
{
   setup_comparator(NC_NC_NC_NC);   //Input Digital
   set_tris_b(0B00000000);
   set_tris_c(0B10000000);
}