#include <3048fone.h> #include "h8_3048fone.h" volatile int count1=-1;/*LED0用カウンタ -1の時は休止中*/ volatile int count2=-1;/*LED1用カウンタ -1の時は休止中*/ main() { initLed(); initPushSW();/*PushSWの初期化*/ initTimer1Int(10000); /*時間割り込み10000μsec=10msec ch1使用*/ E_INT(); /*CPU割り込み許可*/ startTimer1(); /*時間割り込みタイマスタートch1*/ while(1) { if ((count1==-1 || 50<count1) && checkPushSW(0)==1) { count1=0; turnOnLed(0); } else if (100<count1 && count1<200) { turnOffLed(0); } else if (200<count1 && count1<300) { /*200カウントで2秒経過*/ turnOnLed(0); } else if (300<count1) { count1=-1; turnOffLed(0); } if ((count2==-1 || 50<count2) && checkPushSW(1)==1) { count2=0; turnOnLed(1); } else if (100<count2 && count2<200) { turnOffLed(1); } else if (200<count2 && count2<300) { /*200カウントで2秒経過*/ turnOnLed(1); } else if (200<count2) { /*200カウントで2秒経過*/ count2=-1; turnOffLed(1); } } }
void main (void) { //Set Clock Frequency = 500kHz OSCCONbits.IRCF2 = 0; OSCCONbits.IRCF2 = 1; OSCCONbits.IRCF2 = 1; // Enable Global interrupts INTCONbits.GIE = 1; // Enable High priority interrupt //Setup IR Sensor setupIRSensor(); //Initializes the timer2 for PWM for Motor and Servo setTimer2PWM(); //Setup Motor setupMotor(); //Setup Timer for servo startTimer0(); //Setup Timer for timed water startTimer1(); //SetupButtonInterupt setupButtons(); while (1) { // This area loops forever } }
void testLedMatrix(int speed) { tU8 cntA = 0; PINSEL0 |= 0x00001500 ; //Initiering av SPI SPI_SPCCR = 0x08; SPI_SPCR = 0x60; IODIR0 |= SPI_CS; startTimer1(2); for(;;) { cntA++; if (cntA > sizeof(eaText)-speed) break; #if 0 pattern[0] = eaText[cntA+0]; pattern[1] = eaText[cntA+1]; pattern[2] = eaText[cntA+2]; pattern[3] = eaText[cntA+3]; pattern[4] = eaText[cntA+4]; pattern[5] = eaText[cntA+5]; pattern[6] = eaText[cntA+6]; pattern[7] = eaText[cntA+7]; #endif } }
int main() { //Create current LED placeholders int currLED = 1; //This function is necessary to use interrupts. //enableInterrupts(); //Initialize SW1 initSwitch1(); //Initialize all LEDs initLEDs(); //Initialize Timer 2 initTimer2(); //Initialize Timer 1 initTimer1(); //Turn on LED 1 before starting the state machine turnOnLED(1); while (1) { //See state descriptions above switch (state) { case wait: if (SW1 == PRESSED) { startTimer1(); state = debouncePress; } break; case debouncePress: delayMs(100); state = wait2; break; case wait2: if (IFS0bits.T1IF == FLAGUP){ stopTimer1(); state = debounceRelease2; } if (SW1 == RELEASED) { stopTimer1(); state = debounceRelease; } break; case debounceRelease: delayMs(100); if (currLED == 1) { state = led2; } else if (currLED == 2) { state = led3; } else if (currLED == 3) { state = led1; } break; case debounceRelease2: if (SW1 == RELEASED) { delayMs(100); if (currLED == 1) { state = led3; } else if (currLED == 2) { state = led1; } else if (currLED == 3) { state = led2; } } break; case led1: turnOnLED(1); turnOffLED(currLED); currLED = 1; state = wait; break; case led2: turnOnLED(2); turnOffLED(currLED); currLED = 2; state = wait; break; case led3: turnOnLED(3); turnOffLED(currLED); currLED = 3; state = wait; break; } } return 0; }