Guest User

Untitled

a guest
Apr 28th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. /*
  2. 5x7test.cpp --- led matrix example
  3.  
  4. P1.0 - P1.4 .. low to high pins for columns
  5. P2.0 - P2.6 .. low to high pins for rows
  6.  
  7. This example code is in the public domain.
  8. */
  9.  
  10. #define F_CPU 16000000
  11.  
  12. #include <fabooh.h>
  13. #include <fabooh.ipp>
  14. #include <DigitalIO.ipp>
  15.  
  16. using namespace fabooh;
  17.  
  18. const uint8_t rowPins[] = { 8, 9, 10, 11, 12, 13, 14 };
  19.  
  20. void setup() {
  21. int n = 0;
  22. for (n = 0; n < 6; ++n) {
  23. pinMode(n, OUTPUT);
  24. digitalWrite(n, HIGH);
  25. }
  26.  
  27. for (n = 0; n < 7; ++n) {
  28. pinMode(rowPins[n], OUTPUT);
  29. digitalWrite(rowPins[n], LOW);
  30. }
  31.  
  32. P2SEL &= ~(BIT6|BIT7);
  33. }
  34.  
  35. // 5x7 numeric characters from X11
  36. // note we only have 7 rows per but we pad to 8 so
  37. // the code runs faster
  38.  
  39. const uint8_t glyphs[] = {
  40. //0030:20505050502000
  41. 0x00, 0x2, 0x5, 0x5, 0x5, 0x5, 0x2,0,
  42. //0031:20602020207000
  43. 0x0, 0x2, 0x6, 0x2, 0x2, 0x2, 0x7, 0,
  44. //0032:6090102040F000
  45. 0x0, 0x6, 0x9, 0x1, 0x2, 0x4, 0xF, 0,
  46. //0033:F0106010906000
  47. 0x0, 0xF, 0x1, 0x6, 0x1, 0x9, 0x6, 0,
  48. //0034:2060A0F0202000
  49. 0x0, 0x2, 0x6, 0xA, 0xF, 0x2, 0x2, 0,
  50. //0035:F080E010906000
  51. 0x0, 0xF, 0x8, 0xE, 0x1, 0x9, 0x6, 0,
  52. //0036:6080E090906000
  53. 0x0, 0x6, 0x8, 0xE, 0x9, 0x9, 0x6, 0,
  54. //0037:F0102020404000
  55. 0x0, 0xF, 0x1, 0x2, 0x2, 0x4, 0x4, 0,
  56. //0038:60906090906000
  57. 0x0, 0x6, 0x9, 0x6, 0x9, 0x9, 0x6, 0,
  58. //0039:60909070106000
  59. 0x0, 0x6, 0x9, 0x9, 0x7, 0x1, 0x6, 0,
  60. };
  61.  
  62. void loop() {
  63. int n, j;
  64.  
  65. int num = 9;
  66. unsigned long nextTime = millis() + 250;
  67.  
  68. while (true) {
  69. for (n = 0; n < 7; ++n) {
  70. digitalWrite(rowPins[n], HIGH); // set the LED on
  71. // toggle the columns values for each row
  72. // driving the column pin low lets the current flow
  73. // from the row pin, we have cathode columns and anode rows
  74. P1OUT &= ~glyphs[ (num * 8) + n ];
  75. __delay_cycles(32653); // 1/7th /70Hz when running at 16Mhz
  76. P1OUT |= 0x1F;
  77. digitalWrite(rowPins[n], LOW); // set the LED on
  78. }
  79.  
  80. // countdown every 250 ms
  81. if (millis() > nextTime) {
  82. nextTime = millis() + 250;
  83. if (--num < 0)
  84. num = 9;
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment