void eaDogM_Initialize(void) { // v2.03 fix #if EADOGM_SPI_HW == 1 setup_spi(SPI_MASTER | SPI_H_TO_L | EADOGM_SPI_DIV); #endif // v2.03 fix #if EADOGM_SPI_HW == 2 setup_spi2(SPI_MASTER | SPI_H_TO_L | EADOGM_SPI_DIV); #endif #ifdef EADOGM_SPI_SW eaDogM_iniSPI_BB(); #endif #ifdef EADOGM_8BIT eaDogM_ini8Bit(); #else output_drive(EADOGM_PIN_CSB); output_drive(EADOGM_PIN_RS); output_high(EADOGM_PIN_CSB); output_high(EADOGM_PIN_RS); #endif delay_ms(200); eaDogM_WriteCommand(EADOGM_INIT_FS1); eaDogM_WriteCommand(EADOGM_INIT_BIAS_SET); eaDogM_WriteCommand(EADOGM_INIT_POWER_CONTROL); eaDogM_WriteCommand(EADOGM_INIT_FOLLOWER_CONTROL); eaDogM_WriteCommand(EADOGM_INIT_CONTRAST_SET); eaDogM_WriteCommand(EADOGM_INIT_FS2); eaDogM_WriteCommand(EADOGM_INIT_CLEAR_DISPLAY); eaDogM_WriteCommand(EADOGM_INIT_ENTRY_MODE); }
//***************************************************************************************** //***************************************************************************************** //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); }
void main() { disable_interrupts(GLOBAL); setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_spi2(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_4V096); setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0); // TIMER 0 is being used to service the WTD setup_timer_0(T0_INTERNAL|T0_DIV_256); /* sets the internal clock as source and prescale 256. At 10 Mhz timer0 will increment every 0.4us (Fosc*4) in this setup and overflows every 6.71 seconds. Timer0 defaults to 16-bit if RTCC_8_BIT is not used. Fosc = 10 MHz, Fosc/4 = 2.5 Mhz, div 256 = 0.0001024 s, 65536 increments = 6.71 sec Fosc = 64 MHz, Fosc/4 = 16 Mhz, div 256 = 0.000016 s, 65536 increments = 1.05 sec .. pre-load with 3036 to get exact 1.0000 sec value */ // TIMER 1 is used to extinguish the LED setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); /* sets the internal clock as source and prescale 4. At 10Mhz timer0 will increment every 0.4us in this setup and overflows every 104.8 ms. Timer1 is 16-bit. Fosc = 10 Mhz ... 2.5 MHz / div 4 = 0.00000160 s * 65536 = 0.104858 sec Fosc = 64 Mhz ... 16 MHz / div 4 = 0.00000025 s * 65536 = 0.016384 sec Fosc = 64 Mhz ... 16 MHz / div 8 = 0.00000200 s * 65536 = 0.032768 sec */ setup_stepper_pwm(); // Uses TIMER 2 // TIMER 3 is used for stepper motor intervals setup_timer_3(T3_INTERNAL | T3_DIV_BY_1); // 16 bit timer // TIMER 4 is use for serial time-outs. 8-bit timer. setup_timer_4(T4_DIV_BY_4, 127, 1); setup_comparator(NC_NC_NC_NC); setup_oscillator(OSC_16MHZ | OSC_PLL_ON); // Fosc = 64 MHz ext_int_edge(0, H_TO_L); // Set up PIC18 EXT0 enable_interrupts(INT_EXT); start_heartbeat(); enable_interrupts(GLOBAL); init_hardware(); motor_sleep_rdy(); sleep_mode = FALSE; busy_set(); init_nv_vars(); get_step_vars(); init_aws(); blink(); //Add for TCP/IP interface //delay_ms(15000); signon(); RTC_read(); RTC_last_power(); RTC_reset_HT(); RTC_read(); RTC_read_flags(); if(nv_sd_status>0) fprintf(COM_A,"@SD=%Lu\r\n", nv_sd_status); init_rtc(); // This is the FAT RTC sd_status = init_sdcard(); if(sd_status>0) msg_card_fail(); reset_event(); if(m_error[0] > 0 || m_error[1] > 0) msg_mer(); if (m_comp[0]==FALSE) { e_port[0]=0; write16(ADDR_E1_PORT,0); fprintf(COM_A, "@MC1,%Lu,%Ld\r\n", m_comp[0],e_port[0]); } if (m_comp[1]==FALSE) { m_lin_pos[1]=-1; write16(ADDR_M2_LIN_POS, -1); fprintf(COM_A, "@MC2,%Lu,%Ld\r\n", m_comp[1],m_lin_pos[1]); } if (nv_cmd_mode == FALSE){ for(dt=0; dt<100; ++dt){ blip(); if (nv_cmd_mode == TRUE) { busy_clear(); fputs("@OK!", COM_A); command_prompt(); dt = 100; } } } else command_prompt(); user_quit = auto_sample_ready(); reset_cpu(); }
void hmr_spi2_initialize(void){ setup_spi2(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_64|SPI_CLK_DIV2_5);//MASTER, L to H(共通), クロック100Kbps位 }