Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "lib.h" // lib.h from http://pastebin.com/Bzz5PRcx
- unsigned long timeInMinutes = 0;
- unsigned long long minutesCounter = 0;
- unsigned int dotCounter = 0;
- unsigned char cursor = 0; // 0 - sati, 1 - minuti
- unsigned char display[5] = {SEG7_1, SEG7_1, SEG7_1, SEG7_1};
- void makeClock(unsigned char *display_buffer, int num) {
- unsigned char numbers[] = { SEG7_0, SEG7_1, SEG7_2, SEG7_3, SEG7_4, SEG7_5,
- SEG7_6, SEG7_7, SEG7_8, SEG7_9 };
- unsigned int minutes = num % 60;
- unsigned int hours = (num / 60) % 24;
- display_buffer[3] = numbers[minutes % 10];
- display_buffer[2] = numbers[minutes / 10];
- display_buffer[1] = numbers[hours % 10];
- display_buffer[0] = numbers[hours / 10];
- if (display_buffer[0] == SEG7_0) {
- display_buffer[0] = SEG7_NULL;
- }
- }
- ISR(TIMER0_COMPA_vect) {
- minutesCounter++;
- dotCounter++;
- if (minutesCounter == 60000) {
- timeInMinutes++;
- makeClock(display, timeInMinutes);
- minutesCounter = 0;
- }
- if (dotCounter == 500) {
- display[1] &= 0b11111011;
- } else if (dotCounter == 1000) {
- display[1] |= 0b00000100;
- dotCounter = 0;
- }
- }
- ISR(PCINT1_vect) {
- // Interrupt
- }
- int main() {
- init7seg();
- initTimer();
- initButtons();
- makeClock(display, 0);
- while (1) {
- if (readButton('l') == 1) {
- cursor = 0;
- }
- if (readButton('r') == 1) {
- cursor = 1;
- }
- if (readButton('u') == 1) {
- if (cursor == 1) {
- timeInMinutes += 1;
- } else {
- timeInMinutes += 60;
- }
- makeClock(display, timeInMinutes);
- while (readButton('u') == 1) print7segWord(display);
- }
- if (readButton('d') == 1) {
- if (cursor == 1) {
- timeInMinutes -= 1;
- } else {
- timeInMinutes -= 60;
- }
- makeClock(display, timeInMinutes);
- while (readButton('d') == 1) print7segWord(display);
- }
- print7segWord(display);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement