Made code to work. Cleaned up

This commit is contained in:
nedko 2023-03-06 22:32:25 +02:00
parent c04af37359
commit c25e6f5f44

View File

@ -1,11 +1,8 @@
#define F_CPU 1000000
#include <avr/eeprom.h> #include <avr/eeprom.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <avr/io.h> #include <avr/io.h>
#include <avr/sleep.h> #include <avr/sleep.h>
#include <util/delay.h>
#include <stdint.h> #include <stdint.h>
#define VALUE_MIN -99999 #define VALUE_MIN -99999
@ -84,12 +81,12 @@ ISR(PCINT0_vect)
uint8_t event = EVENT_NONE; uint8_t event = EVENT_NONE;
cli(); cli();
if (0 == (PINB & PIN_BTN_DEC)) if (0 == (PINB & (1 << PIN_BTN_DEC)))
{ {
new_btn_flag |= BTN_FLAG_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; new_btn_flag |= BTN_FLAG_INC;
} }
@ -153,8 +150,7 @@ void hard_init()
// Sleep mode - Power down // Sleep mode - Power down
MCUCR = (1 << SM1); MCUCR = (1 << SM1);
// Disable power to Timer1, Timer0, USI, ADC // Disable power to Timer1, USI, ADC
//PRR = (1 << PRTIM1) | (1 << PRTIM0) | (1 << PRUSI) | (1 << PRADC);
PRR = (1 << PRTIM1) | (1 << PRUSI) | (1 << PRADC); PRR = (1 << PRTIM1) | (1 << PRUSI) | (1 << PRADC);
// Enable button interrupts // Enable button interrupts
@ -184,17 +180,17 @@ void display_send_bit(uint8_t bit)
{ {
if (0 != bit) if (0 != bit)
{ {
PORTB |= (1 << OUT_DATA); PORTB |= (1 << PORTB1);
} }
else else
{ {
PORTB &= ~(1 << OUT_DATA); PORTB &= ~(1 << PORTB1);
} }
_delay_ms(1); PORTB |= (1 << PORTB2);
PORTB |= (1 << OUT_CLOCK); while(!(PINB & (1 << PINB2)));
_delay_ms(1); PORTB &= ~(1 << PORTB2);
PORTB &= (1 << OUT_CLOCK); while(PINB & (1 << PINB2));
} }
void display_send_buffer() void display_send_buffer()
@ -205,7 +201,7 @@ void display_send_buffer()
for (b = 0; b < DISPLAY_SIZE / 2; ++b) 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) for (b = 0; b < DISPLAY_SIZE / 2; ++b)
@ -224,10 +220,10 @@ void display_send_buffer()
void display_show() void display_show()
{ {
_delay_ms(1); PORTB |= (1 << PORTB0);
PORTB |= (1 << OUT_STORE); while(!(PINB & (1 << PINB0)));
_delay_ms(1); PORTB &= ~(1 << PORTB0);
PORTB &= (1 << OUT_STORE); while(PINB & (1 << PINB0));
} }
void display_show_value(uint8_t dots) 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) for (i = 0; i < DISPLAY_SIZE; ++i)
{ {
digit = counter_copy / div_val; digit = counter_copy / div_val;
if ((0 != txt) || (0 != digit)) if ((0 != txt) || (0 != digit) || (DISPLAY_SIZE - 1 == i))
{ {
txt = 1; txt = 1;
display_buffer[i] = seg_table[digit]; display_buffer[i] = seg_table[digit];
@ -271,7 +267,7 @@ void display_show_value(uint8_t dots)
if (0 != dots) if (0 != dots)
{ {
display_buffer[6] |= DP; display_buffer[DISPLAY_SIZE - 1] |= DP;
} }
display_send_buffer(); display_send_buffer();