/******************************* Main Program Code *************************/ int main(void) { // configure the microprocessor pins for the data lines lcd_D7_ddr |= (1<<lcd_D7_bit); // 4 data lines - output lcd_D6_ddr |= (1<<lcd_D6_bit); lcd_D5_ddr |= (1<<lcd_D5_bit); lcd_D4_ddr |= (1<<lcd_D4_bit); // configure the microprocessor pins for the control lines lcd_E_ddr |= (1<<lcd_E_bit); // E line - output lcd_RS_ddr |= (1<<lcd_RS_bit); // RS line - output // initialize the LCD controller as determined by the defines (LCD instructions) lcd_init_4d(); // initialize the LCD display for a 4-bit interface // display the first line of information lcd_write_string_4d(program_author); // set cursor to start of second line lcd_write_instruction_4d(lcd_SetCursor | lcd_LineTwo); _delay_us(80); // 40 uS delay (min) // display the second line of information lcd_write_string_4d(program_version); // endless loop while(1); return 0; }
/******************************* Main Program Code *************************/ int main(void) { // enable motor#1 DDRA = 0b00001100; // initialize the LCD controller as determined by the defines (LCD instructions) lcd_init_4d(); // initialize the LCD display for a 4-bit interface // endless loop while(1) { lcd_clear_line_4d(lcd_LineOne); _delay_ms(500); // display the first line of information lcd_write_string_line_4d("Motor Clockwise", lcd_LineOne); // rotate motor UNSET(PORTA, PIN(2)); SET(PORTA, PIN(3)); // clear LCD lcd_clear_line_4d(lcd_LineTwo); _delay_ms(500); // display the first line of information lcd_write_string_line_4d("Counter Clockwiz", lcd_LineTwo); // rotate motor SET(PORTA, PIN(2)); UNSET(PORTA, PIN(3)); } return 0; }
int main(void) { tipke_init(); lcd_init_4d(); char status_char[] = "UUUU"; char line1[] = "T0=U T1=U "; char line2[] = "T2=U T3=U "; uint8_t delay_release[4]={0}; while(1){ tipke_driver(); uint8_t tipka = tipke_get(); uint8_t i = 0; if (tipka) { switch (tipka & T_TMASK) { case T1: i=0; break; case T2: i=1; break; case T3: i=2; break; case T4: i=3; break; } switch (tipka & T_SMASK){ case T_UP: if(delay_release[i]==0)status_char[i]='U'; break; case T_DOWN: status_char[i]='D'; break; case T_TAP: status_char[i]='T'; delay_release[i]=10; break; case T_HOLD: status_char[i]='H'; break; default: break; } } for (uint8_t j=0; j<4; j++){ if (status_char[j]=='T'){ if (delay_release[j]>0) delay_release[j]--; else status_char[j]='U'; } } line1[3]=status_char[0]; line1[11]=status_char[1]; line2[3]=status_char[2]; line2[11]=status_char[3]; lcd_write_instruction_4d(lcd_Home); lcd_write_string_4d(line1); lcd_write_instruction_4d(lcd_SetCursor | lcd_LineTwo); lcd_write_string_4d(line2); _delay_ms(100); } }
/******************************* Main Program Code *************************/ int main(void) { // configure the microprocessor pins for the data lines lcd_D7_ddr |= (1<<lcd_D7_bit); // 4 data lines - output lcd_D6_ddr |= (1<<lcd_D6_bit); lcd_D5_ddr |= (1<<lcd_D5_bit); lcd_D4_ddr |= (1<<lcd_D4_bit); // configure the microprocessor pins for the control lines lcd_E_ddr |= (1<<lcd_E_bit); // E line - output lcd_RS_ddr |= (1<<lcd_RS_bit); // RS line - output // configure the microprocessor pins for the pushbutton pushbutton_ddr &= (1<<pushbutton_bit); pushbutton_port |= (1<<pushbutton_bit); // initialize adc ADMUX = ((1<<REFS0)|(1<<MUX2)|(1<<MUX0)); // Aref = Vcc, select ADC5 ADCSRA = ((1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<ADPS0)); // Prescaler div factor = 128 // initialize the LCD controller as determined by the defines (LCD instructions) lcd_init_4d(); // initialize the LCD display for a 4-bit interface // initialize TWI i2c_init(); // initialize thermometer therm_init(); // display the first line of information lcd_write_string_4d(disp_time); // set cursor to start of second line lcd_write_instruction_4d(lcd_setCursor | lcd_lineTwo); _delay_us(40); // 40 uS delay (min) // Code for interfacing with the serial connection char str[25]; int yy,mm,dd; sei(); // Enable global interrupts uart_init(); // Initialize the USART using baud rate 9600 uart_printstr(sdata); // Print a string from SRAM uart_printstr(fdata); // Print a string from FLASH getDate(&yy,&mm,&dd); // Get date from user sprintf(str,"Date: %d/%d/%d\n",yy,mm,dd); uart_printstr(str); // endless loop while(1) { uart_printstr(sdata); // Print a string from SRAM uart_printstr(fdata); // replace with check for button press function if(bit_is_clear(pushbutton_pin,pushbutton_bit)) { _delay_ms(100); if(bit_is_clear(pushbutton_pin,pushbutton_bit)) mode_new = (mode + 1) % 3; } if(mode_new != mode) { // clear lcd lcd_write_instruction_4d(lcd_clear); // display the first line of information // set cursor to start of first line lcd_write_instruction_4d(lcd_setCursor | lcd_lineOne); _delay_us(40); // 40 uS delay (min lcd_write_string_4d(disp_time); // set cursor to start of second line lcd_write_instruction_4d(lcd_setCursor | lcd_lineTwo); _delay_us(40); // 40 uS delay (min) if (mode_new == 0) { voltage = read_ADC(); lcd_write_string_4d(disp_volt); } else if (mode_new == 1) { frequency = 10 * freq_cntr_get_frequency(); lcd_write_string_4d(disp_freq); } else { temp_calcTemp(); // test thermometer lcd_write_string_4d(disp_temp); } } mode = mode_new; } return 0; }
/******************************* Main Program Code *************************/ int main(void) { // configure the microprocessor pins for the data lines lcd_D7_ddr |= (1<<lcd_D7_bit); // 4 data lines - output lcd_D6_ddr |= (1<<lcd_D6_bit); lcd_D5_ddr |= (1<<lcd_D5_bit); lcd_D4_ddr |= (1<<lcd_D4_bit); // configure the microprocessor pins for the control lines lcd_E_ddr |= (1<<lcd_E_bit); // E line - output lcd_RS_ddr |= (1<<lcd_RS_bit); // RS line - output // configure the microprocessor pins for the pushbutton pushbutton_ddr &= (1<<pushbutton_bit); pushbutton_port |= (1<<pushbutton_bit); // initialize adc ADMUX = ((1<<REFS0)|(1<<MUX2)|(1<<MUX0)); // Aref = Vcc, select ADC5 ADCSRA = ((1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<ADPS0)); // Prescaler div factor = 128 // initialize the LCD controller as determined by the defines (LCD instructions) lcd_init_4d(); // initialize the LCD display for a 4-bit interface // display the first line of information lcd_write_string_4d(disp_time); // set cursor to start of second line lcd_write_instruction_4d(lcd_setCursor | lcd_lineTwo); _delay_us(40); // 40 uS delay (min) if (mode == 0) { lcd_write_string_4d(disp_volt); } else if (mode == 1) { lcd_write_string_4d(disp_freq); } else { lcd_write_string_4d(disp_temp); } // Code for interfacing with the serial connection char str[25]; int yy,mm,dd; sei(); // Enable interrupts usart_init(); // Initialize the USART // Get the date, make a formatted string, and then // send via the USART. getDate(&yy,&mm,&dd); sprintf(str,"Date: %d/%d/%d\n",yy,mm,dd); usart_prints(str); // I2C code //i2c_init(); // initialize I2C library // endless loop while(1) { if(bit_is_clear(pushbutton_pin,pushbutton_bit)) { _delay_ms(10); if(bit_is_clear(pushbutton_pin,pushbutton_bit)) mode_new = (mode + 1) % 3; } if(mode_new != mode) { // set cursor to start of second line lcd_write_instruction_4d(lcd_setCursor | lcd_lineTwo); _delay_us(40); // 40 uS delay (min) if (mode_new == 0) { lcd_write_string_4d(disp_volt); } else if (mode_new == 1) { lcd_write_string_4d(disp_freq); } else { lcd_write_string_4d(disp_temp); } } mode = mode_new; } return 0; }