Rev 57 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include "util.h"
#include <util/delay.h>
#include <stdlib.h>
#include "wire.h"
#include "lcd.h"
volatile uint8_t tmr0_ovf = 0;
volatile uint8_t tmr2_ovf = 0;
volatile uint32_t systime = 0;
volatile uint8_t lcdupdate = 1;
uint8_t emblock[] = { 0B00011111,
0B00010001,
0B00010001,
0B00010001,
0B00010001,
0B00010001,
0B00010001,
0B00011111 };
int main(void) {
analogInit();
/*
DDR : 1 = Output, 0 = Input
PORT: 1 = Pullup for Input, otherwise set output
PIN : Read input pin
*/
/*
PB0 - Output - Keypad 2
PB1 - Output - Keypad 7
PB2 - Output - Keypad 6
PB3 - Output - Keypad 4
PB4 - Input, Pullup - Function select
PB5 - Input, Pullup - Function select
*/
DDRB = 0B00001111;
PORTB = 0B00111111;
DDRC = 0B00000000;
PORTC = 0B00110000;
/*
PD0 - Output
PD1 - Input, Pullup, PCINT17 - Rotary 1b
PD4 - Output - Keypad select status led
PD5 - Input, Pullup - Keypad 3
PD6 - Input, Pullup - Keypad 1
PD7 - Input, Pullup - Keypad 5
*/
DDRD = 0B00010001;
PORTD = 0B11100011;
TIMSK0 = (1<<TOIE0); // Enable 8bit timer overflow for Timer0
TCNT0 = 0x00; // Set Timer0 to 0
TCCR0B = (1<< CS00) ; // /1 prescaler
TIMSK2 = (1<<TOIE2); // Enable 8bit timer overflow for Timer2
TCNT2 = 0x00; // Set Timer2 to 0
TCCR2B = (1<< CS21 | 1<<CS20 ) ; // /8 prescaler
sei();
i2c_master();
lcd_init();
lcd_createChar(0x00, emblock);
wdt_enable(WDTO_8S);
uint8_t oldpotVal = -1;
char strTime[] = {'T', 'i', 'm', 'e', ':', 0x00};
lcd_setCursor(0, 1);
lcd_print(strTime);
for(;;) {
wdt_reset();
if (lcdupdate) {
lcdupdate = 0;
char syschar[10];
ultoa(systime, syschar, 10);
lcd_overprint_right(syschar, 10, 5, 1);
uint8_t potVal = map_8(analogRead(0), 0, 255, 0, 100);
if (potVal != oldpotVal) {
lcd_percent_graph(potVal, 0, 0);
oldpotVal = potVal;
char pot[3];
utoa(potVal, pot, 10);
lcd_overprint_right(pot, 3, 11, 0);
// Set percentage
lcd_setCursor(15, 0);
lcd_char(0x25);
}
}
}
}
ISR(TIMER0_OVF_vect) {
tmr0_ovf++;
if (tmr0_ovf>=46) {
xbi(PORTD, PD0);
systime++;
tmr0_ovf = 0;
}
}
ISR(TIMER2_OVF_vect) {
tmr2_ovf++;
if (tmr2_ovf>=58) {
xbi(PORTD, PD4);
lcdupdate=1;
tmr2_ovf = 0;
}
}