void initialisation(void) { //ADC Off ADCON0bits.ADON = 0; ADCON1 = 0b00001111; //Définition des IO define_i_o(); //Périphériques // init_timer_0(); config_port_b(); init_i2c(); init_eusart(); //config_euart(); //Init GLCD GLCD_Initalize(); Delay10KTCYx(0); //Modifier? GLCD_ClearScreen(); // On autorise toutes les interruptions RCONbits.IPEN = 0; //1 niveau INTCONbits.GIE = 1; INTCONbits.PEIE = 1; }
int main(void) { hours_tens = 1; hours_ones = 3; minutes_tens = 3; minutes_ones = 6; seconds_tens = 4; seconds_ones = 9; GLCD_Initalize(); GLCD_ClearScreen(); /*//Draw the Hackaday Logo: GLCD_GoTo(0,0); for (unsigned char j=0; j<8; j++) { GLCD_GoTo(0,j); for (unsigned char i=0; i<64; i++) { GLCD_WriteData(skull[i+(j*64)]); } } */ while(1) { //FIXME: Optimize so we don't redraw the entire screen every second. ShowBigTime(hours_tens, hours_ones, minutes_tens, minutes_ones); GLCD_GoTo(0,7); //Easter Egg: if ((hours_tens == 1) && (hours_ones == 3) && (minutes_tens == 3) && (minutes_ones == 7)) { //Display Hackaday URL when time is 13:37 GLCD_WriteString(" http://hackaday.com "); } else { //Display Day, Date, and Seconds GLCD_WriteString("Tuesday 12/3/2013 "); GLCD_WriteChar(seconds_tens+48); //ASCII offset GLCD_WriteChar(seconds_ones+48); //ASCII offset } IncSecond(); //FIXME: This should be a hardware timer for accuracy //FIXME: This should use an RTC for accuracy Delay_ms(1000); } }
void config(void) { //Define inputs/outputs define_io(); //Assignation des périphériques peripheral_pin_select(); //Config peripherals: setup_usart1(); //PC/GPS setup_usart2(); //Radio setup_timer1(); //10ms timebase setup_adc(); //ADC //Encoder interrupts: _INT0IF = 0; _INT1IF = 0; _INT0IE = 1; _INT1IE = 1; //Disable unwanted interrupts: _U1TXIE = 0; _U2TXIE = 0; _SPI1IE = 0; _SPI1IF = 0; _T3IE = 0; _T2IE = 0; _OC2IE = 0; _IC1IE = 0; _OC1IE = 0; _IC1IE = 0; _U1ERIE = 0; _U2ERIE = 0; _PMPIE = 0; #ifdef USE_GLCD //Init GLCD GLCD_Initalize(); GLCD_ClearScreen(); #endif }
int main(void) { BL_OUTPUT; // DS_OUTPUT; BL_ON; GLCD_Initalize(); // Initalize LCD GLCD_ClearText(); // Clear text area GLCD_ClearCG(); // Clear character generator area GLCD_ClearGraphic(); // Clear graphic area GLCD_TextGoTo(0,0);// set text coordinates GLCD_WriteString("Hello"); // write text GLCD_Circle(32,32,20); // draw circle GLCD_Rectangle(8,8,24, 48); // draw rectangle // GLCD_FillRectangle(0, 0, 96, 8); USART_Init(MYUBRR); USART_Transmit_string("Hi\n"); LED_OUTPUT; BLINK3; GLCD_ClearText(); GLCD_TextGoTo(0,0);// set text coordinates ADCSRA = 0b10000111; data_flag=0; sei(); uint16_t T = 0; uint8_t i; while(1) { if (data_flag == 1) { //BLINK00; // Heh nasty error when it is here, if 'g' followed by newline comes, because it rewrites data here :D if (data == 't') { T = DS_get(6); GLCD_TextGoTo(0,0); i = (uint8_t)(T>>8); USART_Transmit_num(i); GLCD_WriteChar(i/10 + '0'); GLCD_WriteChar(i%10 + '0'); USART_Transmit('.'); GLCD_WriteChar('.'); i = (uint8_t)(T); USART_Transmit_num(i); GLCD_WriteChar(i/10 + '0'); GLCD_WriteChar(i%10 + '0'); USART_Transmit('C'); GLCD_WriteChar('C'); USART_Transmit('\n'); } if (data == 'g') { ADMUX = 0x00; sbi(ADCSRA, ADSC); while (qbi(ADCSRA, ADSC)) ; uint16_t val = ADC; GLCD_TextGoTo(0,0); } data_flag=0; } }
// Main function int main (void) { // Local variable definations emxArray_uint8_T *xaxis; emxArray_uint8_T *yaxis; emxArray_uint8_T *norm_xaxis_filt; emxArray_uint8_T *norm_yaxis_filt; uint16_T count; uint8_T xaxis2,yaxis2; long j = 0; int again = 1; char letter; char letterstr[10]; int i=0; letterstr[i] = '\0'; // Variable Initialisation for(j=0;j<MAX_VALUE;j++) { xdata[j] = 0; ydata[j] = 0; } // Function Initialisation PINSEL2 &= ~((1<<2)|(1<<3)); GLCD_Initalize(); //Initialize the LCD Init_UART(); InitADC(); // Welcome message GLCD_ClearScreen(); GLCD_GoTo(10,4); GLCD_WriteString("Intelligent e-book"); // for(j=0;j<999999;j++); delay_ms(2000); // Calibration //Left bottom GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Calibration"); GLCD_GoTo(10,4); GLCD_WriteString("Touch the point"); GLCD_GoTo(0,7); GLCD_WriteString("o"); do { xaxis1 = Read_xaxis(); yaxis1 = Read_yaxis(); if(xaxis1<10) xaxis1 = 0; if(yaxis1<10) yaxis1 = 0; }while(xaxis1==0 && yaxis1==0); for(j=0;j<25;j++) capture(); x1 = xaxis1; y1 = yaxis1; GLCD_GoTo(10,5); GLCD_WriteString("Stored"); delay_ms(1000); //Right top GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Calibration"); GLCD_GoTo(10,4); GLCD_WriteString("Touch the point"); GLCD_GoTo(120,0); GLCD_WriteString("o"); do { xaxis1 = Read_xaxis(); yaxis1 = Read_yaxis(); if(xaxis1<10) xaxis1 = 0; if(yaxis1<10) yaxis1 = 0; }while(xaxis1==0 && yaxis1==0); for(j=0;j<25;j++) capture(); x2 = xaxis1; y2 = yaxis1; GLCD_GoTo(10,5); GLCD_WriteString("Stored"); delay_ms(1000); while(again==1) { again = 0; // Capturing xaxis and yaxis GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Intelligent e-book"); GLCD_GoTo(12,4); GLCD_WriteString("Waiting for input"); do { xaxis1 = Read_xaxis(); yaxis1 = Read_yaxis(); if(xaxis1<10) xaxis1 = 0; if(yaxis1<10) yaxis1 = 0; }while(xaxis1==0 && yaxis1==0); xyelem = 0; count = 0; GLCD_ClearScreen(); GLCD_GoTo(0,0); // Eliminate first 25 samples for(j=0;j<25;j++) capture(); while(count!=250) { capture(); if(xaxis1!=0 && yaxis1!=0 && count==0) { // xaxis2 = (uint8_T)(((xaxis1-80)*255)/730); // yaxis2 = (uint8_T)(((yaxis1-100)*255)/650); xaxis2 = (uint8_T)(((xaxis1-x1)*255)/(x2-x1)); yaxis2 = (uint8_T)(((yaxis1-y1)*255)/(y2-y1)); count = 0; xdata[xyelem] = xaxis2; ydata[xyelem] = yaxis2; xyelem = xyelem + 1; GLCD_SetPixel(xaxis2/2,255-(yaxis2/4),1); if(xyelem>MAX_VALUE - 1) { GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Intelligent e-book"); GLCD_GoTo(10,4); GLCD_WriteString("Overflow!!!"); while(1); } } else if(xaxis1!=0 && yaxis1!=0) { xyelem = xyelem - 2; // Eliminate first 25 samples for(j=0;j<25;j++) capture(); count = 0; } else { count = count + 1; } // delay(1000); } GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Intelligent e-book"); GLCD_GoTo(0,1); GLCD_WriteString(letterstr); //GLCD_GoTo(10,4); //GLCD_WriteString("Scanning ended"); //delay_ms(500); // Transmitting data to PC // transmit(); // Remove noise remove_noise(); // Allocating space for pointers xaxis = emxCreateWrapper_uint8_T(xdata,1,xyelem); //xdata1 yaxis = emxCreateWrapper_uint8_T(ydata,1,xyelem); //ydata1 emxInit_uint8_T(&norm_xaxis_filt, 2); emxInit_uint8_T(&norm_yaxis_filt, 2); /* GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Intelligent e-book"); GLCD_GoTo(0,2); GLCD_WriteString("Step1"); GLCD_GoTo(37,2); GLCD_WriteString("In"); */ // for(j=0;j<999999;j++); step1(xaxis, yaxis, norm_xaxis_filt, norm_yaxis_filt); // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(54,2); // GLCD_WriteString("Out"); // for(j=0;j<999999;j++); emxDestroyArray_uint8_T(xaxis); emxDestroyArray_uint8_T(yaxis); // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(0,3); // GLCD_WriteString("Step2"); // GLCD_GoTo(37,3); // GLCD_WriteString("In"); // for(j=0;j<999999;j++); // char_bin is stored in column first fashion... each column vector are concatenated step2(norm_xaxis_filt, norm_yaxis_filt, char_bin); // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(54,3); // GLCD_WriteString("Out"); // for(j=0;j<999999;j++); emxFree_uint8_T(&norm_xaxis_filt); emxFree_uint8_T(&norm_yaxis_filt); // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(0,4); // GLCD_WriteString("Step3"); // GLCD_GoTo(37,4); // GLCD_WriteString("In"); // for(j=0;j<999999;j++); for(j=0;j<10;j++) char_vec[j] = 1; step3(char_bin, char_vec); // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(54,4); // GLCD_WriteString("Out"); // for(j=0;j<999999;j++); for(j=0;j<26;j++) char_vec1[j] = char_vec[j]; // Feeding char_vec to trained neural network char_recog_nn(char_vec1,Y); letter = character(); letterstr[i] = letter; letterstr[i+1] = '\0'; // GLCD_ClearScreen(); // GLCD_GoTo(10,0); // GLCD_WriteString("Intelligent e-book"); // GLCD_GoTo(0,6); // GLCD_WriteString("Letter is: "); GLCD_GoTo(0,1); GLCD_WriteString(letterstr); GLCD_GoTo(0,7); GLCD_WriteString("Continue"); do { xaxis1 = Read_xaxis(); yaxis1 = Read_yaxis(); if(xaxis1<10) xaxis1 = 0; if(yaxis1<10) yaxis1 = 0; }while(xaxis1==0 && yaxis1==0); again = 1; i = i + 1; /* GLCD_ClearScreen(); GLCD_GoTo(10,0); GLCD_WriteString("Intelligent e-book"); GLCD_GoTo(20,4); GLCD_WriteString("Restarting."); delay_ms(200); GLCD_WriteString("."); delay_ms(200); GLCD_WriteString("."); delay_ms(200); GLCD_WriteString("."); */ delay_ms(400); } while(1); }