summaryrefslogtreecommitdiff
path: root/tests/projects/embed/c51/hello/src/main.c
blob: 1106b33dabae870f6c0a532beab4423ce01859ed (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
#include <reg52.h>

#define REP(i, j) for(i = 0; i < j; ++i)
sbit control = P3 ^ 2;

void delay_ms(unsigned int n) {
    unsigned int i, j;
    for (j = n; j > 0; j--)
        for (i = 112; i > 0; i--);
}


int i;

void set(unsigned int x) {
    P1 = x;
    delay_ms(100);
}

void left_fill() {
    REP(i, 8) set(0xFF >> i);
}

void right_fill() {
    REP(i, 8) set((0xFF >> (7 - i)) ^ 0xFF);
}

void left_erase() {
    REP(i, 8) set((0xFF >> (7 - i)));
}

void right_erase() {
    REP(i, 8) set((0xFF >> i) ^ 0xFF);
}

int main() {
    P1 = 0xFF;
    P3 = 0xFF;
    while (1) {
        if (control == 0) {
            left_fill();
            left_erase();
            right_fill();
            right_erase();
        } else {
            set(0x55);
            set(0xAA);
        }
    }
}