Made code to work. Cleaned up
This commit is contained in:
parent
c04af37359
commit
c25e6f5f44
36
code/main.c
36
code/main.c
@ -1,11 +1,8 @@
|
||||
#define F_CPU 1000000
|
||||
#include <avr/eeprom.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/sleep.h>
|
||||
|
||||
#include <util/delay.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define VALUE_MIN -99999
|
||||
@ -84,12 +81,12 @@ ISR(PCINT0_vect)
|
||||
uint8_t event = EVENT_NONE;
|
||||
|
||||
cli();
|
||||
if (0 == (PINB & PIN_BTN_DEC))
|
||||
if (0 == (PINB & (1 << PIN_BTN_DEC)))
|
||||
{
|
||||
new_btn_flag |= BTN_FLAG_DEC;
|
||||
}
|
||||
|
||||
if (0 == (PINB & PIN_BTN_INC))
|
||||
if (0 == (PINB & (1 << PIN_BTN_INC)))
|
||||
{
|
||||
new_btn_flag |= BTN_FLAG_INC;
|
||||
}
|
||||
@ -153,8 +150,7 @@ void hard_init()
|
||||
// Sleep mode - Power down
|
||||
MCUCR = (1 << SM1);
|
||||
|
||||
// Disable power to Timer1, Timer0, USI, ADC
|
||||
//PRR = (1 << PRTIM1) | (1 << PRTIM0) | (1 << PRUSI) | (1 << PRADC);
|
||||
// Disable power to Timer1, USI, ADC
|
||||
PRR = (1 << PRTIM1) | (1 << PRUSI) | (1 << PRADC);
|
||||
|
||||
// Enable button interrupts
|
||||
@ -184,17 +180,17 @@ void display_send_bit(uint8_t bit)
|
||||
{
|
||||
if (0 != bit)
|
||||
{
|
||||
PORTB |= (1 << OUT_DATA);
|
||||
PORTB |= (1 << PORTB1);
|
||||
}
|
||||
else
|
||||
{
|
||||
PORTB &= ~(1 << OUT_DATA);
|
||||
PORTB &= ~(1 << PORTB1);
|
||||
}
|
||||
|
||||
_delay_ms(1);
|
||||
PORTB |= (1 << OUT_CLOCK);
|
||||
_delay_ms(1);
|
||||
PORTB &= (1 << OUT_CLOCK);
|
||||
PORTB |= (1 << PORTB2);
|
||||
while(!(PINB & (1 << PINB2)));
|
||||
PORTB &= ~(1 << PORTB2);
|
||||
while(PINB & (1 << PINB2));
|
||||
}
|
||||
|
||||
void display_send_buffer()
|
||||
@ -205,7 +201,7 @@ void display_send_buffer()
|
||||
|
||||
for (b = 0; b < DISPLAY_SIZE / 2; ++b)
|
||||
{
|
||||
custom_buffer[b] = (((display_buffer[b * 2] & 0xF0) << 4) | (display_buffer[b * 2 + 1] & 0xF0));
|
||||
custom_buffer[b] = ((display_buffer[b * 2] & 0xF0) | ((display_buffer[b * 2 + 1] & 0xF0) >> 4));
|
||||
}
|
||||
|
||||
for (b = 0; b < DISPLAY_SIZE / 2; ++b)
|
||||
@ -224,10 +220,10 @@ void display_send_buffer()
|
||||
|
||||
void display_show()
|
||||
{
|
||||
_delay_ms(1);
|
||||
PORTB |= (1 << OUT_STORE);
|
||||
_delay_ms(1);
|
||||
PORTB &= (1 << OUT_STORE);
|
||||
PORTB |= (1 << PORTB0);
|
||||
while(!(PINB & (1 << PINB0)));
|
||||
PORTB &= ~(1 << PORTB0);
|
||||
while(PINB & (1 << PINB0));
|
||||
}
|
||||
|
||||
void display_show_value(uint8_t dots)
|
||||
@ -260,7 +256,7 @@ void display_show_value(uint8_t dots)
|
||||
for (i = 0; i < DISPLAY_SIZE; ++i)
|
||||
{
|
||||
digit = counter_copy / div_val;
|
||||
if ((0 != txt) || (0 != digit))
|
||||
if ((0 != txt) || (0 != digit) || (DISPLAY_SIZE - 1 == i))
|
||||
{
|
||||
txt = 1;
|
||||
display_buffer[i] = seg_table[digit];
|
||||
@ -271,7 +267,7 @@ void display_show_value(uint8_t dots)
|
||||
|
||||
if (0 != dots)
|
||||
{
|
||||
display_buffer[6] |= DP;
|
||||
display_buffer[DISPLAY_SIZE - 1] |= DP;
|
||||
}
|
||||
|
||||
display_send_buffer();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user