summaryrefslogtreecommitdiffstats
path: root/src/sdram.c
blob: 60b94598a5b1e14ea5e6bfdf4ee02f33753189de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <io.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "system.h"


#define msleep(msec) usleep(1000*msec);

pio_write (unsigned int data)
{
  IOWR (PIO_0_BASE, 0, data);
}


static void
show_score (int score)
{
  // int to seven segment lookup: MSB dp g f e d c b a LSB
  const uint8_t lookup[10] =
    { 0x3F, 0x6, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x7, 0x7F, 0x6F };

  uint8_t ss = 0;

  // show negative with DP
  if (score < 0)
    {
      ss |= 0x80;
      score = -score;
    }

  if (score > 9)
    score = 9;

  ss |= lookup[score];

  pio_write (ss);
}
int
main (void)
{
  int i;
  printf ("Working...\n");
  for (;;) {
  for (i=-9;i<10;++i)
  {
  printf("%d\n",i);
  show_score(i);
  msleep(200);
  }
 }
}