blob: ba1be8d8c103536294fe61b4d5172128aa7d378b (
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
55
56
|
#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 (int v)
{
// 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 pio = 0;
// show negative with DP
if (v < 0)
{
pio |= 0x80;
v = -v;
}
if (v > 9)
v = 9;
pio |= lookup[v];
pio_write (pio);
}
int
main (void)
{
int i;
printf ("Working...\n");
for (;;) {
for (i=-9;i<10;++i) {
printf("Showing %d\n",i);
show(i);
msleep(1000);
}
}
}
|