/* ------------------------------------------------------------------ ht16k33_demo.c Demo fuer die Verwendung eines HT16K33 LED-Treibers mit I2C- Interface. Hier fuer Anschluss mit max. 8-Digits MCU : CH32V003 Takt : 13.05.2025 R. Seelig ------------------------------------------------------------------ */ /* CH32V003 A4M6 CH32V003F4P6 +-----------+ +--------------+ PC1 / sda |1 C 16| PC0 PD4 / a7 | 1 20 | PD3 / a4 PC2 / scl |2 H 15| Vdd PD5 / a5 / utx | 2 C 19 | PD2 / a3 PC3 |3 3 14| gnd PD6 / a6 / urx | 3 H 18 | PD1 / swio PC4 |4 2 13| PA2 / osc0 / a0 nrst / PD7 | 4 3 17 | PC7 / miso PC6 / mosi |5 V 12| PA1 / osc1 / a1 PA1 / osc0 / a0 | 5 2 16 | PC6 / mosi PC7 / miso |6 0 11| nrst / PD7 PA2 / osc1 / a1 | 6 V 15 | PC5 / sck / scl PD1 / swio |7 0 10| PD6 / a6 / urx gnd | 7 0 14 | PC4 / a2 PD4 / a7 |8 3 9| PD5 / a5 / utx PD0 | 8 0 13 | PC3 +-----------+ Vdd | 9 3 12 | PC2 / scl PC0 | 10 11 | PC1 / sda +--------------+ */ #include #include "ch32fun.h" #include "ch32v003_gpio.h" #include "ht16k33.h" #define laufanz 12 // Laufmuster fuer ein Lauflicht auf einer 4 stelligen 7-Segmentanzeige // LSB beinhaltet das Bitmap des Digits, MSB die // Adresse des Digits uint16_t laufmust[laufanz] = { 0x0601, 0x0401, 0x0201, 0x0001, 0x0002, 0x0004, 0x0008, 0x0208, 0x0408, 0x0608, 0x0610, 0x0620 }; /* ------------------------------------------------------- main ------------------------------------------------------- */ int main(void) { uint16_t cx; uint8_t i; uint16_t val; uint8_t lloops; SystemInit(); i2c_master_init(); ht16k_init(); while(1) { // Lauflichtausgabe lloops= 0; do { for (i= 0; i< laufanz; i++) { // Anzeige loeschen for (cx= 0; cx< 4; cx++) { ht16k_wr2ram(0, cx << 1); } val= laufmust[i]; ht16k_wr2ram(val & 0x00ff, val >> 8); delay(50); } lloops++; } while(lloops < 2); // Hexadezimale Zahl mit "dunkelster" Anzeige ausgeben ht16k_setbrightness(0); ht16k_sethex(0xabcd,0,0); // und diese Aufblenden delay(500); for (i= 0; i< 15; i++) { ht16k_setbrightness(i); delay(100); } delay(1000); // Zaehler for (cx= 990; cx < 1101; cx++) { // Dezimalzahlenausgabe, rechtsbuendig (pos= 0); Unterdrueckung fuehrender Nullen ht16k_setdez(cx,0,1); // Anzeige Dezimalpunkt (eine Kommastelle) ht16k_setdp(1,1); delay(100); } delay(1000); } }