importsequence
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | importsequence [2014/11/02 19:22] (current) – created admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | < | ||
+ | unsigned char ImportSequence(){ | ||
+ | // P1.6 and P1.7 will be Fototransistors for getting the Data | ||
+ | // P1.4 is a pushbutton for starting the sequence will maybe handled as interrupt | ||
+ | static unsigned char OldPinState = 0; | ||
+ | unsigned char PinState = 0; | ||
+ | static unsigned char count1 = 0; | ||
+ | static unsigned char count2 = 0; | ||
+ | static unsigned char Valid = 0; | ||
+ | static unsigned long Millis = 10000; // Wait 10 Seconds, if sequence not starting in this time, end function | ||
+ | unsigned long CurrentMillis = millis(); | ||
+ | unsigned long PreviousMillis = CurrentMillis; | ||
+ | static unsigned char ArrayLength = 0; | ||
+ | static unsigned char ActualByteOfArray = 0; | ||
+ | static unsigned char ByteCounter = 0; | ||
+ | // Startsequnece. If Both inputs blink 3 times together, and first input blinks 3 times alone, | ||
+ | // then go on with importing the new sequence, if this does not happen within 10seconds, leave step. | ||
+ | while (CurrentMillis - PreviousMillis <= Millis || Valid == 1){ | ||
+ | CurrentMillis = millis(); | ||
+ | PinState = P1IN & 0xC0; | ||
+ | if (PinState == 0xC0 && PinState != OldPinState){ | ||
+ | count1++; | ||
+ | } | ||
+ | if (PinState == 0x40 && PinState != OldPinState){ | ||
+ | count2++; | ||
+ | } | ||
+ | OldPinState = PinState; | ||
+ | if (count1 == 3 && count2 == 3){ | ||
+ | Valid = 1; | ||
+ | } | ||
+ | } | ||
+ | // Import first byte, length of Array | ||
+ | ByteCounter = 0; | ||
+ | while (Valid == 1 && ByteCounter <= 7){ | ||
+ | PinState = P1IN & 0xC0; | ||
+ | if (PinState == 0xC0 && PinState != OldPinState){ | ||
+ | ArrayLength = ArrayLength << 1; | ||
+ | ArrayLength |= 0x01; | ||
+ | ByteCounter++; | ||
+ | } | ||
+ | if (PinState == 0x40 && PinState != OldPinState){ | ||
+ | ArrayLength = ArrayLength << 1; | ||
+ | ByteCounter++; | ||
+ | } | ||
+ | OldPinState = PinState; | ||
+ | } | ||
+ | unsigned char FreqArray[ArrayLength]; | ||
+ | while (Valid == 1 && ActualByteOfArray < ArrayLength){ | ||
+ | ByteCounter = 0; | ||
+ | while (Valid == 1 && ByteCounter <= 7){ | ||
+ | PinState = P1IN & 0xC0; | ||
+ | if (PinState == 0xC0 && PinState != OldPinState){ | ||
+ | FreqArray[ActualByteOfArray] = FreqArray[ActualByteOfArray] << 1; | ||
+ | FreqArray[ActualByteOfArray] |= 0x01; | ||
+ | ByteCounter++; | ||
+ | } | ||
+ | if (PinState == 0x40 && PinState != OldPinState){ | ||
+ | FreqArray[ActualByteOfArray] = FreqArray[ActualByteOfArray] << 1; | ||
+ | ByteCounter++; | ||
+ | } | ||
+ | OldPinState = PinState; | ||
+ | } | ||
+ | ActualByteOfArray++; | ||
+ | } | ||
+ | unsigned char TimeArray[ArrayLength]; | ||
+ | ActualByteOfArray = 0; | ||
+ | while (Valid == 1 && ActualByteOfArray < ArrayLength){ | ||
+ | ByteCounter = 0; | ||
+ | while (Valid == 1 && ByteCounter <= 7){ | ||
+ | PinState = P1IN & 0xC0; | ||
+ | if (PinState == 0xC0 && PinState != OldPinState){ | ||
+ | TimeArray[ActualByteOfArray] = TimeArray[ActualByteOfArray] << 1; | ||
+ | TimeArray[ActualByteOfArray] |= 0x01; | ||
+ | ByteCounter++; | ||
+ | } | ||
+ | if (PinState == 0x40 && PinState != OldPinState){ | ||
+ | TimeArray[ActualByteOfArray] = TimeArray[ActualByteOfArray] << 1; | ||
+ | ByteCounter++; | ||
+ | } | ||
+ | OldPinState = PinState; | ||
+ | } | ||
+ | ActualByteOfArray++; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </ | ||
importsequence.txt · Last modified: 2014/11/02 19:22 by admin