Buttoneingabe hinzugefügt, mit Beispiel in main.c
Textausgabe-Beispiel jetzt mit Scrolling. Code aufgeräumt.master
parent
fdd4f774aa
commit
a908350b86
2
Makefile
2
Makefile
|
@ -84,7 +84,7 @@ OBJDIR = .
|
||||||
|
|
||||||
|
|
||||||
# List C source files here. (C dependencies are automatically generated.)
|
# List C source files here. (C dependencies are automatically generated.)
|
||||||
SRC = $(TARGET).c ht1632c.c
|
SRC = $(TARGET).c ht1632c.c util.c
|
||||||
|
|
||||||
|
|
||||||
# List C++ source files here. (C dependencies are automatically generated.)
|
# List C++ source files here. (C dependencies are automatically generated.)
|
||||||
|
|
|
@ -4,6 +4,7 @@ JY-MCU 3208 LED Matrix
|
||||||
Dieses Kit bietet die möglichkeit, die LED Matrix mit wenigen Befehlen einfach anzusteuern.
|
Dieses Kit bietet die möglichkeit, die LED Matrix mit wenigen Befehlen einfach anzusteuern.
|
||||||
Diese Befehle sind:
|
Diese Befehle sind:
|
||||||
|
|
||||||
|
## LED Matrix ##
|
||||||
* `MTX_init()`
|
* `MTX_init()`
|
||||||
Die LED Matrix initialisieren. Muss zu Anfang aufgerufen werden!
|
Die LED Matrix initialisieren. Muss zu Anfang aufgerufen werden!
|
||||||
* `MTX_update()`
|
* `MTX_update()`
|
||||||
|
@ -24,13 +25,19 @@ Diese Befehle sind:
|
||||||
Einen string an der Stelle (x, y) anzeigen.
|
Einen string an der Stelle (x, y) anzeigen.
|
||||||
|
|
||||||
|
|
||||||
|
## HT1632C Controller IC ##
|
||||||
Weiterhin können noch verwendet werden:
|
Weiterhin können noch verwendet werden:
|
||||||
|
|
||||||
* `ht1632c_setblink(bool on)`
|
* `ht1632c_setblink(bool on)`
|
||||||
Alle 0,5 Sekunden alle LEDs blinken (on = true aktivieren; on = false deaktivieren)
|
Alle 0,5 Sekunden alle LEDs blinken (on = true aktivieren; on = false deaktivieren)
|
||||||
* `ht1632c_setbrightness(uint8_t value)`
|
* `ht1632c_setbrightness(uint8_t value)`
|
||||||
Helligkeit des Displays setzen (maximal 15)
|
Helligkeit des Displays setzen (maximal 15)
|
||||||
|
|
||||||
|
## Buttons ##
|
||||||
|
* `button_init()`
|
||||||
|
Eingabe über die Buttons aktivieren. Muss unbedingt vor `button_get()` aufgerufen werden.
|
||||||
|
* `button_get()`
|
||||||
|
Status der Buttons abfragen. Die Buttons sind von oben nach unten mit BUTTON1, BUTTON2, BUTTON3 durchnummeriert. Beispiel: `if (button_get(BUTTON1)) {...}`.
|
||||||
|
|
||||||
#### Siehe main.c für Beispiele ####
|
#### Siehe main.c für Beispiele ####
|
||||||
Diese Bibliothek ist NICHT für den regulären Einsatz, sondern nur zum Erlernen der Programmierung einer LED Matrix geeignet.
|
Diese Bibliothek ist NICHT für den regulären Einsatz, sondern nur zum Erlernen der Programmierung einer LED Matrix geeignet.
|
||||||
Eine flexiblere Bibliothek findet sich z.B. [hier](https://github.com/vogelchr/avr-jy-mcu-3208).
|
Eine flexiblere Bibliothek findet sich z.B. [hier](https://github.com/vogelchr/avr-jy-mcu-3208).
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
/* Source: https://github.com/noccy80/mspdev/blob/master/lib430/src/liblcd/font5x8.h which
|
/* Source: https://github.com/noccy80/mspdev/blob/master/lib430/src/liblcd/font5x8.h which
|
||||||
is FLOSS according to the README */
|
is FLOSS according to the README */
|
||||||
|
|
||||||
static const PROGMEM uint8_t font5x8[][5] = {
|
static const PROGMEM uint8_t font5x8[][5] =
|
||||||
|
{
|
||||||
{0x00,0x00,0x00,0x00,0x00}, // 0x00 0
|
{0x00,0x00,0x00,0x00,0x00}, // 0x00 0
|
||||||
{0x64,0x18,0x04,0x64,0x18}, // 0x01 1
|
{0x64,0x18,0x04,0x64,0x18}, // 0x01 1
|
||||||
{0x3c,0x40,0x40,0x20,0x7c}, // 0x02 2
|
{0x3c,0x40,0x40,0x20,0x7c}, // 0x02 2
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#include "ht1632c.h"
|
#include "ht1632c.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <util/delay.h> // TODO
|
|
||||||
|
|
||||||
#define HT1632C_PORT PORTB
|
#define HT1632C_PORT PORTB
|
||||||
#define HT1632C_DDR DDRB
|
#define HT1632C_DDR DDRB
|
||||||
#define HT1632C_NCS PB3
|
#define HT1632C_NCS PB3
|
||||||
|
|
52
main.c
52
main.c
|
@ -1,4 +1,5 @@
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
#include "util.h"
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
|
|
||||||
uint8_t bitmap[] =
|
uint8_t bitmap[] =
|
||||||
|
@ -27,17 +28,60 @@ uint8_t bitmap[] =
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
MTX_init();
|
MTX_init();
|
||||||
|
button_init();
|
||||||
|
|
||||||
|
// "CAG"-Schriftzug als Bitmap
|
||||||
MTX_bitmap(bitmap, 7, 0, 19, 8);
|
MTX_bitmap(bitmap, 7, 0, 19, 8);
|
||||||
MTX_update();
|
MTX_update();
|
||||||
_delay_ms(5000);
|
_delay_ms(3000);
|
||||||
|
|
||||||
|
// "Hello" fährt von links rein
|
||||||
|
int8_t i;
|
||||||
|
for (i = -31; i<=1; i++)
|
||||||
|
{
|
||||||
MTX_clear();
|
MTX_clear();
|
||||||
MTX_putstring("Hello", 0, 0);
|
MTX_putstring("Hello", i, 0);
|
||||||
MTX_update();
|
MTX_update();
|
||||||
_delay_ms(5000);
|
_delay_ms(30);
|
||||||
|
}
|
||||||
|
_delay_ms(1000);
|
||||||
|
|
||||||
uint8_t i;
|
// "World" fährt von rechts rein
|
||||||
|
for (i = 31; i>=1; i--)
|
||||||
|
{
|
||||||
|
MTX_clear();
|
||||||
|
MTX_putstring("World", i, 0);
|
||||||
|
MTX_update();
|
||||||
|
_delay_ms(30);
|
||||||
|
}
|
||||||
|
_delay_ms(1000);
|
||||||
|
|
||||||
|
// Button: Eingabe-Test
|
||||||
|
for (i = 0; i<100; i++)
|
||||||
|
{
|
||||||
|
MTX_clear();
|
||||||
|
if (button_get(BUTTON1))
|
||||||
|
{
|
||||||
|
MTX_line(0, 6, 31, 6, true);
|
||||||
|
MTX_line(0, 7, 31, 7, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button_get(BUTTON2))
|
||||||
|
{
|
||||||
|
MTX_line(0, 3, 31, 3, true);
|
||||||
|
MTX_line(0, 4, 31, 4, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button_get(BUTTON3))
|
||||||
|
{
|
||||||
|
MTX_line(0, 0, 31, 0, true);
|
||||||
|
MTX_line(0, 1, 31, 1, true);
|
||||||
|
}
|
||||||
|
MTX_update();
|
||||||
|
_delay_ms(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Endloser roter Streifen
|
||||||
bool positive = true;
|
bool positive = true;
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
|
38
matrix.h
38
matrix.h
|
@ -5,6 +5,7 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "font5x8.h"
|
#include "font5x8.h"
|
||||||
|
|
||||||
|
// Framebuffer: Contains all data displayed on the matrix screen
|
||||||
uint8_t fb[32];
|
uint8_t fb[32];
|
||||||
|
|
||||||
void MTX_clear(void)
|
void MTX_clear(void)
|
||||||
|
@ -19,25 +20,35 @@ void MTX_update(void)
|
||||||
ht1632c_flip(fb);
|
ht1632c_flip(fb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MTX_dot(uint8_t x, uint8_t y, bool positive)
|
void MTX_dot(int8_t x, int8_t y, bool positive)
|
||||||
{
|
{
|
||||||
|
if (x < 0 || y < 0 || x > 31 || y > 7) return;
|
||||||
if (positive) sbi(fb[x], y);
|
if (positive) sbi(fb[x], y);
|
||||||
else cbi(fb[x], y);
|
else cbi(fb[x], y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* http://de.wikipedia.org/wiki/Bresenham-Algorithmus */
|
/* http://de.wikipedia.org/wiki/Bresenham-Algorithmus */
|
||||||
void MTX_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, bool positive)
|
void MTX_line(int8_t x0, int8_t y0, int8_t x1, int8_t y1, bool positive)
|
||||||
{
|
{
|
||||||
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
|
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
|
||||||
int dy = -abs(y1-y0), sy = y0<y1 ? 1 : -1;
|
int dy = -abs(y1-y0), sy = y0<y1 ? 1 : -1;
|
||||||
int err = dx+dy, e2; /* error value e_xy */
|
int err = dx+dy, e2; /* error value e_xy */
|
||||||
|
|
||||||
for(;;){ /* loop */
|
for(;;)
|
||||||
|
{
|
||||||
MTX_dot(x0,y0,positive);
|
MTX_dot(x0,y0,positive);
|
||||||
if (x0==x1 && y0==y1) break;
|
if (x0==x1 && y0==y1) break;
|
||||||
e2 = 2*err;
|
e2 = 2*err;
|
||||||
if (e2 > dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
|
if (e2 > dy)
|
||||||
if (e2 < dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
|
{
|
||||||
|
err += dy; /* e_xy+e_x > 0 */
|
||||||
|
x0 += sx;
|
||||||
|
}
|
||||||
|
if (e2 < dx)
|
||||||
|
{
|
||||||
|
err += dx; /* e_xy+e_y < 0 */
|
||||||
|
y0 += sy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,26 +64,21 @@ void MTX_bitmap(uint8_t *bitmap, uint8_t destx, uint8_t desty, uint8_t bitmapx,
|
||||||
uint8_t x, y;
|
uint8_t x, y;
|
||||||
for (x = 0; x < bitmapx; x++)
|
for (x = 0; x < bitmapx; x++)
|
||||||
for (y = 0; y < bitmapy; y++)
|
for (y = 0; y < bitmapy; y++)
|
||||||
{
|
MTX_dot(destx+x,desty+y,gbi(bitmap[x], (bitmapy-y-1)));
|
||||||
if (gbi(bitmap[x], (bitmapy-y-1)))
|
|
||||||
sbi(fb[destx+x], (desty+y));
|
|
||||||
else
|
|
||||||
cbi(fb[destx+x], (desty+y));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MTX_putchar(char c, uint8_t x, uint8_t y)
|
void MTX_putchar(char c, int8_t x, int8_t y)
|
||||||
{
|
{
|
||||||
uint8_t bitmap[5];
|
uint8_t bitmap[5];
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
for (i = 0; i<5; i++)
|
for (i = 0; i<5; i++)
|
||||||
bitmap[i] = pgm_read_byte(&(font5x8[(uint8_t)c][i]));
|
bitmap[i] = pgm_read_byte(&(font5x8[(uint8_t)c][i]));
|
||||||
MTX_bitmap(bitmap, x, y, 5, 8);
|
MTX_bitmap(bitmap, x, y-1, 5, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MTX_putstring(char *string, uint8_t x, uint8_t y)
|
void MTX_putstring(char *string, int8_t x, int8_t y)
|
||||||
{
|
{
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
while(string[i] != 0x00)
|
for (i = 0; string[i] != 0x00; i++)
|
||||||
MTX_putchar(string[i++], x+6*i, y);
|
MTX_putchar(string[i], x+6*i, y);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
void button_init(void)
|
||||||
|
{
|
||||||
|
cbi(BUTTON_DDR, BUTTON1);
|
||||||
|
cbi(BUTTON_DDR, BUTTON2);
|
||||||
|
cbi(BUTTON_DDR, BUTTON3);
|
||||||
|
|
||||||
|
sbi(BUTTON_PORT, BUTTON1);
|
||||||
|
sbi(BUTTON_PORT, BUTTON2);
|
||||||
|
sbi(BUTTON_PORT, BUTTON3);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool button_get(enum BUTTON b)
|
||||||
|
{
|
||||||
|
return !gbi(BUTTON_PIN, b);
|
||||||
|
}
|
22
util.h
22
util.h
|
@ -1,3 +1,9 @@
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifndef _UTIL_H
|
||||||
|
#define _UTIL_H
|
||||||
|
|
||||||
// Modify single bits in registers / bytes
|
// Modify single bits in registers / bytes
|
||||||
#define sbi(ADDR, BIT) ((ADDR |= (1<<BIT)))
|
#define sbi(ADDR, BIT) ((ADDR |= (1<<BIT)))
|
||||||
#define cbi(ADDR, BIT) ((ADDR &= ~(1<<BIT)))
|
#define cbi(ADDR, BIT) ((ADDR &= ~(1<<BIT)))
|
||||||
|
@ -6,3 +12,19 @@
|
||||||
|
|
||||||
// Sleep 1 cycle
|
// Sleep 1 cycle
|
||||||
#define nop() asm volatile ("nop")
|
#define nop() asm volatile ("nop")
|
||||||
|
|
||||||
|
#define BUTTON_DDR DDRD
|
||||||
|
#define BUTTON_PORT PORTD
|
||||||
|
#define BUTTON_PIN PIND
|
||||||
|
|
||||||
|
enum BUTTON
|
||||||
|
{
|
||||||
|
BUTTON1 = PD7,
|
||||||
|
BUTTON2 = PD6,
|
||||||
|
BUTTON3 = PD5
|
||||||
|
};
|
||||||
|
|
||||||
|
void button_init(void);
|
||||||
|
bool button_get(enum BUTTON b);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue