lab2-4-1.c
1.2 KB
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
57
58
59
60
61
62
63
64
65
66
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
const int FndSelectPin[6] = { 4, 17, 18, 27, 22, 23 };
const int FndPin[8] = { 6, 12, 13, 16, 19, 20, 26, 21 };
const int FndFont[6] = { 0x00, 0x76, 0x79, 0x38, 0x38, 0x3F };
void init(){
int i;
if( wiringPiSetupGpio() == -1 ){
printf( "wiringPiSetupGpio() error\n" );
exit(-1);
}
for(i=0;i<6;i++){
pinMode( FndSelectPin[i], OUTPUT );
digitalWrite( FndSelectPin[i], HIGH );
}
for(i=0;i<8;i++){
pinMode( FndPin[i], OUTPUT );
digitalWrite( FndPin[i], LOW );
}
}
void FndSelect(int position){
int i;
for(i=0;i<6;i++){
if(i==position){
digitalWrite(FndSelectPin[i],LOW);
}
else{
digitalWrite(FndSelectPin[i],HIGH);
}
}
}
void FndDisplay(int position, int num){
int i;
int flag=0;
int shift=0x01;
for(i=0;i<8;i++){
flag=(FndFont[num]&shift);
digitalWrite(FndPin[i], flag);
shift<<=1;
}
FndSelect(position);
}
int main(){
int pos;
int data[6]={5,4,3,2,1,0};
init();
int i=0;
unsigned long prevtime=millis();
while(1){
unsigned long curtime=millis();
if(curtime-prevtime > 500){
i+=1;
i=i%6;
prevtime=curtime;
}
for(pos=0;pos<6;pos++){
FndDisplay((pos+i)%6,data[pos]);
delay(1);
}
}
return 0;
}