Advertisement
nubideus

Untitled

Mar 5th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1. #
  2. include < avr / sfr_defs.h > #include < avr / iom128.h > #include < avr / io.h > #include < string.h > #define CELL_OFF 0x00# define SEGMENT_A# define SEGMENT_B# define SEGMENT_C# define SEGMENT_D# define SEGMENT_E# define SEGMENT_F# define SEGMENT_G# define SEGMENT_H# define SYMBOL_Br(SEGMENT_A | SEGMENT_C | SEGMENT_D | SEGMENT_E | SEGMENT_F | SEGMENT_G)# define SYMBOL_Gr(SEGMENT_A | SEGMENT_E | SEGMENT_F)# define SYMBOL_Ur(SEGMENT_B | SEGMENT_C | SEGMENT_D | SEGMENT_F | SEGMENT_G)# define SYMBOL_Ir(SEGMENT_B | SEGMENT_C | SEGMENT_D | SEGMENT_E | SEGMENT_F)# define SYMBOL_Rr(SEGMENT_A | SEGMENT_B | SEGMENT_E | SEGMENT_F | SEGMENT_G)# define TOGGLE_CLK()(PORTC |= _BV(PC3), \
  3.   PORTC &= ~_BV(PC3))# define STRING_RUN_PERIOD 3000
  4. static uint8_t aunVideoMemory[] = {
  5.   0,
  6.   0,
  7.   0,
  8.   0,
  9.   0,
  10.   0,
  11.   0,
  12.   0
  13. };
  14. static uint8_t aunRunningString[] = {
  15.   0,
  16.   0,
  17.   0,
  18.   0,
  19.   0,
  20.   0,
  21.   0,
  22.   0,
  23.   SYMBOL_Rr,
  24.   SYMBOL_Ir,
  25.   SYMBOL_Ur,
  26.   SYMBOL_Gr,
  27.   SYMBOL_Br,
  28.   0,
  29.   0,
  30.   0,
  31.   0,
  32.   0,
  33.   0,
  34.   0,
  35.   0,
  36. };
  37. const uint8_t unVMSize = sizeof(aunVideoMemory) / sizeof(uint8_t);
  38. const uint8_t unRSSize = sizeof(aunRunningString) / sizeof(uint8_t);
  39. int main(void) {
  40.   uint8_t unDispCell = 0;
  41.   int32_t nDelayIn, nDelayOut;
  42.   int16_t nSymbol = 0;
  43.   DDRA = _BV(DDA0) | _BV(DDA1) | \
  44.     _BV(DDA2) | _BV(DDA3) | \
  45.     _BV(DDA4) | _BV(DDA5) | \
  46.     _BV(DDA6) | _BV(DDA7);
  47.   DDRC = _BV(DDC0) | _BV(DDC1) | \
  48.     _BV(DDC2) | _BV(DDC3);
  49.   while (1) {
  50.     nDelayOut = STRING_RUN_PERIOD;
  51.     memcpy(aunVideoMemory, aunRunningString + nSymbol, unVMSize);
  52.     while (--nDelayOut > 0) {
  53.       PORTC = unDispCell;
  54.       PORTA = ~(aunVideoMemory[unDispCell++]);
  55.       unDispCell %= unVMSize;
  56.       TOGGLE_CLK();
  57.       for (nDelayIn = 0; nDelayIn < 5; nDelayIn++);
  58.       PORTA = ~CELL_OFF;
  59.       TOGGLE_CLK();
  60.     }
  61.     if (--nSymbol < 0) {
  62.       nSymbol = (unRSSize - unVMSize);
  63.     }
  64.   }
  65.   return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement