Utilities. More...

Go to the source code of this file.
Defines | |
| #define | PORTDIGIT PORTC |
| #define | DDRDIGIT DDRC |
| #define | PORTBUTTON PORTC |
| #define | DDRBUTTON DDRC |
| #define | PORTSA234 PORTD |
| #define | DDRSA234 DDRD |
| #define | PORTSA1 PORTB |
| #define | DDRSA1 DDRB |
| #define | PORTDOT PORTD |
| #define | DDRDOT DDRD |
| #define | DOT 3 |
| #define | PORTHVPUMP PORTB |
| #define | DDRHVPUMP DDRB |
| #define | BV2(a, b) (_BV(a)|_BV(b)) |
| #define | BV3(a, b, c) (_BV(a)|_BV(b)|_BV(c)) |
| #define | BV4(a, b, c, d) (_BV(a)|_BV(b)|_BV(c)|_BV(d)) |
| #define | BV5(a, b, c, d, e) (_BV(a)|_BV(b)|_BV(c)|_BV(d)|_BV(e)) |
| #define | BV6(a, b, c, d, e, f) (_BV(a)|_BV(b)|_BV(c)|_BV(d)|_BV(e)|_BV(f)) |
| #define | BV7(a, b, c, d, e, f, g) (_BV(a)|_BV(b)|_BV(c)|_BV(d)|_BV(e)|_BV(f)|_BV(g)) |
| #define | maketime(hh, mm) (((hh) << 8) + (mm)) |
| Make BCD time from 2 bytes. | |
| #define | _frombcd(x) ((x & 017) + (((x) & 0160)>>4) * 10) |
Enumerations | |
| enum | _sa_values { SA1 = 0, SA2, SA3, SA4, SAX = 0377 } |
Functions | |
| uint8_t | frombcd (uint8_t) |
| uint16_t | tobcd16 (uint16_t) |
| uint8_t | days_in_month_bcd (uint8_t year, uint8_t month) |
| uint8_t | bcd_increment (uint8_t x) |
| Increment BCD value by 1. | |
| uint8_t | day_of_week (uint8_t y, uint8_t m, uint8_t d) |
| Get day of week, 0 = Sunday. Input parameters are binary (not BCD). | |
| void | blinkmode_set (uint8_t mode) |
| Set blinkmode. | |
| uint8_t | blinkmode_get () |
| Get blinkmode. | |
| void | fade_set (uint8_t mode) |
| void | fadeto (uint16_t t) |
| uint16_t | get_display_value () |
| Return current BCD display value. | |
| void | mode_next () |
| uint8_t | mode_get () |
| void | savingmode_set (uint8_t s) |
| uint8_t | savingmode_get () |
| void | savingmode_next () |
| void | dotmode_set (uint8_t mode) |
Variables | |
| void(* | blinkhandler )(uint8_t) |
| Called every blink, unless NULL. | |
Utilities.
Bit settings. BCD conversions. Calendar.
| #define _frombcd | ( | x | ) | ((x & 017) + (((x) & 0160)>>4) * 10) |
Convert to binary from BCD representation
| #define BV2 | ( | a, | |||
| b | ) | (_BV(a)|_BV(b)) |
| #define BV3 | ( | a, | |||
| b, | |||||
| c | ) | (_BV(a)|_BV(b)|_BV(c)) |
| #define BV4 | ( | a, | |||
| b, | |||||
| c, | |||||
| d | ) | (_BV(a)|_BV(b)|_BV(c)|_BV(d)) |
| #define BV5 | ( | a, | |||
| b, | |||||
| c, | |||||
| d, | |||||
| e | ) | (_BV(a)|_BV(b)|_BV(c)|_BV(d)|_BV(e)) |
| #define BV6 | ( | a, | |||
| b, | |||||
| c, | |||||
| d, | |||||
| e, | |||||
| f | ) | (_BV(a)|_BV(b)|_BV(c)|_BV(d)|_BV(e)|_BV(f)) |
| #define BV7 | ( | a, | |||
| b, | |||||
| c, | |||||
| d, | |||||
| e, | |||||
| f, | |||||
| g | ) | (_BV(a)|_BV(b)|_BV(c)|_BV(d)|_BV(e)|_BV(f)|_BV(g)) |
| #define DDRBUTTON DDRC |
| #define DDRDIGIT DDRC |
| #define DDRDOT DDRD |
| #define DDRHVPUMP DDRB |
| #define DDRSA1 DDRB |
| #define DDRSA234 DDRD |
| #define DOT 3 |
| #define maketime | ( | hh, | |||
| mm | ) | (((hh) << 8) + (mm)) |
Make BCD time from 2 bytes.
| #define PORTBUTTON PORTC |
| #define PORTDIGIT PORTC |
| #define PORTDOT PORTD |
| #define PORTHVPUMP PORTB |
| #define PORTSA1 PORTB |
| #define PORTSA234 PORTD |
| enum _sa_values |
| uint8_t bcd_increment | ( | uint8_t | x | ) |
| uint8_t blinkmode_get | ( | ) | [inline] |
Get blinkmode.
00081 { return blinkmode; }
| void blinkmode_set | ( | uint8_t | mode | ) |
Set blinkmode.
00077 { 00078 blinkmode = mode; 00079 }
| uint8_t day_of_week | ( | uint8_t | y, | |
| uint8_t | m, | |||
| uint8_t | d | |||
| ) |
Get day of week, 0 = Sunday. Input parameters are binary (not BCD).
00033 { 00034 uint8_t leap = y%4 == 0; 00035 uint16_t centurydays = 6 + y * 365 + (y+3)/4; // year 2000 started on Saturday 00036 for (; --m >= 1; ) { 00037 centurydays += month_length(m,leap); 00038 } 00039 00040 centurydays += d-1; 00041 00042 return (centurydays % 7); 00043 }

| uint8_t days_in_month_bcd | ( | uint8_t | year, | |
| uint8_t | month | |||
| ) |
Return BCD count of days in month for given BCD year and month. Valid only for years 2000-2099.
00013 { 00014 uint8_t y = frombcd(year);//(year & 7) + ((year & 070)>>3) * 10; 00015 uint8_t m = frombcd(month);//(month & 7) + ((month & 070)>>3) * 10; 00016 uint8_t leap = y % 4 == 0; // non y2k1-compliant, but should be correct for the next 91 years or so :) 00017 00018 uint8_t knuckle = m < 8 ? (m & 1) == 1 : (m & 1) == 0; 00019 return knuckle ? 0x31 : m != 2 ? 0x30 : leap ? 0x29 : 0x28; 00020 }

| void dotmode_set | ( | uint8_t | mode | ) |
00041 { 00042 dotmode = mode; 00043 }
| void fade_set | ( | uint8_t | mode | ) |
Sets fading mode and speed
00014 { 00015 switch (mode) { 00016 case FADE_ON: 00017 fadetime_full = FADETIME; 00018 fadetime_quart = FADETIME/4; 00019 fademode = FADE_ON; 00020 break; 00021 case FADE_OFF: 00022 fademode = FADE_OFF; 00023 break; 00024 case FADE_SLOW: 00025 fadetime_full = FADETIME_S; 00026 fadetime_quart = FADETIME_S/4; 00027 fademode = FADE_ON; 00028 break; 00029 } 00030 }
| void fadeto | ( | uint16_t | t | ) |
Start fading time to given value. Transition is performed in TIMER0_OVF_vect and takes FADETIME cycles.
00151 { 00152 uint16_t raw = getrawdigits_bcd(t); // takes time 00153 cli(); 00154 timef = t; 00155 rawfadeto = raw; 00156 fadetime = -1; 00157 sei(); 00158 }

| uint8_t frombcd | ( | uint8_t | ) |
| uint16_t get_display_value | ( | ) | [inline] |
Return current BCD display value.
00161 { 00162 return timef; 00163 }
| uint8_t mode_get | ( | ) | [inline] |
| void mode_next | ( | ) |
Cycle display modes
00053 { 00054 display_mode = (display_mode + 1) % NDISPLAYMODES; 00055 switch (display_mode) { 00056 case HHMM: fade_set(FADE_SLOW); 00057 dotmode_set(DOT_BLINK); 00058 break; 00059 case MMSS: fade_set(FADE_ON); 00060 dotmode_set(DOT_BLINK); 00061 break; 00062 case VOLTAGE: fade_set(FADE_OFF); 00063 dotmode_set(DOT_OFF); 00064 break; 00065 } 00066 }

| void savingmode_next | ( | ) |
00097 { 00098 savingmode_set((savingmode_get() + 1) % 3); 00099 }

| uint16_t tobcd16 | ( | uint16_t | ) |
| void(* blinkhandler)(uint8_t) |
Called every blink, unless NULL.
1.6.1