<commit_before>//7 segment clock based on DS1307 for timekeeping
#define F_CPU 1000000
#include <avr/io.h> //allows more human readable stuff
#include <avr/interrupt.h>  //allows interrupts 
#include <util/delay.h> //Gives delay functions
#include <math.h> //Used in this case just for "round" because I didn't want to implement it myself.

#include "IIC.h" //IIC communication functions via TWI
#include "DS1307.h"//Clock chip functions

//define button pins
#define HourPort PINC
#define HourMask 0x01 //C0
#define MinutePort PINC
#define MinuteMask 0x02 //C1

//Use shift register for output
//#define USESHIFTREGISTER

#ifdef USESHIFTREGISTER
#include "ShiftOut.h"
#define ClockPin 0
#define ClockPORT DDRB
#define DataPin 1
#define DataPORT DDRB
#define LatchPin 2
#define LatchPORT DDRB
#endif

//Function prototype
uint32_t ConvertToBar(uint8_t num);

//define variables that will be affected by ISR
volatile uint8_t HourButton = 0;
volatile uint8_t MinuteButton = 0;


int main(void){
  _delay_ms(50);//the delay is to give the DS1307 time to initialize. 
  //set up output pins
  DDRD = 0xFF;//set all of port D to be output
  DDRB = 0xFF;//set all of port C to be output

  //init clock chip (ds1307)
  TWIInit();
  DS1307Init();

  //set up timer0 and enable interrupts
  TCCR0A |= (0 << CS02);
  TCCR0B |= (1 << CS01) | (1 << CS00);
  TIMSK0 |= (1 << TOIE0);
  sei(); 

  while(1){  

    //define time variables
    static uint8_t Minutes = 0, Hours = 0;
    //read current time from clock
    cli();
    Minutes = DS1307RegisterR(0x01);
    Hours = DS1307RegisterR(0x02);
    sei();

    //define state variables
    static uint8_t HourAdd = 0, MinuteAdd = 0, HourState = 0, MinuteState = 0;
    //define working variables
    static uint8_t MinutesOnes = 0, MinutesTens = 0, HoursOnes = 0, HoursTens = 0;
    //define Bar variables
    static uint8_t DecMinutes = 0, DecHours = 0, IntLEDS = 0;
    static double FracHour = 0, FHours = 0, FracDay = 0, LEDS = 0;
    static uint32_t LIntLEDS = 0;

    //separate digits from read values
    MinutesOnes = Minutes & 0x0F;
    MinutesTens = (Minutes & 0x70) >> 4;
    HoursOnes = Hours & 0x0F;
    HoursTens = (Hours & 0x30) >> 4;

    //merge ones and tens digits and convert to base 10
    DecMinutes = MinutesOnes + 10*MinutesTens;
    DecHours = HoursOnes + 10*HoursTens;

    //Calculate fraction of Day that has occured
    FracHour = (double)DecMinutes / (60.);
    FHours = (double)DecHours + FracHour;
    FracDay = FHours / (24.);
    
    //round to nearest LED
    LEDS = FracDay * (16.);//exact number of LEDs needed
    LEDS = round(LEDS);//round to nearest integer
    IntLEDS = (uint8_t)LEDS & 0xFF;//pull the bottom byte into a smaller variable
    LIntLEDS = ConvertToBar(IntLEDS);//convert number of LEDs needed to a string of "1"s in a 32 bit int
    
    //output to Bars
    #ifndef USESHIFTREGISTER
    PORTB = (LIntLEDS & 0xFF);
    PORTD = ((LIntLEDS >> 8) & 0xFF);
    #endif<commit_msg>added comment<commit_after>//7 segment clock based on DS1307 for timekeeping
#define F_CPU 1000000
#include <avr/io.h> //allows more human readable stuff
#include <avr/interrupt.h>  //allows interrupts 
#include <util/delay.h> //Gives delay functions
#include <math.h> //Used in this case just for "round" because I didn't want to implement it myself.

#include "IIC.h" //IIC communication functions via TWI
#include "DS1307.h"//Clock chip functions

//define button pins
#define HourPort PINC
#define HourMask 0x01 //C0
#define MinutePort PINC
#define MinuteMask 0x02 //C1

//Use shift register for output
//#define USESHIFTREGISTER

#ifdef USESHIFTREGISTER
#include "ShiftOut.h"
#define ClockPin 0
#define ClockPORT DDRB
#define DataPin 1
#define DataPORT DDRB
#define LatchPin 2
#define LatchPORT DDRB
#endif

//Function prototype
uint32_t ConvertToBar(uint8_t num);

//define variables that will be affected by ISR
volatile uint8_t HourButton = 0;
volatile uint8_t MinuteButton = 0;


int main(void){
  _delay_ms(50);//the delay is to give the DS1307 time to initialize. 
  //set up output pins
  DDRD = 0xFF;//set all of port D to be output
  DDRB = 0xFF;//set all of port C to be output

  //init clock chip (ds1307)
  TWIInit();
  DS1307Init();

  //set up timer0 and enable interrupts
  TCCR0A |= (0 << CS02);
  TCCR0B |= (1 << CS01) | (1 << CS00);
  TIMSK0 |= (1 << TOIE0);
  sei(); 

  while(1){  

    //define time variables
    static uint8_t Minutes = 0, Hours = 0;
    //read current time from clock
    cli();
    Minutes = DS1307RegisterR(0x01);
    Hours = DS1307RegisterR(0x02);
    sei();

    //define state variables
    static uint8_t HourAdd = 0, MinuteAdd = 0, HourState = 0, MinuteState = 0;
    //define working variables
    static uint8_t MinutesOnes = 0, MinutesTens = 0, HoursOnes = 0, HoursTens = 0;
    //define Bar variables
    static uint8_t DecMinutes = 0, DecHours = 0, IntLEDS = 0;
    static double FracHour = 0, FHours = 0, FracDay = 0, LEDS = 0;
    static uint32_t LIntLEDS = 0;//define 32 bit variable to hold number of LEDs to light up. This does impose a maximum of 32 LEDs. Given that this is intended to run directly off uC pins, this is not much of a limit, since the uC only has 28 pins total

    //separate digits from read values
    MinutesOnes = Minutes & 0x0F;
    MinutesTens = (Minutes & 0x70) >> 4;
    HoursOnes = Hours & 0x0F;
    HoursTens = (Hours & 0x30) >> 4;

    //merge ones and tens digits and convert to base 10
    DecMinutes = MinutesOnes + 10*MinutesTens;
    DecHours = HoursOnes + 10*HoursTens;

    //Calculate fraction of Day that has occured
    FracHour = (double)DecMinutes / (60.);
    FHours = (double)DecHours + FracHour;
    FracDay = FHours / (24.);
    
    //round to nearest LED
    LEDS = FracDay * (16.);//exact number of LEDs needed
    LEDS = round(LEDS);//round to nearest integer
    IntLEDS = (uint8_t)LEDS & 0xFF;//pull the bottom byte into a smaller variable
    LIntLEDS = ConvertToBar(IntLEDS);//convert number of LEDs needed to a string of "1"s in a 32 bit int
    
    //output to Bars
    #ifndef USESHIFTREGISTER
    PORTB = (LIntLEDS & 0xFF);
    PORTD = ((LIntLEDS >> 8) & 0xFF);
    #endif
{'fraction_non_alphanumeric': 0.10212352082995624, 'fraction_numerical': 0.04506402982655212, 'mean_word_length': 3.183050847457627, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4715218', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2102, 'n_words': 763}