etwas kürzen
-
Hallo, ich habe ein Programm das 2 funktionen hat. Es soll Anzeigen (per 7 segment LED Anzeige) welcher wert in der Datei (0-99) steht. Wenn mindestens 1 da ist soll eine andere LED Blinken und bei mindestens 2 sollen 2 LEDs Blinken.
es Funktioniert auch soweit ganz gut nur finde ich es so etwas Umständlich oder?
Vielleicht kann mir ja jemand einen Tip geben wies leichter geht
Mit freundlichen Grüßen LoZe
#include <stdio.h> #include <conio.h> #include <windows.h> #define LPT1 0x378 #define LPT2 0x400 #define Set1 0x20 #define Set2 0x40 #define Set3 0xC0 #define SetOff 0x00 typedef short (_stdcall *inpfuncPtr)(short portaddr); typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum); int main(void) { HINSTANCE hLib; inpfuncPtr inp32; oupfuncPtr oup32; short x; int i, bitmask, status, zerocoin=0; hLib = LoadLibrary("inpout32.dll"); if (hLib == NULL) { printf("LoadLibrary Failed.\n"); return -1; } inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32"); if (inp32 == NULL) { printf("GetProcAddress for Inp32 Failed.\n"); return -1; } oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32"); if (oup32 == NULL) { printf("GetProcAddress for Oup32 Failed.\n"); return -1; } /*Abfrage Start*/ (oup32)(LPT1,SetOff); while(1 < 2){ FILE *coin_datei = fopen( "coin.ini", "r" ); int coin; if( !coin_datei ){ printf( "Fehler beim Laden der Datei" );} while( !feof(coin_datei) ) fscanf(coin_datei, "%i", &coin ); fclose(coin_datei); if(coin == 0){(oup32)(LPT1,0x00);} if(coin == 1){(oup32)(LPT1,0x01);} if(coin == 2){(oup32)(LPT1,0x02);} if(coin == 3){(oup32)(LPT1,0x03);} if(coin == 4){(oup32)(LPT1,0x04);} if(coin == 5){(oup32)(LPT1,0x05);} if(coin == 6){(oup32)(LPT1,0x06);} if(coin == 7){(oup32)(LPT1,0x07);} if(coin == 8){(oup32)(LPT1,0x08);} if(coin == 9){(oup32)(LPT1,0x09);} if(coin == 10){(oup32)(LPT1,0x10);} if(coin == 11){(oup32)(LPT1,0x11);} if(coin == 12){(oup32)(LPT1,0x12);} if(coin == 13){(oup32)(LPT1,0x13);} if(coin == 14){(oup32)(LPT1,0x14);} if(coin == 15){(oup32)(LPT1,0x15);} if(coin == 16){(oup32)(LPT1,0x16);} if(coin == 17){(oup32)(LPT1,0x17);} if(coin == 18){(oup32)(LPT1,0x18);} if(coin == 19){(oup32)(LPT1,0x19);} if(coin == 20){(oup32)(LPT1,0x20);} if(coin == 21){(oup32)(LPT1,0x21);} if(coin == 22){(oup32)(LPT1,0x22);} if(coin == 23){(oup32)(LPT1,0x23);} if(coin == 24){(oup32)(LPT1,0x24);} if(coin == 25){(oup32)(LPT1,0x25);} if(coin == 26){(oup32)(LPT1,0x26);} if(coin == 27){(oup32)(LPT1,0x27);} if(coin == 28){(oup32)(LPT1,0x28);} if(coin == 29){(oup32)(LPT1,0x29);} if(coin == 30){(oup32)(LPT1,0x30);} if(coin == 31){(oup32)(LPT1,0x31);} if(coin == 32){(oup32)(LPT1,0x32);} if(coin == 33){(oup32)(LPT1,0x33);} if(coin == 34){(oup32)(LPT1,0x34);} if(coin == 35){(oup32)(LPT1,0x35);} if(coin == 36){(oup32)(LPT1,0x36);} if(coin == 37){(oup32)(LPT1,0x37);} if(coin == 38){(oup32)(LPT1,0x38);} if(coin == 39){(oup32)(LPT1,0x39);} if(coin == 40){(oup32)(LPT1,0x40);} if(coin == 41){(oup32)(LPT1,0x41);} if(coin == 42){(oup32)(LPT1,0x42);} if(coin == 43){(oup32)(LPT1,0x43);} if(coin == 44){(oup32)(LPT1,0x44);} if(coin == 45){(oup32)(LPT1,0x45);} if(coin == 46){(oup32)(LPT1,0x46);} if(coin == 47){(oup32)(LPT1,0x47);} if(coin == 48){(oup32)(LPT1,0x48);} if(coin == 49){(oup32)(LPT1,0x49);} if(coin == 50){(oup32)(LPT1,0x50);} if(coin == 51){(oup32)(LPT1,0x51);} if(coin == 52){(oup32)(LPT1,0x52);} if(coin == 53){(oup32)(LPT1,0x53);} if(coin == 54){(oup32)(LPT1,0x54);} if(coin == 55){(oup32)(LPT1,0x55);} if(coin == 56){(oup32)(LPT1,0x56);} if(coin == 57){(oup32)(LPT1,0x57);} if(coin == 58){(oup32)(LPT1,0x58);} if(coin == 59){(oup32)(LPT1,0x59);} if(coin == 60){(oup32)(LPT1,0x60);} if(coin == 61){(oup32)(LPT1,0x61);} if(coin == 62){(oup32)(LPT1,0x62);} if(coin == 63){(oup32)(LPT1,0x63);} if(coin == 64){(oup32)(LPT1,0x64);} if(coin == 65){(oup32)(LPT1,0x65);} if(coin == 66){(oup32)(LPT1,0x66);} if(coin == 67){(oup32)(LPT1,0x67);} if(coin == 68){(oup32)(LPT1,0x68);} if(coin == 69){(oup32)(LPT1,0x69);} if(coin == 70){(oup32)(LPT1,0x70);} if(coin == 71){(oup32)(LPT1,0x71);} if(coin == 72){(oup32)(LPT1,0x72);} if(coin == 73){(oup32)(LPT1,0x73);} if(coin == 74){(oup32)(LPT1,0x74);} if(coin == 75){(oup32)(LPT1,0x75);} if(coin == 76){(oup32)(LPT1,0x76);} if(coin == 77){(oup32)(LPT1,0x77);} if(coin == 78){(oup32)(LPT1,0x78);} if(coin == 79){(oup32)(LPT1,0x79);} if(coin == 80){(oup32)(LPT1,0x80);} if(coin == 81){(oup32)(LPT1,0x81);} if(coin == 82){(oup32)(LPT1,0x82);} if(coin == 83){(oup32)(LPT1,0x83);} if(coin == 84){(oup32)(LPT1,0x84);} if(coin == 85){(oup32)(LPT1,0x85);} if(coin == 86){(oup32)(LPT1,0x86);} if(coin == 87){(oup32)(LPT1,0x87);} if(coin == 88){(oup32)(LPT1,0x88);} if(coin == 89){(oup32)(LPT1,0x89);} if(coin == 90){(oup32)(LPT1,0x90);} if(coin == 91){(oup32)(LPT1,0x91);} if(coin == 92){(oup32)(LPT1,0x92);} if(coin == 93){(oup32)(LPT1,0x93);} if(coin == 94){(oup32)(LPT1,0x94);} if(coin == 95){(oup32)(LPT1,0x95);} if(coin == 96){(oup32)(LPT1,0x96);} if(coin == 97){(oup32)(LPT1,0x97);} if(coin == 98){(oup32)(LPT1,0x98);} if(coin == 99){(oup32)(LPT1,0x99);} if(coin <= 0) { status = (inp32)(LPT2); bitmask = status | Set1; (oup32)(LPT2,bitmask); Sleep(500); /*printf("Erste Bitmask %i\n",bitmask);*/ status = (inp32)(LPT2); bitmask = status ^ Set1; (oup32)(LPT2,bitmask); Sleep(500); /*printf("Zweite Bitmask %i\n",bitmask);*/ } if(coin == 1) { status = (inp32)(LPT2); bitmask = status | Set2; (oup32)(LPT2,bitmask); Sleep(500); /*printf("Erste Bitmask %i\n",bitmask);*/ status = (inp32)(LPT2); bitmask = status ^ Set2; (oup32)(LPT2,bitmask); Sleep(500); /*printf("Zweite Bitmask %i\n",bitmask);*/ } if(coin >= 2) { status = (inp32)(LPT2); bitmask = status | Set3; (oup32)(LPT2,bitmask); Sleep(500); /*printf("Erste Bitmask %i\n",bitmask);*/ status = (inp32)(LPT2); bitmask = status ^ Set3; (oup32)(LPT2,bitmask); Sleep(500); /*printf("Zweite Bitmask %i\n",bitmask);*/ } } }
-
das kann doch schon fast nicht stimmen
aber wollen wir uns mal um die frage kümmern...
#define Set1 0x1 #define Set2 0x2 #define Set12 Set1 | Set2 if(num &= Set12){ if(num == Set12) //zwei bit gesetzt else //ein bit gesetzt }
-
hoffe das stimmt halbwegs, wie du das unterbringst mußt schon selber rausfinden
btw. short sind doch idr. nur 16 bit oder?
void setAndClearBit(uint32_t flag){ uint32_t status = inp32(LPT2) | flag; oup32(LPT2,status); Sleep(500); oup32(LPT2,status ^ flag); } if(coin > -1 && coin < 100){ oup32(LPT1,((coin / 10) << 4) | (coin % 10)); } if(coin > 0){ if(coin < 2){ setAndClearBit(Set2); }else{ setAndClearBit(Set3); } }else{ setAndClearBit(Set1); }
-
sowas geht dann natürlich auch
setAndClearBit(coin > 0 ? coin < 2 ? Set2 : Set3 : Set1);
-
das Problem bei dem ganzen ist das ich mit den ersten 4 bits die erste LED steuere und mit 5-8 die zweite LED. so ist meine Schaltung
http://www.mikrocontroller.net/attachment/80343/Unbenannt.png
d.h. ich muss wirklich um eine 11 anzuzeigen eine 0x11 schreiben.
-
wo blinken da in deiner schaltung die segment anzeigen abwechselnd, dachte sowas macht man zum strom sparen
axo ja nochwas wenn du die "coin.ini" x mal ausliest steht auch nix anderes drin also versuch das doch mal aus der schleife raus zu nehmen
(natürlich nur falls es sich da auch befindet? einrückung lässt grüßen dann könnt man sowas gleich auf den ersten blick erkennen und müßt nicht mühsam die klammern zählen...)ist der return wert von int main() bei nem fehler nicht 1
-
LoZe schrieb:
das Problem bei dem ganzen ist das ich mit den ersten 4 bits die erste LED steuere und mit 5-8 die zweite LED. so ist meine Schaltung
http://www.mikrocontroller.net/attachment/80343/Unbenannt.png
d.h. ich muss wirklich um eine 11 anzuzeigen eine 0x11 schreiben.
Dann schreib doch den gewünschten Dezimalwert in ein char-Array und lies ihn wieder als Hexadezimalwert ein.
-
SeppJ schrieb:
LoZe schrieb:
das Problem bei dem ganzen ist das ich mit den ersten 4 bits die erste LED steuere und mit 5-8 die zweite LED. so ist meine Schaltung
http://www.mikrocontroller.net/attachment/80343/Unbenannt.png
d.h. ich muss wirklich um eine 11 anzuzeigen eine 0x11 schreiben.
Dann schreib doch den gewünschten Dezimalwert in ein char-Array und lies ihn wieder als Hexadezimalwert ein.
war dir das zu viel overhead dass da gleich ein array her muß?
no_c0de schrieb:
if(coin > -1 && coin < 100){ oup32(LPT1,((coin / 10) << 4) | (coin % 10)); }
-
LoZe schrieb:
d.h. ich muss wirklich um eine 11 anzuzeigen eine 0x11 schreiben.
-
oopsNoobs schrieb:
axo ja nochwas wenn du die "coin.ini" x mal ausliest steht auch nix anderes drin also versuch das doch mal aus der schleife raus zu nehmen
(natürlich nur falls es sich da auch befindet? einrückung lässt grüßen dann könnt man sowas gleich auf den ersten blick erkennen und müßt nicht mühsam die klammern zählen...)die "coin.ini" wird immer wieder verändert je nach dem ob eine Münze eingeworfen wird oder ein Spiel gestartet wird.
ich werde es mal mit dem Char-Array versuchen... Danke Mal...