This repository has been archived on 2022-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
AtTiny_alarm_clock/main.c

88 lines
1.5 KiB
C

/*
* AtTiny_alarm_clock.c
*
* Created: 16.07.2018 13:55:13
* Author : dozed
*/
#include <avr/io.h>
#include <stdlib.h>
#include "lcd4.h"
#define butt1 0
typedef enum {CLOCK_INIT = 0, CLOCK_IDLE, CLOCK_ALARM, CLOCK_STOPWATCH_RUNNING, CLOCK_STOPWATCH_STOPPED, CLOCK_STOPWATCH_NOT_SET, CLOCK_USER_INPUT, CLOCK_SET_TIME} clock_state_e;
clock_state_e clock_old_state;
clock_state_e clock_state = CLOCK_INIT;
clock_state_e clock_new_state = CLOCK_INIT;
uint8_t t1[] = {' ','H','a','l','l','o','_','_','_','_','_','_','_','_','_','_','_'};
int counter = 0;
uint8_t flags;
int main(void)
{
DDRD = 0x00;
/* Replace with your application code */
while (1)
{
clock_state = clock_new_state;
switch(clock_state){
case CLOCK_INIT:
//do some init stuff...
lcd_init(); //I know, it's just c but I don't care
lcd_instruct(lcd_DISPLAY_CLEAR);
//INIT done -> change to IDLE
clock_new_state = CLOCK_IDLE;
break;
case CLOCK_IDLE:
//IDLE MODE
//print the IDLE Screen
lcd_write_text(0,0,t1);
if(((PIND & 0x03) == 3) != (flags & 1<<butt1)){
if((PIND & 0x03) == 3){
flags |= 1<<butt1;
counter++;
}
else{
flags &= ~(1<<butt1);
}
}
t1[0] = counter + 48;
break;
}
}
}
void lcd_write_text(int row, int col, uint8_t text[16])
{
switch(row){
case 0:
row = line1;
break;
case 1:
row = line2;
break;
}
int i=0;
while(text[i] != 0x5F){
lcd_write(row, text[i], 0+i);
i++;
}
}