- /*
- 5x7test.cpp --- led matrix example
- P1.0 - P1.4 .. low to high pins for columns
- P2.0 - P2.6 .. low to high pins for rows
- This example code is in the public domain.
- */
- #define F_CPU 16000000
- #include <fabooh.h>
- #include <fabooh.ipp>
- #include <DigitalIO.ipp>
- using namespace fabooh;
- const uint8_t rowPins[] = { 8, 9, 10, 11, 12, 13, 14 };
- void setup() {
- int n = 0;
- for (n = 0; n < 6; ++n) {
- pinMode(n, OUTPUT);
- digitalWrite(n, HIGH);
- }
- for (n = 0; n < 7; ++n) {
- pinMode(rowPins[n], OUTPUT);
- digitalWrite(rowPins[n], LOW);
- }
- P2SEL &= ~(BIT6|BIT7);
- }
- // 5x7 numeric characters from X11
- // note we only have 7 rows per but we pad to 8 so
- // the code runs faster
- const uint8_t glyphs[] = {
- //0030:20505050502000
- 0x00, 0x2, 0x5, 0x5, 0x5, 0x5, 0x2,0,
- //0031:20602020207000
- 0x0, 0x2, 0x6, 0x2, 0x2, 0x2, 0x7, 0,
- //0032:6090102040F000
- 0x0, 0x6, 0x9, 0x1, 0x2, 0x4, 0xF, 0,
- //0033:F0106010906000
- 0x0, 0xF, 0x1, 0x6, 0x1, 0x9, 0x6, 0,
- //0034:2060A0F0202000
- 0x0, 0x2, 0x6, 0xA, 0xF, 0x2, 0x2, 0,
- //0035:F080E010906000
- 0x0, 0xF, 0x8, 0xE, 0x1, 0x9, 0x6, 0,
- //0036:6080E090906000
- 0x0, 0x6, 0x8, 0xE, 0x9, 0x9, 0x6, 0,
- //0037:F0102020404000
- 0x0, 0xF, 0x1, 0x2, 0x2, 0x4, 0x4, 0,
- //0038:60906090906000
- 0x0, 0x6, 0x9, 0x6, 0x9, 0x9, 0x6, 0,
- //0039:60909070106000
- 0x0, 0x6, 0x9, 0x9, 0x7, 0x1, 0x6, 0,
- };
- void loop() {
- int n, j;
- int num = 9;
- unsigned long nextTime = millis() + 250;
- while (true) {
- for (n = 0; n < 7; ++n) {
- digitalWrite(rowPins[n], HIGH); // set the LED on
- // toggle the columns values for each row
- // driving the column pin low lets the current flow
- // from the row pin, we have cathode columns and anode rows
- P1OUT &= ~glyphs[ (num * 8) + n ];
- __delay_cycles(32653); // 1/7th /70Hz when running at 16Mhz
- P1OUT |= 0x1F;
- digitalWrite(rowPins[n], LOW); // set the LED on
- }
- // countdown every 250 ms
- if (millis() > nextTime) {
- nextTime = millis() + 250;
- if (--num < 0)
- num = 9;
- }
- }
- }