int main(void){ ini_lcd(); ini_avr(); for(;;) { if(get_key() == 13) // SET DATE { //put_lcd('A'); row = 0; col = 0; clr_lcd(); pos_lcd(0,0); put_str_lcd("MMDDYYYY"); start = 0; pos_lcd(0,0); set_date = 1; set_time = 0; index = 0; } else if(get_key() == 9) // SET TIME { //put_lcd('B'); row = 1; col = 0; clr_lcd(); pos_lcd(1,0); put_str_lcd("HHMMSS"); start = 0; pos_lcd(1,0); set_time = 1; set_date = 0; index = 0; } if (start == 1) { increment(); print(); } else { if(get_key() == 2) { //put_lcd('#'); if (set_date) {setDate();} if (set_time) {setTime();} start = 1; } else if(get_key() == 3){ put_lcd('0'); if(set_date){ date[index] = 0; } else if(set_time){ time[index] = 0; } index++; col++; } else if(get_key() == 4){ //put_lcd('*'); clr_lcd(); col = 0; row = 0; set_time = 0; set_date = 0; start = 1; index = 0; } else if(get_key() == 6){ put_lcd('9'); if(set_date){ date[index] = 9; } else if(set_time){ time[index] = 9; } index++; col++; } else if(get_key() == 7){ put_lcd('8'); if(set_date){ date[index] = 8; } else if(set_time){ time[index] = 8; } index++; col++; } else if(get_key() == 8){ put_lcd('7'); if(set_date){ date[index] = 7; } else if(set_time){ time[index] = 7; } index++; col++; } else if(get_key() == 10){ put_lcd('6'); if(set_date){ date[index] = 6; } else if(set_time){ time[index] = 6; } index++; col++; } else if(get_key() == 11){ put_lcd('5'); if(set_date){ date[index] = 5; } else if(set_time){ time[index] = 5; } index++; col++; } else if(get_key() == 12){ put_lcd('4'); if(set_date){ date[index] = 4; } else if(set_time){ time[index] = 4; } index++; col++; } else if(get_key() == 14){ put_lcd('3'); if(set_date){ date[index] = 3; } else if(set_time){ time[index] = 3; } index++; col++; } else if(get_key() == 15){ put_lcd('2'); if(set_date){ date[index] = 2; } else if(set_time){ time[index] = 2; } index++; col++; } else if(get_key() == 16){ put_lcd('1'); if(set_date){ date[index] = 1; } else if(set_time){ time[index] = 1; } index++; col++; } if (set_time) { if (col > 5) { col = 0; pos_lcd(row, col); } } else if (set_date) { if (col > 7) { col = 0; pos_lcd(row, col); } } } wait_avr(25); } return 0; }
void print() { tens = '0' + (hr / 10); ones = '0' + (hr % 10); pos_lcd(1,0); put_lcd(tens); put_lcd(ones); pos_lcd(1,2); put_lcd(':'); tens = '0' + (min / 10); ones = '0' + (min % 10); pos_lcd(1,3); put_lcd(tens); put_lcd(ones); pos_lcd(1,5); put_lcd(':'); tens = '0' + (sec / 10); ones = '0' + (sec % 10); pos_lcd(1,6); put_lcd(tens); put_lcd(ones); tens = '0' + (month / 10); ones = '0' + (month % 10); pos_lcd(0,0); put_lcd(tens); put_lcd(ones); pos_lcd(0,2); put_lcd('/'); tens = '0' + (day / 10); ones = '0' + (day % 10); pos_lcd(0,3); put_lcd(tens); put_lcd(ones); pos_lcd(0,5); put_lcd('/'); unsigned char thous = '0' + (year / 1000); unsigned char hund = '0' + ((year%1000) / 100); tens = '0' + ((year%100) / 10); ones = '0' + (year % 10); pos_lcd(0,6); put_lcd(thous); put_lcd(hund); put_lcd(tens); put_lcd(ones); }
//--------------------------------------------------------------------------------------------------------------------------- int main() { unsigned char ch=0; wdt_enable(WDTO_500MS); PORTB=0x1C; DDRB= 0xBC; DDRD = 0xF0; DDRC = 0x0F; PORTC= 0xF8; sbi(SPSR,SPI2X); SPCR= _BV(SPE) | _BV(MSTR) | _BV(CPOL) | _BV(CPHA) | _BV(SPR0); // calc(); net_init(); lcd_init(); OCR1A=675; TCCR1A=0; TCCR1B= _BV(WGM12) | _BV(CS12) | _BV(CS10); sbi(TIMSK,OCIE1A); dac[0]=eeprom_read_word(val); dac[1]=eeprom_read_word(val+1); wdt_reset(); sei(); while(1) { sprintf(s," %3d%% %3d%%\01%3d%%%c",ai[0]/40,ai[1]/40,dac[0]/40,eeprom_read_byte(md)?'A':'P'); put_lcd(s,0); sprintf(s," %3d%% %3d%%\01%3d%%%c",ai[2]/40,ai[3]/40,dac[1]/40,eeprom_read_byte(md+1)?'A':'P'); put_lcd(s,1); byte2lcd(128+64*ch,0); byte2lcd(2,1); switch(getkey()) { case SET & STOP: setup(); calc(); break; case STOP: ch ^=1; break; case SET: if(eeprom_read_byte(md+ch)) { eeprom_write_byte(md+ch,0); dac[ch] = ((dac[ch]/200))*200; } else eeprom_write_byte(md+ch,1); break; case MIN: if(!eeprom_read_byte(md+ch)) { dac[ch]-=200; if(dac[ch]&0x8000) dac[ch]=0; eeprom_write_word(val+ch,dac[ch]); } break; case MAX: if(!eeprom_read_byte(md+ch)) { dac[ch]+=200; if(dac[ch]>4000) dac[ch]=4000; eeprom_write_word(val+ch,dac[ch]); } } delay_ms(300); wdt_reset(); } return 0; }