Esempio n. 1
0
void_isr(void)
   {
   itr += 1;
   if (itr==1){
output_b(num[d1]);
output_c(0);
output_c(1);
}
if (itr==2){
output_b(num[d2]);
output_c(0);
output_c(2);
}
if (itr==3){
output_b(num[d3]);
output_c(0);
output_c(4);
}
if (itr==4){
output_b(num[d4]);
output_c(0);
output_c(8);
itr=0;
con+=1;
}
   
   }
Esempio n. 2
0
void main()
{

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

   // TODO: USER CODE!!
   
      set_adc_channel(0);            // set ref valus
      delay_ms(100);
      ref_0 =read_adc();
      delay_ms(100);
      
      set_adc_channel(3);            // set ref valus
      delay_ms(100);
      ref_3 =read_adc();
      delay_ms(100);
   
   output_b(0b11111111);
   delay_ms(700);
   output_b(0);
   
   while(1){
      set_adc_channel(0);
      delay_ms(20);                        // take readings
      adc_val_0 =read_adc();
      delay_ms(20);
      if(adc_val_0 > ref_0+cons){
         l_0 =1;
         output_high(pin_d7);
         delay_ms(500);
      }
      else{
         l_0=0;
         output_low(pin_d7);
     //    delay_ms(500);
      }
      
      set_adc_channel(3);
      delay_ms(20);                        // take readings
      adc_val_3 =read_adc();
      delay_ms(20);
      if(adc_val_3> ref_3+cons){
         l_3 =1;
         output_high(pin_d6);
         delay_ms(500);
      }
      else{
         l_3=0;
         output_low(pin_d6);
      }
   }
}
Esempio n. 3
0
void main (){
   set_TRIS_b(0x00);   //Puerto D en salida.
   output_b(0x00);     //Inicia puerto D en 0 para evitar valores basura.
do {
//Enciende PIN_D0
   output_b(0x01);
   delay_ms(1000);   //Retardo de 1s.
//Enciende PIN_D1
   output_b(0x02);
   delay_ms(1000);   //Retardo de 1s.
//Enciende PIN_D2
   output_b(0x04);
   delay_ms(1000);   //Retardo de 1s.
//Enciende PIN_D3
   output_b(0x08);
   delay_ms(1000);   //Retardo de 1s.
//Enciende PIN_D4
   output_b(0x10);
   delay_ms(1000);   //Retardo de 1s.
//Enciende PIN_D5
   output_b(0x20);
   delay_ms(1000);   //Retardo de 1s.
//Enciende PIN_D6
   output_b(0x40);
   delay_ms(1000);   //Retardo de 1s.
//Enciende PIN_D7
   output_b(0x80);
   delay_ms(1000);   //Retardo de 1s.
//Reinicio
   output_b(0x00);
   delay_ms(1000);
}

while(TRUE);
}
Esempio n. 4
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);
}            
Esempio n. 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);
}
Esempio n. 6
0
void update_field ()
{
    output_a (0);
    output_b (field);
    if (dir_left)
        field <<= 1;
    else
        field >>= 1;
    if (!field) {
        dir_left = !dir_left;
        if (dir_left) {
            field = 1;
            if (input (BTN_A))
                score (LED_A);
        }
        else {
            field = 0x80;
            if (input (BTN_B))
                score (LED_B);
        }
    }
    else {
        if (!input (BTN_A))
            score (LED_B);
        if (!input (BTN_B))
            score (LED_A);
    }
}
Esempio n. 7
0
void HW_Init(){
    output_b(0x01);
    cmd.modulId=0;
    cmd.ledId=0;
    cmd.activ=0;
    cmd.ready=false;
}
Esempio n. 8
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]);
   }
}
Esempio n. 9
0
void init_device ()
{
    set_tris_a (0x18);          /* 0b11000 */
    set_tris_b (0);

    output_b (0);
    output_a (0);

    out_of_game = 1;

    output_high (LED_OUT);
}
Esempio n. 10
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;             
}
Esempio n. 11
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);
}
Esempio n. 12
0
void main() {
   
   setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
   set_tris_b(0x00);                
   output_b(0x00);
   LED_ON(LEDR);
   LED_OFF(LEDV); 
   usb_init();                      
   usb_task();   //Monitorea el estado de la coneccion conectandose y desconectandose automaticamente
   usb_wait_for_enumeration();  //espera infinitamente hasta que el dispositivo fue enumerado    
   LED_ON(LEDV);
   LED_OFF(LEDR); 
   
   while (TRUE) 
   {
      usb_task();
      if (usb_enumerated()) 
      {
        
            Salida[0]=read_adc();
            usb_put_packet(1, Salida, 1, USB_DTS_TOGGLE);

         if (usb_kbhit(1)) 
         {
         
           usb_get_packet(1, Entrada, 1);
           if (Entrada[0]==1)
            {      
             LED_ON(PIN_B0);
              
            }

            else 
            LED_OFF(PIN_B0);

         }
         
      }
   }
   }
Esempio n. 13
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;
}

}

}
Esempio n. 14
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;
   
}
Esempio n. 15
0
void main(void)
{   
  
   set_tris_a(0b11110000);    //  PROBAR SACAR ESTOO
   set_tris_b(0b11111111);
   
   // PORT_B_PULLUPS(0b00000000);    //  PROBAR SACAR ESTOO
   
   output_a(0b00000000);
   output_b(0b00000000);
     
   OUTPUT_HIGH(LED_APAGADO);
   
   if(!INPUT(MODO))
      delay=1;   
   
   while(!delay){  // MODO DEPURACION
   
      OUTPUT_HIGH(CONTACTOR);
      
      if(INPUT(START)&&(!encendido))
      {
         encendido=1;
         OUTPUT_HIGH(SENNAL_ENCENDIDO);
         OUTPUT_LOW(LED_APAGADO);
         OUTPUT_HIGH(LED_ENCENDIDO);
         delay_ms(200);         
         OUTPUT_LOW(SENNAL_ENCENDIDO);
         OUTPUT_HIGH(NEON);
      }      
      
      if(INPUT(STOP)&&(encendido))
      {
         encendido=0;
         OUTPUT_HIGH(SENNAL_APAGADO);
         OUTPUT_LOW(LED_ENCENDIDO);
         OUTPUT_HIGH(LED_APAGADO);
         delay_ms(200);         
         OUTPUT_LOW(SENNAL_APAGADO);
         OUTPUT_LOW(NEON);
      }
      
      
      if(INPUT(ERROR)&&(encendido))   // LIMPIA LOS ERRORES
      {
         encendido=0;
         OUTPUT_LOW(LED_ENCENDIDO);
         OUTPUT_HIGH(LED_APAGADO);
         OUTPUT_LOW(NEON);
      }
   
   }   // MODO DEPURACION
   
   while(delay)  //  MODO NORMAL
   {  
      
      if(INPUT(START)&&(!encendido))
      {
         encendido=1;
         delay_ms(50);
         OUTPUT_HIGH(CONTACTOR);
         OUTPUT_LOW(LED_APAGADO);
         
         for (int i = 0; i < 10; i++){
            OUTPUT_HIGH(LED_ENCENDIDO);
            delay_ms(200);
            OUTPUT_LOW(LED_ENCENDIDO);
            delay_ms(200);

         }
         
         OUTPUT_HIGH(LED_ENCENDIDO);
         
         OUTPUT_HIGH(SENNAL_ENCENDIDO);
         delay_ms(200);
         OUTPUT_LOW(SENNAL_ENCENDIDO);
         
         OUTPUT_HIGH(NEON);
         
      }  
      
      
      if(INPUT(STOP)&&(encendido))
      {
         encendido=0;
         delay_ms(50);
         OUTPUT_HIGH(SENNAL_APAGADO);
         OUTPUT_LOW(LED_ENCENDIDO);
         
         delay_ms(200);
         OUTPUT_LOW(SENNAL_APAGADO);
         
         OUTPUT_LOW(NEON);
         
         delay_ms(200);
         OUTPUT_LOW(CONTACTOR);
                 
         for (int i = 0; i < 10; i++){
            OUTPUT_HIGH(LED_APAGADO);
            OUTPUT_HIGH(NEON);
            delay_ms(200);
            OUTPUT_LOW(LED_APAGADO);
            OUTPUT_LOW(NEON);
            delay_ms(200);
            if (i==2){
               OUTPUT_HIGH(SENNAL_ENCENDIDO);
               delay_ms(200);
               OUTPUT_LOW(SENNAL_ENCENDIDO);
            }
            else
               OUTPUT_LOW(SENNAL_ENCENDIDO);

         }
         OUTPUT_HIGH(SENNAL_APAGADO);        
         delay_ms(200);
         OUTPUT_LOW(SENNAL_APAGADO);
         /*OUTPUT_HIGH(SENNAL_ENCENDIDO);
         delay_ms(500);
         OUTPUT_LOW(SENNAL_ENCENDIDO);*/
         delay_ms(20);
         OUTPUT_HIGH(LED_APAGADO);         
         
         OUTPUT_LOW(NEON);

      }
      
      if(INPUT(ERROR)&&(encendido))   // LIMPIA LOS ERRORES
      {
         encendido=0;
         OUTPUT_LOW(LED_ENCENDIDO);
         OUTPUT_HIGH(LED_APAGADO);
         OUTPUT_LOW(NEON);
      }   

   }   // MODO NORMAL 
   
}  // FUNCION PRINCIPAL
Esempio n. 16
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);
}
Esempio n. 17
0
void setup(){
	//OPTION=0b00000010;
	/* 0 PBPU プルアップを使用する。
	 * 0 INTEDG 立下りエッジを検出し割り込む
	 * 0 TMR0clocksource 内部クロック
	 * 0 TMR0のインクリメントタイミング
	 * 0 ぷりすけーらーをTMR0に使う。
	 * 010 0.8192ms 1/8
	   001 0.4096ms 1/16
	 */
	setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
	 	
	 //INTCON=0b10101000;
	/* 1 GIE
	 * 0 EE  INT EN
	 * 1 TM0 INT EN
	 * 0 INT INT EN
	 * 1 RB  INT EN
	 * 0 TM0 INT FLAG
	 * 0 INT INT FLAG
	 * 0 RB  INT FLAG
	 */
	 	
	 set_tris_A(0b00010000);
	 //TRISA=0b00010000;
	/* 0 予約
	 * 0 予約
	 * 0 予約
	 * 1 
	 * 0 17 U3 IN1
	 * 0 18 U3 IN2
	 * 0 02 U2 IN2
	 * 0 01 U2 IN1
	 */
	 //PORTA=0;
	 output_a(0);

	 set_tris_B(0b11111111);
	 //TRISB=0b11111111;
	/* 1 13 ラインセンサ
	 * 1 12 ラインセンサ
	 * 1 11 ラインセンサ
	 * 1 
	 * 1 
	 * 1 
	 * 1 
	 * 1 
	 */
	 //PORTB=0;
	output_b(0);
	
	enable_interrupts(INT_TIMER0);
	enable_interrupts(GLOBAL);





/*temp aaa
	 CLRWDT();
	 TMR0=0;
	 T0IE=0;
	 T0IF=0;

}
	
void TmWait(void){
	while(!T0IF);
	T0IF = 0;
}
aaa temp*/
}
Esempio n. 18
0
	void loop (int xStepsTobe, int yStepsTobe){

	        signed int yToDo = yStepsTobe - yStep;
	        signed int xToDo = xStepsTobe - xStep;

	        int yDir = 1;   if (yToDo < 0)   yDir = -1;              //Assigning a value to know what direction to move the motors
	        int xDir = 1;   if (xToDo < 0)   xDir = -1;              //Using the nested if statment. 

	        
	        int hToDo;
	        int lToDo;

	        signed int *hStep_ptr;
	        signed int *lStep_ptr;

	        int hDir;
	        int lDir;

	        char hSft;
	        char lSft;

			// setting values and exception cases
				if (yToDo == 0 && xToDo == 0){                          // This is to prevent goinginto the loop if no movement happens. To stop in crashing inside the loop. 
		        	printf("ERORO: You told me to go noWHERE\r\n");
		        return;}

		        if (abs(yToDo)>abs(xToDo)){                             // This is where ALT is larger ALT is Y 
		            
		            hToDo = abs(yToDo);
		            lToDo = abs(xToDo);

		            hStep_ptr = &yStep;
		            lStep_ptr = &xStep;

		            hDir = yDir;
		            lDir = xDir;  

		            hSft = 0;
		            lSft = 4;
		        }

		        else if (abs(xToDo)>abs(yToDo)){                        // This is where AZ is larger AZ is X 
		            
		            hToDo = abs(xToDo);
		            lToDo = abs(yToDo);

		            hStep_ptr = &xStep;
		            lStep_ptr = &yStep;

		            hDir = xDir;
		            lDir = yDir; 

		            hSft = 4;
		            lSft = 0;
		        }

		        else                                                    // intended for the cases where the x and y change values are the same so we run both at once
		            while (abs(yToDo) > 0){
		                yToDo = abs(yToDo);
		                xToDo = abs(xToDo);
		                output_b(HalfStep[yStep&0x7]<<4|HalfStep[xStep&0x7]);
		                delay_ms (d);
		                yToDo --;
		                xToDo --;
		                xStep += xDir;
		                yStep += yDir;
		                output_b(0x000);
		            }
/*		            
		        if (xStep == 0 || yStep == 0){                          // If one motor moves and the other does not, to avoid devision by 0    
		            printf("in the one move fore loop\n\r");
		            yToDo = abs(yToDo);
		            xToDo = abs(xToDo);
		            
		            while (hToDo > 0){
		                output_b(HalfStep[*hStep_ptr&0x7]<<lSft);
		                *hStep_ptr+=hDir;
		                hToDo--;
		                delay_ms(d);
		            }
		            
		            output_b(0x000);
		        // }*/
//
        ///////////////////////// Main Stepper Code Loop ///////////////////////////
	

///////// stepper loop
        while (hToDo>lToDo){
            
            int mod = (int) hToDo/(hToDo%lToDo);          
				printf("mod: 0 = %d\n",mod);
            
            // Mod array building 
			int lStep_ary[10];
			lStep_ary[0]= hToDo/lToDo;
				printf("A#: 0 = %d\n",lStep_ary[0]);
			
			// Populating the rest of the array
			int m = lToDo;
			for (int i = 1; hToDo%m != 0; i++){				
				//printf("inthe loop\n");
				m = hToDo%m;
				printf("m = %d\n",m);
				lStep_ary[i]=(int)(hToDo/m)+1;// this +1 is used to tweek how it behaves
					printf("A#: %d = %d\n",i,lStep_ary[i]);
			}
			/// steper while loop
            	printf("Starting the while\n");
            while ( lToDo > 0 ){
                for ( unsigned int i = /*lStep_ary[0]*/ (int)((hToDo/(lToDo))+0.5); i > 0; i--){// the divison vs the initial array point for tweeking
                    output_b(HalfStep[*hStep_ptr&0x7]<<lSft);
                    *hStep_ptr+=hDir;
                    hToDo--;
                    delay_ms(d);
                    	//printf("fast\n");
                    for (int e = 1; e < 10; e++){
                    	//printf("firstif\n");
	                    if ( lStep_ary[e] != 0 && hToDo%lToDo != 0 && hToDo%lStep_ary[e] == 0 ){
		                    //printf("Extra\n");
		                    i++;	
	                    }
	                    break;
	                }
                }
	                //printf("Slow itteration\n");
	                
	                
                output_b(HalfStep[*lStep_ptr&0x7]<<hSft); //| HalfStep[yStep&0x7]<<lSft);
                    
                *lStep_ptr+=lDir;
                lToDo--;
                delay_ms(d);
                printf("%d,%d\r\n", lToDo, hToDo);
            }

            output_b(0x000);
        }

    }
Esempio n. 19
0
void c64_bn1541_device::parallel_strobe_w(int state)
{
	if (LOG) logerror("1541 parallel strobe %u\n", state);

	output_b(state);
}