//////////////////////////////////////////////////////
// Mokhtar Zerdali 2022. ATtiny85 oled ssd1306 I2c interface
// Attiny85 PINS
#include<avr/io.h>
#include <TinyWireM.h> // I2C library
#define TINY4KOLED_QUICK_BEGIN
#include <Tiny4kOLED.h> // this library uses the same interrupt such ISR timer0_vect
//such library is compatible for I2C interface
// Oled to ATtiny85 Pins
#define SCL PB3// Oled pin D0 I/O ATtiny 85 =PB4
#define SDA PB4// Oled pin D1 I/O ATtiny 85 =PB1
int address = 0x3C;
#define DS1621_ADDR 0x48
/////////////////////////////////////////////
#define F_CPU 8000000UL
volatile unsigned long Countclk;
volatile unsigned long Overflowprb;
volatile unsigned long Time;
//////Oled SSD1306 code////////
void Oleddisplay_setup()
{
//pinMode(SDA, INPUT); //data Pin input
oled.begin(128, 32, sizeof(tiny4koled_init_128x32br), tiny4koled_init_128x32br);
/// Two fonts are supplied with this library, FONT8X16 and FONT6X8
oled.setFont(FONT8X16); // (FONT8X16) (FONT6X8)
/// To clear all the memory
oled.clear();
oled.on();
//oled.fill(0xFF);
oled.setCursor(1, 0);
oled.print (("ATtiny SSD1306"));
// oled.setCursor(1, 10);
//oled.print(F("---------------------"));
}
/////////////////////////////////////////
void setup() // Registers configuration
{
DDRB = (1 << PB5) | (1 << PB4);
TCCR0A = 0X00; //TCCR0A to low for normal port operation and mode 0.
TCCR0B = 0X00; //WGM02=0
TCNT0 = 0; //initializing the counter to 0
//TIMSK = bit (TOIE0); //|= (1 << TOIE0); //enabling overflow >255 interrupts of timer0
TIMSK = bit (OCIE0B); //|= (1 << TOIE0); //enabling overflow >255 interrupts from compB
OCR0B = 0xFF; //valeur max 255 to compare with TCNT0
sei(); //enabling global interrupt
}
void Pulse_RB() // pulse rate beat program
{
Overflowprb = 0;
TCCR0B |= (1 << CS00); //No prescaling clk
// Mode sense of MCUCR Register to choose the adequate sense
MCUCR = (1 << ISC01); //3/ FALLING mode sense
//MCUCR = bit(ISC01) | bit(ISC00); //4// RISING mode sense
}
ISR (TIMER0_COMPB_vect) //Interrupt vector for Timer0 by
//comparing the register bit TCNT0 to OCR0B=0xFF
{
{
Overflowprb++; // count number of overflow
}
}
// End of TIMER0_OVF_vect
void display_test()
{
oled.fill(0xFF);
// Swap which half of RAM is being written to, and which half is being displayed
// This is equivalent to calling both switchRenderFrame and switchDisplayFrame
//oled.switchFrame();
//delay(1000);
}
int main()
{
Oleddisplay_setup();
setup();
Pulse_RB();
while (1)
{
Countclk = TCNT0 + (Overflowprb << 8); //n° overflow*256
Time = 0.000125 * Countclk; // 8MHz ; clk : 125 ns.
oled.begin();
oled.setCursor(1, 10) ; // Column / Line couple
oled.print("Clk:");
oled.print(Time, 1);
oled.print("ms");
PORTB = 0b00010000;
//oled.print(millis());
}
}