/* Main Function */ int main(void){ enum states{ setup, drawing, readusart, } currentstate = setup; unsigned char STRING1[]="YAY THIS"; unsigned char STRING2[]="WORKS!!!"; unsigned char STR1CMP[9]; unsigned char STR2CMP[9]; unsigned char x, i, j; unsigned char send[50]; while(1){ switch(currentstate){ case setup: initialize(); clearArray(); PORTB = 0b10000000; PORTC |= 0b10000000; ht1632_initialize(); PORTC |= 0b01000000; InitializeUART(); PORTC |= 0b00100000; sprintf(send, "Initialized...\n"); PORTC |= 0b00010000; SendStringUART(send); _delay_ms(200); PORTC = 0; strcpy(STRING1, "YAY THIS"); strcpy(STRING2, "WORKS!!!"); currentstate = drawing; break; case drawing: for(x=1;x<sizeof(STRING1);x++) { null_buffer(); for(i=0;i<8;i++){ for(j=0;j<8;j++){ set_buffer(STRING1[x-1]); if (~buffer[i][j] & (1<<0)) { ht1632_plot(j+(8*(x-1))-1,i,GREEN); PORTC = ~PORTC; } else { ht1632_plot(j+(8*(x-1))-1,i,BLACK); PORTC = ~PORTC; } } } } for(x=1;x<sizeof(STRING2);x++) { null_buffer(); for(i=0;i<8;i++){ for(j=0;j<8;j++){ set_buffer(STRING2[x-1]); if (~buffer[i][j] & (1<<0)) { ht1632_plot(j+(8*(x-1))-1,i+8,GREEN); PORTC = ~PORTC; } else { ht1632_plot(j+(8*(x-1))-1,i+8,BLACK); PORTC = ~PORTC; } } } } PORTC = 0; currentstate = readusart; break; case readusart: strcpy(STR1CMP, STRING1); strcpy(STR2CMP, STRING2); NewScreen(STRING1, STRING2); if((strcmp(STRING1, "RESETRES") == 0)){ currentstate = setup; }else if((strcmp(STRING1, STR1CMP) != 0) | (strcmp(STRING2, STR2CMP) != 0)){ currentstate = drawing; } break; } } }
int main(void) { MCUSR &= ~(1 << WDRF); wdt_disable(); clock_prescale_set(clock_div_1); USB_Init(); // /usb/LowLevel/LowLevel.c LEDs_Init(); SetupHardware(); //--- Histogram tests h_buff_t buffer01; buffer01.buff[0].bin[0] = 33; buffer01.buff[0].bin[1]++; buffer01.max_total = 200; h_buff_clean_unit(&buffer01, 0); //--- Histogram tests sei(); for(int u=0; u<200; u++){ _delay_ms(10); } for(;;){ //while ( !RecvStringUART(StrinIn) ); //wait for RS data //receive string: u20z (char+number+delimiter) if (RecvStringUART(StrinIn)) { //SendStringUART("\r\nReceived: "); switch (StrinIn[0]) { //setting options: case 'q': //duty cycle 1st phase if (valRcv <= ICR3) OCR3A = valRcv; else OCR3A = ICR3; sprintf(StrinOut, "Duty %d. Cycles %d.\r\n", OCR3A, ICR3); break; case 'w': //PWM period = 1/frequency if ( (valRcv <= 255) && (valRcv > 20) ) ICR3 = valRcv; else valRcv = ICR3; sprintf(StrinOut, "Cycles: %d\r\n", ICR3); break; default: sprintf(StrinOut, "Unknown message:(\r\n"); } SendStringUART(StrinOut); } //if USART } }