daeun

a

1 +#include <wiringPi.h>
2 +#include <stdio.h>
3 +#include <stdlib.h>
4 +
5 +const int FndSelectPin[6] = { 4, 17, 18, 27, 22, 23 };
6 +const int FndPin[8] = { 6, 12, 13, 16, 19, 20, 26, 21 };
7 +const int FndFont[10] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66,
8 + 0x6D, 0x7D, 0x07, 0x7F, 0x67 };
9 +
10 +void init(){
11 + int i;
12 + if( wiringPiSetupGpio() == -1 ){
13 + printf( "wiringPiSetupGpio() error\n" );
14 + exit(-1);
15 + }
16 + for(i=0;i<6;i++){
17 + pinMode( FndSelectPin[i], OUTPUT );
18 + digitalWrite( FndSelectPin[i], HIGH );
19 + }
20 + for(i=0;i<8;i++){
21 + pinMode( FndPin[i], OUTPUT );
22 + digitalWrite( FndPin[i], LOW );
23 + }
24 +}
25 +void FndSelect(int position){
26 + int i;
27 + for(i=0;i<6;i++){
28 + if(i==position){
29 + digitalWrite(FndSelectPin[i],LOW);
30 + }
31 + else{
32 + digitalWrite(FndSelectPin[i],HIGH);
33 + }
34 + }
35 +}
36 +void FndDisplay(int position, int num){
37 + int i,number;
38 + int flag=0;
39 + int shift=0x01;
40 + number=FndFont[num];
41 + if(position==2)
42 + number|=0x80;
43 +
44 + for(i=0;i<8;i++){
45 + flag=(number&shift);
46 + digitalWrite(FndPin[i], flag);
47 + shift<<=1;
48 + }
49 + FndSelect(position);
50 +}
51 +int main(){
52 + int pos;
53 + int time=0;
54 + init();
55 + unsigned long prevtime=millis();
56 + while(1){
57 + unsigned long curtime=millis();
58 + if(curtime-prevtime > 10){
59 + prevtime=curtime;
60 + time++;
61 + }
62 + int data[6]={time%10, (time%100)/10, (time%1000)/100,
63 + (time/1000)%10, (time/10000)%10, time/100000};
64 + for(pos=0;pos<6;pos++){
65 + FndDisplay(pos,data[pos]);
66 + delay(1);
67 + }
68 + }
69 + return 0;
70 +}
...\ No newline at end of file ...\ No newline at end of file