2_Digit-7_seg_ohneTreiber

Dependencies:   mbed

main.cpp

Committer:
04M04
Date:
2016-04-13
Revision:
0:90237d7d06ae

File content as of revision 0:90237d7d06ae:

#include "mbed.h"

// Nr.                               a b c d  e f g t
// --------------------------------------------------
#define D_0 (0xfc)  // 0             1 1 1 1  1 1 0 0
#define D_1 (0x60)  // 1             0 1 1 0  0 0 0 0
#define D_2 (0xda)  // 2             1 1 0 1  1 0 1 0
#define D_3 (0xf2)  // 3             1 1 1 1  0 0 1 0
#define D_4 (0x66)  // 4             0 1 1 0  0 1 1 0
#define D_5 (0xb6)  // 5             1 0 1 1  0 1 1 0
#define D_6 (0xbe)  // 6             1 0 1 1  1 1 1 0
#define D_7 (0xe4)  // 7             1 1 1 0  0 1 0 0
#define D_8 (0xfe)  // 8             1 1 1 1  1 1 1 0
#define D_9 (0xf6)  // 9             1 1 1 1  0 1 1 0
#define D_AUS (0x00)// Aus           0 0 0 0  0 0 0 0       

BusOut myled(p28,p27,p26,p25,p24,p23,p22,p21);
DigitalOut CC1(p29);
DigitalOut CC2(p30);
DigitalOut L1(LED1);
DigitalOut L2(LED2);
Serial pc(USBTX, USBRX);

int t = 10;
int ta = 1;
int i = 24;
int j = 1;
int k = 1;

void berechnen()
{
    j=i/10;
    k=(i-(j*10))/1;
    i= 0;
}

void TimerAnzeige()
{
    CC1 = 1;
    CC2 = 0;
    myled = D_AUS;
    wait_us(ta);
    myled = k;
    wait_us(t);

    CC1 = 0;
    CC2 = 1;
    myled = D_AUS;
    wait_us(ta);
    myled = j;
    wait_us(t);
}

void wandler()
{
    if(j == 0)
        j = D_0;
    if(j == 1)
        j = D_1;
    if(j == 2)
        j = D_2;
    if(j == 3)
        j = D_3;
    if(j == 4)
        j = D_4;
    if(j == 5)
        j = D_5;
    if(j == 6)
        j = D_6;
    if(j == 7)
        j = D_7;
    if(j == 8)
        j = D_8;
    if(j == 9)
        j = D_9;
        
    if(k == 0)
        k = D_0;
    if(k == 1)
        k = D_1;
    if(k == 2)
        k = D_2;
    if(k == 3)
        k = D_3;
    if(k == 4)
        k = D_4;
    if(k == 5)
        k = D_5;
    if(k == 6)
        k = D_6;
    if(k == 7)
        k = D_7;
    if(k == 8)
        k = D_8;
    if(k == 9)
        k = D_9;
}

int main()
{
    while(1) {
        berechnen(); 
        wandler();
        /*pc.printf("Timer Zeit: ");
        pc.scanf("%d \n\r",&i);
        berechnen(); 
        pc.printf("i = %d\n\rj = %d\n\rk = %d\n\r",i,j,k);
        wandler();*/
        while(1) {
            TimerAnzeige();
        }
    }
}