ATTiny85 4 all chars — ATtiny85 simulation

An interactive ATtiny85 circuit simulation you can run free in your browser on Velxio, by ian7171.

Components

Sketch code

#define F_CPU 8000000UL // Is slower than the CPU but for this is fine

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <stdint.h>
#include "functions.h"
#include "font_data.h"

const uint8_t glyph_H[5] PROGMEM =
{
    0x7F, 0x08, 0x08, 0x08, 0x7F
};

const uint8_t glyph_E[5] PROGMEM =
{
    0x7F, 0x49, 0x49, 0x49, 0x41
};

const uint8_t glyph_L[5] PROGMEM =
{
    0x7F, 0x40, 0x40, 0x40, 0x40
};

const uint8_t glyph_O[5] PROGMEM =
{
    0x3E, 0x41, 0x41, 0x41, 0x3E
};


/* =========================================================
   PRINT ONE GLYPH
   ========================================================= */

static void oled_glyph(const uint8_t *glyph)
{
    oled_data_start();

    for (uint8_t i = 0; i < 5; i++)
    {
        uint8_t b =
            pgm_read_byte(&glyph[i]);

        usi_write_byte(b);
    }

    usi_write_byte(0x00);

    oled_data_stop();
}


static void oled_putc(char c)
{
    if (c < 32 || c > 126)
        c = '?';

    uint16_t offset = ((uint8_t)c - 32) * 5;

    oled_data_start();

    for (uint8_t i = 0; i < 5; i++)
    {
        uint8_t b = pgm_read_byte(&font5x7[offset + i]);
        usi_write_byte(b);
    }

    /* one blank column between characters */
    usi_write_byte(0x00);

    oled_data_stop();
}




//static void print_to_oled(const char *format)
//{
  //  char c;

  //  while ((c = pgm_read_byte(format++)))
   // {
     //       oled_putc(c);

      //  }
    

//}



int main(void)
{
    usi_i2c_init(); // Set up AT85 SCL and SDA to USI
    oled_init(); // Init the OLED
    oled_clear(); // Clear the screen


    oled_cursor(10, 2); // Set the display position on the oled column, page


    oled_putc('H');

//print_to_oled(PSTR("Ian")); // PSTR means the fixed text is stored in FLASH rather than consuming SRAM.


    oled_glyph(glyph_H);   
    oled_glyph(glyph_E);
    oled_glyph(glyph_L);
    oled_glyph(glyph_L);
    oled_glyph(glyph_O);


    while (1)
    {
    }

    return 0;
}

More projects by ian7171