/** * Initialize all modules */ void initAll() { // initialize ADC initADC(); // initialize system timer initTimer0(); // initialize serial com uart_init(); // redirect printf output to serial port stdout = &uart_stdout; // motor.c: initialize motor PWM, pins, encoders and PID initPWM1(); initMotorPins(); initEncoders(); initTachoVariables(); resetPID(); // clear motor speed and direction just in case setDirection(LMOTOR, FORWARD); setDirection(RMOTOR, FORWARD); setPower100(LMOTOR, 0); setPower100(RMOTOR, 0); // odometer.c set initial position and position correction setOdometerTo(0, 0); updateRelativePos(); resetPosCorrection(); }
void initSymPWM0(uint16_t prescaler, _t_pwm_pol pol) { /* Override previous PWM init */ initTimer0(prescaler, TMR_CLK_RISE, PWM, CLKOSC, INT_OFF); /* DC = 0%*/ pwm0Pins(pol); }
int main(void) { // -------- Inits --------- // uint8_t i; LED_DDR = 0xff; initTimer0(); // ------ Event loop ------ // while (1) { for (i = 0; i < 255; i++) { _delay_ms(DELAY); brightnessA = i; brightnessB = 255 - i; } for (i = 254; i > 0; i--) { _delay_ms(DELAY); brightnessA = i; brightnessB = 255 - i; } } /* End event loop */ return (0); /* This line is never reached */ }
void init() { PWMInit(); init_1602(); initTimer0(); init_serial(); timePrint(); car.current = TG_START; }
void main() { //Set watchdog off and make correct smclk WDTCTL = WDTPW + WDTHOLD; // Halt the watchdog timer BCSCTL1 = CALBC1_16MHZ; // 16MHz SMCLK bits. DCOCTL = CALDCO_16MHZ; //Initialize Timer0, then turn the CPU off. initTimer0(); initGPIO(); _bis_SR_register(GIE+LPM0_bits); // Global interrupts enabled, CPU off }
int main(void) { initTimer0(); // Timer0 - Lys/Lyd initTimer1(); // Timer1 - Lyd(OCR1A) og Delays initTimer2(); // Timer2 - Motorstyring initBackLEDPort(); initFrontLEDPort(); sei(); allLightsOn(); // Tænd alle lys while(1) { do { ReflectionCount(); DriveForward1(); brakeLightOff(); if( antalRefleksbrik == 3 ) // Brems ved bakken. { Brake(); brakeLightOn(); } if( antalRefleksbrik == 6 ) // Bremse og bak. { Brake(); _delay_us(5000000); brakeLightOn(); Reverse(); } if( antalRefleksbrik == 8 ) // Når den holder ved refleksbrik nr 5. { Brake(); _delay_us(5000000); } } while ( antalRefleksbrik >=0 && antalRefleksbrik <=11 ); Brake(); brakeLightNormal(); StopLevelComplete(); } return 0; }
int main(void) { initTimer0(); initTimer1(); initTimer2(); initSwitchPort(); sei(); //int antalRefleksbrik; while(1) { do { ReflectionCount(); DriveForward1(); /*if( StartReflection() == 1 ) // True = 1. { DetekCoin(); } */ if( antal == 3 ) // Brems ved bakken. { Brake(); } if( antal == 6 ) // Bremse og bak. { Brake(); _delay_us(5000000); Reverse(); } if( antal == 8 ) // Når den holder ved refleksbrik nr 5. { Brake(); _delay_us(5000000); } } while ( antal >=0 && antal <=11 ); Brake(); } return 0; }
int main(void) { initIO(); initTimer0(); initA2D(); initUART(); initLCD(); sei(); while(1) { handleEvents(); } return 0; }
void main(void) { unsigned char tens; initClock(); initPin(); initTimer0(); initInterruptButtons(); while(1) { ADCON0bits.GO = 1; while(!ADCON0bits.DONE); tens = ADRESH; if (tens < 254*10/3.2/5) { PORTBbits.RB5=1; } else { PORTBbits.RB5=0; } } }
// ------------------------------------------------------------------------------------- static void setup(void) { cli(); // adjust power saving modes PRR = (0<<PRTIM0) | // enable timer0 (0<<PRTIM1) | // enable timer1 (1<<PRUSI) | // disable USI (0<<PRADC); // enable ADC initDiagLed(); initTimer0(); initTimer1(); initComparator(); pwmOff(); sei(); }
int main() { uint8_t i; cli(); wdt_enable(WDTO_60MS); for (i = 0; i < 8; i++) { PORTA = PORTA >> 1; PORTA |= ((readEEPROM(i) - '0') & 0x01) << 7; } for (i = 8; i < 16; i++) { PORTC = PORTC >> 1; PORTC |= ((readEEPROM(i) - '0') & 0x01) << 7; } DDRA = 0xff; DDRC = 0xff; for (stackTail = EEPROM_SIZE - 1; readEEPROM(stackTail) != 0xff; stackTail--); status = ((uint16_t) PORTC) << 8 | (uint16_t) PORTA; initUSART(); setDuty(); initTimer0(); initTimer2(); sei(); printf("\nEntering the main loop\n"); while (1) { wdt_reset(); } return 0; }
int main(void) { uint8_t updateSpeed; // -------- Inits --------- // initTimer0(); OCR0B = 0; ANTENNA_DDR |= (1 << ANTENNA); /* now hooked up to MOSFET, output */ LED_DDR |= (1 << LED0); LED_DDR |= (1 << LED1); initUSART(); printString("DC Motor Workout\r\n"); // ------ Event loop ------ // while (1) { updateSpeed = getNumber(); /* Ramp up/down to desired speed */ if (OCR0B < updateSpeed) { LED_PORT |= (1 << LED0); while (OCR0B < updateSpeed) { OCR0B++; _delay_ms(SPEED_STEP_DELAY); } } else { LED_PORT |= (1 << LED1); while (OCR0B > updateSpeed) { OCR0B--; _delay_ms(SPEED_STEP_DELAY); } } LED_PORT = 0; /* all off */ } /* End event loop */ return (0); /* This line is never reached */ }
void initPWM0(uint16_t prescaler, _t_pwm_pol pol) { /* Override previous PWM init */ initTimer0(prescaler, TMR_CLK_RISE, FAST_PWM, CLKOSC, INT_OFF); /* DC = 0%*/ if ((pol == PWM_NORMAL_A)||(pol == PWM_INVERT_A)) { set_pwmPol0A = 0; sbi(DDRD, DDD6); cbi(PORTD, PORTD6); /* out low */ } if ((pol == PWM_NORMAL_B)||(pol == PWM_INVERT_B)) { set_pwmPol0B = 0; sbi(DDRD, DDD5); cbi(PORTD, PORTD5); /* out low */ } pwm0Pins(pol); if (pol == PWM_NORMAL_A) { setDutyPWM0(0, PWM_A); } if (pol == PWM_NORMAL_B) { setDutyPWM0(0, PWM_B); } if (pol == PWM_INVERT_A) { setDutyPWM0(0xff, PWM_A); } if (pol == PWM_INVERT_B) { setDutyPWM0(0xff, PWM_B); } startTimer0(); }
void EINT3_IRQHandler() { int i; if (count == 0) { initTimer0(); command = 0; realCommand = 0; resetTimer0(); count++; } else if (count == 1) { //Startup bit currentbit = 1; command = command << 1; command = command | currentbit; command = command << 1; lastbit = currentbit; resetTimer0(); count++; } else { interval[count - 1] = readTimer0(); if (interval[count - 1] <= 1000 & interval[count - 1] >= 600) { //Short pulse (~800 uS) if (lastbit == 1) { // We're currently at a low currentbit = 0; command = command | currentbit; command = command << 1; lastbit = currentbit; } else { // We're currently at a high currentbit = 1; command = command | currentbit; command = command << 1; lastbit = currentbit; } } else if (interval[count - 1] >= 1400 & interval[count - 1] <= 1800) { //Long pulse (~1600uS) if (lastbit == 1) { // We're currently at a low currentbit = 0; command = command | currentbit; command = command << 2; lastbit = currentbit; } else { // We're currently at a high currentbit = 1; command = command | currentbit; command = command << 1; command = command | currentbit; command = command << 1; lastbit = currentbit; } } else { //Delay is at around 17k so the current command is over command = command >> 1; //Adds a 0 at the end where there is one missing if ((command & 0x4000000) == 0) { command = command << 1; } //Command in manchester commands[commandCount] = command & 0xFFF; currentToggle = command & 0x400000; currentToggle = currentToggle >> 22; test[commandCount] = currentToggle; //Make this into the correct number for (i = 0; i < 5; i++) { if ((commands[commandCount] & (0x1 << i * 2)) == (0x1 << i * 2)) { realCommand = realCommand | (0x1 << i); } } if((currentToggle != lastToggle || commandCount == 0) && count > 20){ realCommands[commandCount] = realCommand; commandCount++; } lastToggle = currentToggle; realCommand = 0; command = 0; count = 0; } resetTimer0(); count++; } IO2IntClr |= (1 << 6); __asm("nop"); __asm("nop"); //# end reset }
int main(void) { volatile uint32_t valore = 0, i, blink = 0, contatore, lampeggio_led; volatile int32_t arrot; volatile int16_t val1 = 0, x, y, z; distanza DIST; //--------------------------// ///definizione strutture///// //-------------------------// //volatile double d = 1.9845637456; gyro G; accelerazione A; cinematica CIN; /// servono differenti PID, almeno uno per la rotazione ed uno per lo spostamento /// per la rotazione sarebbero interessante usarne 2, uno per la ortazione soft ed uno per la rotazione /// brusca. pid CTRL[3], * pidPtr; /// descrittore della sintassi dei comandi syn_stat synSTATO; /// modulo zigbee per telemetria xbee XB; /// pwm servi e motori pwm PWM, pwmServi; /// struttura del sensore di colore colore COL; /// sensore di temperatura ad infrarossi temperatura TEMP; TEMPER sensIR; /// indormazioni sul sopravvissuto survivor SUR; //inizializzazione struttura per qei qei QEI; /// oggetto che riallinea il mezzo allineamento AL; /// disabilita le interruzioni DI(); pidPtr = CTRL; dPtr = &DIST; TEMPptr = &TEMP; CIN.Aptr = &A; CIN.distPTR = &DIST; CIN.vel = 0.0; dati DATA; //passaggio degli indirizzi delle strutture alla struttura generale dati_a_struttura(&G, &DIST, &CIN, &COL, &TEMP, &SUR, &DATA); /// commento per provare il merge su server remoto /// setup di base setupMCU(); /// imposta i parametri del PID setupPID(CTRL); /// imposta le UART setupUART(); //inizializzo l'i2c InitI2C0(); /// messaggio d'inizio PRINT_WELCOME(); /// inizializza il giroscopio initGyro(&G, Z_AXIS); /// inizializza il timer 0 e genera un tick da 10 ms initTimer0(10, &G); /// inizializza il timer 1 initTimer1(100); /// inizializza il contatore della persistenza del comando synSTATO.tick = 0; /// inizializza il pwm pwmMotInit(&PWM); // TODO: //pwmServoInit (&pwmServi); /// inizializza l'adc e lo prepara a funzionare ad interruzioni. initAdc(&DIST); /// reset dell'automa di analisi della sintassi resetAutoma(&synSTATO); //servo = (pwm *) &pwmServi; /// iniziailizzazione del lettore encoder qei_init(&QEI); /// abilita le interruzioni EI(); /// attende che il sensore vada a regime if (G.IsPresent == OK){ PRINTF("\nAzzeramento assi giroscopio\n"); while (blink < 70){ if (procCom == 1){ procCom = 0; blink++; } } blink = 0; /// azzeramento degli assi azzeraAssi(&G); } /// test della presenza del modulo zig-bee /// il modulo zig-be si attiva con al sequnza '+++' e risponde con 'OK' (maiuscolo) if (testXbee() == 0){ // ok; XB.present = 1; PRINTF("Modulo xbee presente.\n"); } else{ XB.present = 0; PRINTF("Modulo xbee non presente.\n"); } pwm_power(&PWM); contatore = 0; //// inizializza l'accelrometro //stato = writeI2CByte(CTRL_REG1_A, ODR1 + ODR0 + ZaxEN + YaxEN + XaxEN); // scrivo nel registro 0x20 il valore 0x0F, cioe' banda minima, modulo on e assi on /// sintassi: indirizzo slave, num parm, indirizzo reg, valore da scrivere //I2CSend(ACCEL_ADDR, 2, CTRL_REG1_A, ODR1 + ODR0 + ZaxEN + YaxEN + XaxEN); A.isPresent = testAccel(); if (A.isPresent) impostaAccel(&A); /// taratura sul sensore di luminosita' whiteBal(&COL); /// taratura del sensore di temepratura taraturaTemp(&TEMP); /// qei_test(&QEI); /// task principale while(1){ /// invia la risposta per i comandi di rotazione, quando sono stati eseguiti if(pidPtr->rispondi == TRUE){ rispostaRotazione(pidPtr, &synSTATO); pidPtr->rispondi = FALSE; } if (procCom == 1 ){ //UARTCharPutNonBlocking(UART1_BASE, 'c'); procCom = 0; contatore++; lampeggio_led++; if(lampeggio_led >= 50) { lampeggio_led = 0; if(DATA.surPtr->isSurvivor == TRUE ) { if(HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + (GREEN_LED << 2))) != GREEN_LED ) HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + (RED_LED << 2))) = 0; HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + (GREEN_LED | RED_LED << 2))) ^= GREEN_LED | RED_LED; } HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + (GREEN_LED << 2))) ^= GREEN_LED; } /* LETTURA DEL COMANDO */ /// restituisce l'indirizzo del PID da utilizzare nel successivo processo di calcolo pidPtr = leggiComando(&synSTATO, CTRL, pidPtr, &DATA); /* LETTURA SENSORI */ /// effettua i calcoli solo se il giroscopio e' presente /// TODO: il PID viene calcolato ongi 10ms oppure ogni 20ms? Come è meglio? /* misura gli encoder e calcola spostameti e velocità */ /* misura i sensori di distanza */ if (DIST.run == true) /// TODO controllare se riesce a funzionare mentre legge le accelerazioni su I2C ROM_ADCProcessorTrigger(ADC0_BASE, 0); /// misura i dati forniti dall'accelerometro se disponibili if(A.isPresent) misuraAccelerazioni(&A); /// le misure del giroscopio invece sono effettuate solo dall'apposito pid /*if(G.IsPresent == OK) if( contatore == 1){ /// ogni 10 ms effettua il calcolo del PID contatore = 0; HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + (GPIO_PIN_0 << 2))) |= GPIO_PIN_0; PID(&G, pidPtr, &PWM, &CIN); setXPWM(&CTRL[1], &PWM); procCom = 0; HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + (GPIO_PIN_0 << 2))) &= ~GPIO_PIN_0; blink++; /// lampeggio del led con periodo di 2 s. if (blink >= 100){ HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + ((GPIO_PIN_2 | GPIO_PIN_1) << 2))) = 0; HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + (GPIO_PIN_3 << 2))) ^= GPIO_PIN_3; blink = 0; } ///provvede ad integrare la misura della velcita' angolare ogni 10 ms //misuraAngoli(&G); //PRINTF("asse x: %d\t", G.pitch); //PRINTF("\tasse y: %d\t", G.roll); //PRINTF("\tasse z: %d\n", G.yaw); //PRINTF("uscita PID: %d\n", C.uscita); }*/ /* RISPOSTA AL COMANDO */ inviaSensore(&synSTATO, &DATA); } } }
int main(void) { static uint8_t oldPosition; static uint8_t divVal, modVal; cli(); wdt_disable(); set_sleep_mode( SLEEP_MODE_IDLE ); initDevice(); DDRD = 0b11111111; DDRB = 0b11111111; initTimer2(); initTimer0(); sei(); startTimer2(); startTimer0(); frame = buf1; buffer = buf2; CLEAR_BUFFER( frame ); CLEAR_BUFFER( buffer ); setAnimationFunction( anim_fillDot, TRUE, TRUE ); animation.loop = TRUE; while ( 1 ) { if( animation.tick ) { animationTick(); clearTick(); } if( currentScanPixel == 0 ) { if( animation.nextFrameReady ) { animationBufferSwap(); } } if( oldPosition != currentScanPixel ) { modVal = currentScanPixel % 8; //we need to change columns only so often if( modVal == 0 ) { divVal = currentScanPixel / 8; COL_PIXEL( divVal ); } if( frame[ divVal ] & _BV( modVal ) ) { ROW_PIXEL( modVal ); } else { ROW_OFF(); } oldPosition = currentScanPixel; } //if( TIME TO SLEEP ) { sleep_mode(); } } }
/**@brief Chiamabile più volte per inizializzare moduli A e B */ void initCompare0 (uint8_t comp_val, _t_compare_sel comp, uint16_t prescaler, _t_edge edge, _t_timer_clock clock, uint8_t timer_int) { initTimer0(prescaler, edge, COMPARE_MATCH, clock, timer_int); switch (comp) { case COMP_A_TOGGLE: sbi(TCCR0A, COM0A0); cbi(TCCR0A, COM0A1); sbi(DDRD, DDD6); OCR0A = comp_val; break; case COMP_A_CLEAR: cbi(TCCR0A, COM0A0); sbi(TCCR0A, COM0A1); sbi(DDRD, DDD6); OCR0A = comp_val; break; case COMP_A_SET: sbi(TCCR0A, COM0A0); sbi(TCCR0A, COM0A1); sbi(DDRD, DDD6); OCR0A = comp_val; break; case COMP_B_TOGGLE: sbi(TCCR0A, COM0B0); cbi(TCCR0A, COM0B1); sbi(DDRD, DDD5); OCR0B = comp_val; break; case COMP_B_CLEAR: cbi(TCCR0A, COM0B0); sbi(TCCR0A, COM0B1); sbi(DDRD, DDD5); OCR0B = comp_val; break; case COMP_B_SET: sbi(TCCR0A, COM0B0); sbi(TCCR0A, COM0B1); sbi(DDRD, DDD5); OCR0B = comp_val; break; case COMP_A_DISCONNECT: cbi(TCCR0A, COM0A0); cbi(TCCR0A, COM0A1); OCR0A = comp_val; break; case COMP_B_DISCONNECT: cbi(TCCR0A, COM0B0); cbi(TCCR0A, COM0B1); OCR0B = comp_val; break; default: /* lascia OCnx sconnesso come lo è da initTimer0*/ cbi(TCCR0A, COM0B0); cbi(TCCR0A, COM0B1); cbi(TCCR0A, COM0A0); cbi(TCCR0A, COM0A1); break; } switch (timer_int) { case INT_ON: /* Non devo chiamare questa funzione se uso il normale */ if ((comp == COMP_A_CLEAR) || (comp == COMP_A_SET) ||(comp == COMP_A_TOGGLE)||(comp == COMP_A_DISCONNECT)) { sbi(TIMSK0, OCIE0A); } if ((comp == COMP_B_CLEAR) || (comp == COMP_B_SET) ||(comp == COMP_B_TOGGLE)||(comp == COMP_B_DISCONNECT)) { sbi(TIMSK0, OCIE0B); } break; case INT_OFF: if ((comp == COMP_A_CLEAR) || (comp == COMP_A_SET) ||(comp == COMP_A_TOGGLE)||(comp == COMP_A_DISCONNECT)) { cbi(TIMSK0, OCIE0A); } if ((comp == COMP_B_CLEAR) || (comp == COMP_B_SET) ||(comp == COMP_B_TOGGLE)||(comp == COMP_B_DISCONNECT)) { cbi(TIMSK0, OCIE0B); } break; default: cbi(TIMSK0, OCIE0A); cbi(TIMSK0, OCIE0B); break; } }
int main(void) { int i; char buff1[3]; char buff2[3]; initDisplay(); initSomGenerator(); initTimer0(); initRC5(); resetTimer0(); initRTC(); initRIT(); setPriorities(); int lastAlarmToggle = 0; char alarmBit; ////////////////////////////////// char* test = generateSom(); char som[10]; strcpy(som, test); free(test); ////////////////////////////////// // char arr[3]; // readRAM(arr, 0x08); // delay(500); // alarmBit = arr[2]; // clear(); int arr2[3]; //int arr[3] = {0x00, 0x24, 0x12}; //setTime(arr); readTime(arr2, 0x00); if(arr2[2] < 10){ sprintf(buff1, "0%d", arr2[2]); } else { sprintf(buff1, "%d", arr2[2]); } if(arr2[1] < 10){ sprintf(buff2, "0%d", arr2[1]); } else { sprintf(buff2, "%d", arr2[1]); } //Set the last known values in RIT.c lastValues[0] = arr2[0]; lastValues[1] = arr2[1]; lastValues[2] = arr2[2]; sprintf(output, "%s:%s", buff1, buff2); // printf("%d\n", arr2[0]); // printf("%d\n", arr2[1]); // printf("%d\n", arr2[2]); //Main loop while (1) { while (!isTimeForAlarm(alarmBit) && (getCommand(commandCount - 1) != 15 && getCommand(commandCount - 1) != 11)) { //This is the main loop, all we do here is print the current time to the display since the current time is updated through the RIT and the EINT takes care of the remote control //Prints the current time printToDisplay(output); } if (getCommand(commandCount - 1) == 15) { //Goes into the set alarm state addAlarmState(); } if (getCommand(commandCount - 1) == 11 && commandCount != lastAlarmToggle) { // '11' needs to be replaced with an other number, because it's an temporary button //Toggle alar state alarmBit = !alarmBit; toggleAlarmState(alarmBit); lastAlarmToggle = commandCount; //Give the user some feedback(Tell them wether they set or unset the alarm) for(i=0; i<200; i++){ asm("nop"); if(alarmBit == 1){ printToDisplay(" + "); } else { printToDisplay(" - "); } } } if (isTimeForAlarm(alarmBit)) { //Goes into the alarm state alarmState(); resetAlarmTime(); } printToDisplay(output); } return 0; }
void main(void) { PORTA=0x00; DDRA=0x00; PORTB=0x00; DDRB=0x00; PORTC=0x00; DDRC=0x00; PORTD=0x00; DDRD=0x00; PORTE=0x00; DDRE=0x00; PORTF=0x00; DDRF=0x00; PORTG=0x00; DDRG=0x00; initTimer0(); initTimer1(); initTimer2(); initTimer3(); enableTimers(); // External Interrupt(s) initialization // INT0-INT7: Off EICRA=0x00; EICRB=0x00; EIMSK=0x00; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; // ====================== TRUE INITIALIZATION ============================= initLeds(); //initJumpers(); InitFans(); // configure Fans FanSetPower(&fan1, 5); FanSetPower(&fan2, 0); FanSetPower(&fan3, 0); FanSetPower(&fan4, 0); // max is 27 FanEnable(&fan2); FanEnable(&fan3); FanEnable(&fan4); InitRailControl(); InitPsuControl(); InitPullDownControl(); //InitTemperature(); // no temperature-based control yet // depend on jumper J1 InitSignalControl(); InitADC(); InitBatChargeControl(); initPPC_State(); initUSART(); #asm("sei") while(1) { // read jumpers // read inputs // update fans // update outputs // enter sleep /* // test fan speed debug if (getTicksDelta(lastFanStepTickCount) > FAN_STEP_INTERVAL) { lastFanStepTickCount = getTickCount(); debug_fan_power_step++; if (debug_fan_power_step > PWR_FAN_MAX) debug_fan_power_step = PWR_FAN_MIN; FanSetPower(&fan1, debug_fan_power_step); }; */ BatChargeUpdate(); //batChargeState.all_batteries_charged = 1; // !!! SignalsIndicateCharged(batChargeState.all_batteries_charged); #if 1 SignalReadUpdate(); switch (ppcState.mode) { case(PPC_MODE_WAITING): { if (InputsTransientHigh(SIGNAL_INDEX_SPINT_POWER)) { setPPC_Mode(PPC_MODE_STARTING); }; break; }; // waiting mode state case(PPC_MODE_STARTING): { FanEnable(&fan1); switch(ppcState.stage) { case(0): PsuSet(0,0,1,0); PsuUpdateOutput(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; delay_ms(200); break; case(1): PsuSet(1,0,1,0); PsuUpdateOutput(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; delay_ms(200); break; case(2): PsuSet(1,0,1,1); PsuUpdateOutput(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; delay_ms(200); break; case(3): RailSet(1,0); RailUpdateOutput(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; delay_ms(200); break; case(4): RailSet(1,1); RailUpdateOutput(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; delay_ms(1000); break; case(5): PullDownSet(1,0,0); PullDownUpdateOutput(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; delay_ms(100); break; case(6): PullDownSet(0,0,0); PullDownUpdateOutput(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; delay_ms(100); break; default: setPPC_Mode(PPC_MODE_ACTIVE); break; }; ppcState.stage++; break; }; // starting mode state case(PPC_MODE_ACTIVE): { FanEnable(&fan1); if (signalState.current_signal_state[SIGNAL_INDEX_SPINT_POWER] == 0) { setPPC_Mode(PPC_MODE_PARKING); }; //if (InputsTransientLow(SIGNAL_INDEX_SPINT_POWER)) break; }; // acitve mode state case(PPC_MODE_PARKING): { FanDisable(&fan1); switch(ppcState.stage) { case(0): // turn off PSU power PsuSet(0,0,0,0); PsuUpdateOutput(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; delay_ms(200); break; case(1): // park computer (pull-in) PullDownSet(1,0,0); PullDownUpdateOutput(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; delay_ms(100); break; case(2): // park computer (pull-out) PullDownSet(0,0,0); PullDownUpdateOutput(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; delay_ms(1000); // wait before clamping power rail break; case(3): // turn-off rails RailSet(0,0); RailUpdateOutput(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; delay_ms(200); break; default: setPPC_Mode(PPC_MODE_WAITING); break; }; ppcState.stage++; break; }; // Parking mode state }; // MODE Switch // This function locks for 0.2 second minimum // This must be read in the end of control loop /* TemperatureReadUpdate(); if (temperatureState.temperature1 != 0) { if (temperatureState.temperature1 <= 30) { FanDisable(&fan1); } else { FanEnable(&fan1); FanSetPower(&fan1,(unsigned char)(PWR_FAN_MIN + ((signed int)(PWR_FAN_MAX - PWR_FAN_MIN))*temperatureState.temperature1/60)); }; } else { FanDisable(&fan1); }; */ RailUpdateOutput(); PsuUpdateOutput(); PullDownUpdateOutput(); networkUpdate(); PORTA = railState.port_value | psuState.port_value | pullDownState.portA_value; #endif /* if (ppcState.mode == PPC_MODE_WAITING) { #asm("sleep") } */ } } // main
int main() { hc595_init(); initTimer0(); int8_t shiftCounter = 0x00; int16_t curShift, curMaxShift; int16_t charCol, row; int16_t col; //revspace: 47 cols uint8_t textLength = 190;//77 + 113+;//198; //test length // strlen(s) * 6 //all output DDRD = 0xFF; DDRA = 0xFF; char text[] = "nee"; textLength = strlen(text);//10 * 5 + 9; int8_t j, i; while(1) { if(shiftIn > 80 + textLength) shiftIn = 0; curMaxShift = shiftIn; //scan the rows for(row = 7; row > 0; row--) { charCol = textLength; //word length PORTA = row; hc595_latchLow(); // all the columns + the length of the text for(col = 80 + textLength; col >= 0; ) { if(80 + textLength - curMaxShift > col && charCol >= 0) { for(i = strlen(text) - 1; i >= 0; i--) { for(j = 4; j >= 0; j--) { if(~chars[text[i] - 'a'][j] & (1 << row)) { hc595_dataHigh(); } else { hc595_dataLow(); } charCol--; hc595_clk(); } hc595_dataHigh(); hc595_clk(); } } else { hc595_dataHigh(); } col--; hc595_clk(); } hc595_latchHigh(); // hc595_latchLow(); // for(col = 80 + textLength; col >= 0; col--){ // if( textLength + 80 - curMaxShift > col && charCol >= 0) { // if(~text[charCol] & (1 << row)) // hc595_dataHigh(); // else // hc595_dataLow(); // // [>if(~orange[charCol] & (1 << row))<] // // [>hc595_dataRedHigh();<] // // [>else<] // // [>hc595_dataRedLow();<] // charCol -= 1; // } // else { // hc595_dataHigh(); // } // hc595_clk(); // } // hc595_latchHigh(); } } }