int main(void) { unsigned constrained = 0, shutOffBuzzer = 0; //Set GPIO Pins if(!shutOffBuzzer) DDRB|=0b00100000; //PIN 13 output to buzzer DDRB|=0b00001000; sei(); setupADC(); setupPWM(); startPWM(); count=0; InitTimer0(); StartTimer0(); while(1) { if(state) pwm_val = remap(adc_val,100,900); else { //0-255 steps for tone strength constrained = remap(adc_val,619,890); //Output tone tone(constrained); } } }
void main() { P2 = 0xF7; InitLed(); InitTimer0(); while(1) ; }
int main(void) { InitPort(); InitTimer0(); StartTimer0(); while(1) { //doing nothing } }
void main() { TRISA.F1 = 0; PORTA.F1 = 0; ADCON1 |= 0x0F; // Define todos pinos AN como digital I/O InitTimer0(); // Inicializa TIMER0 while(1) { } // while } // main
int main(int argc, char** argv) { //Initializations InitCLK(); InitGPIO(); InitDAC(); InitSPI(); InitTimer0(); InitWatchdog(); //Setup interrupts PEIE = 1; GIE = 1; SPI_CS = CS_IDLE; //must be changed! SSPCON1bits.SSPEN=0; // Disable SPI Port //PORTCbits.RC5 = 0; //Set MOSI low //PORTCbits.RC3 = 0; //Set SCK low PORTCbits.PORTC = LATCbits.LATC & 0xD7; //set MOSI and SCK low while(1) { SPI_CS = CS_IDLE; //hands off mode for testing the launcher //Check if beacon has been launched CheckDisconnect(); //DONE+TESTED if(playbackFlag&&!MEM_ACCESS) { PlaybackMode(); playbackFlag = 0; } //Transmit message if(transmitFlag) //DONE+TESTED TransmitMode(); //DONE+TESTED //Go back to sleep, wait for interrupts Hibernate(); } return (EXIT_SUCCESS); }
// Start program int main(void) { // Timer initialize InitTimer1(); InitTimer0(); // Set LED pin to output LED_DDR = (1 << LED_OUT); // Enable interrupts sei(); while(1) { // Sleep Mode set_sleep_mode(SLEEP_MODE_IDLE); sleep_mode(); // If command exists ... compare if (CmdDone == 1) { // If matches required command if (RC5_cmd_val == RC5_CMD) { // Sleep disablen //sleep_disable(); // Set output to 1 LED_PORT |= (1 << LED_OUT); // Set CmdMatch to 1 ... no new command will be sampled CmdMatch = 1; // Set TimerValue to zero TimerValue = 0; // Start counting StartTimer0(); } // Reset all values RC5_cmd_val = 0x00; CmdBitNumber = 7; StartBit = 0; CmdDone = 0; } } }
void main(void) { cct_init(); lcdinit(); InitTimer0(); while(1) { if (start==0 && end==1)// vehicle starts its journey by entering at the first line { if(msCounter==0) { DisplaytoLCD(secCounter-1); } UpdateTimeCounters(); } else if ( start==0 && end==0)//vehicle reached finish line and hence the speed is caliculated here { if(msCounter==0) { speed=((float)15/(float)secCounter); FloatToLCD(speed); } UpdateTimeCounters1(); } else//no vehicle for all the combinations { if(msCounter==0) { Displaystring(); } UpdateTimeCounters1();// function to make the letters visible fora second and then to refresh } } }
int main(void) { _delay_ms(1000); lcd_init(); InitTimer0(); stdout = &mystdout; sei(); while(1) { printf("\rMichal "); _delay_ms(1000); //printf("\nSiecinski "); printf("Czas: %d:%d",min,sek); _delay_ms(1000); } return 0; }
void main(void) { ServoTimerInit(); InitInterrupts(); InitTimer0(); while(1) { static unsigned char LastBitState = 0; static unsigned char CurrentBitState = 0; CurrentBitState = RC1; if ((CurrentBitState == SET) && (CurrentBitState != LastBitState)) { //PWM attack + ShouldAttack = 1; //start/restart Two second timer TMR0 = MAX_TIMER_VAL; //2s complement of max value = 0xFF Two_Seconds_Timer = CLEAR; } else if ((CurrentBitState == CLEAR) && (CurrentBitState != LastBitState)) { ShouldAttack = 0; //PWM retract } if ((Two_Seconds_Timer >= TWO_SEC) && (ShouldAttack)) { Two_Seconds_Timer = CLEAR; ShouldAttack = 0; //PWM retract } if(T0IF == SET) //if(TMR0>10) { T0IF = CLEAR; Two_Seconds_Timer++; } LastBitState = CurrentBitState; } }
//-------------------------------------------------------------------------- // Module: // main // /// This function is the main program. It provides initialization of hardware /// and software components and software. The main loop portion handles /// only the Debug task. /// //-------------------------------------------------------------------------- void main (void) { UINT_16 temp = 0; /* Disable all C167 interrupts */ DISABLE_ALL_INTERRUPTS(); /* Don't allow any interrupt processing to occur */ SetMvbReady (FALSE); SetStartupSuccessful (FALSE); /* Release MVB IPACK hardware */ ReleaseIpackHw(); /* Configure Push-Pull digital IOs at P7 to Digital Outputs */ DO_Init (0xFF); /* Initialize the HiDAC outputs */ InitP8ForDigOuts(); InitDigitalOutputs(); InitAnalogOutputs(); /* Toggle VDrive and CPU watchdogs */ ToggleVDriveWatchdog(); ToggleCPUWatchdog(); /* Set the state of the HIDAC LEDs */ HIDAC_TEST_LED_ON(); HIDAC_FAIL_LED_OFF(); /* Enable SSMR1, SSMR2, VDrive & +5V to Hex LED Display */ DO_WriteBank (DIGOUT_BANK2, 0x00FF); /* Initialize the software to detect a 15 volt failure */ Init15VoltFailDetect(); /* This call initializes the 10 ms Timer ISR */ InitTimer0(); InitTimer1 (); InitTimer7 (); ENABLE_ALL_INTERRUPTS(); /* Allow the VDrive watchdog to toggle and wait some timer before trying to drive display */ SetVdriveDisable (FALSE); TM_Wait (250); /* Display the stored CRC checksum for approximately 1 second at startup */ DisplayCRConHexLED(); /* Perform the RAM Test. */ if (!VerifyRAM()) { HIDAC_FAIL_LED_ON(); UpdateHidacError (RAM_FAILURE); } if (!HidacErrorExists()) { /* Perform the ROM Test. */ if (!VerifyCRCAtStart()) { HIDAC_FAIL_LED_ON(); UpdateHidacError (ROM_FAILURE); } } /* Init the RS-232 */ InitSerialCommunications(); /* Init the analog inputs */ InitAnalogInputs(); /* Init the PWM input hardware */ PwmInInit(); /* Init the MVB IPACK interface */ InitMVBIpack(); /* DAS This call to InitPwmOutputs needs to be after InitMVBIpack. After Sweden made an an upgrade to the IPACK CPLD to rev 2, for some reason, initializing PWM1 prior to initializing the IPACK causes the IPACK not to initialize properly. Didn't have time to investigate ????? */ InitPwmOutputs(); if (!HidacErrorExists()) { /* stop here if +/- 15VDC supply is low */ if (Get15VoltBad()) { HexLEDUpdate (0x15); HIDAC_FAIL_LED_ON(); UpdateHidacError (BAD_15V); } } #ifdef BURN_IN if (!HidacErrorExists()) { BurnInCode(); } else { while (1); } //////////////////////////////////////////////////////////////// // Code never gets past here if Burn-In code enabled // Infinite while (FOREVER) in BurnInCode() or if error detected //////////////////////////////////////////////////////////////// #endif HIDAC_TEST_LED_OFF(); SetStartupSuccessful (TRUE); // Setting the argument to FALSE indicates that the baseline CPU loading has // already been performed and that the CPU load check, that can be performed via // the serial port, will report the CPU loading as a percentage. Setting to TRUE // should only be done when capturing the CPU baseline loading and should be returned // to FALSE for normal operation DebugInit (FALSE); if (!HidacErrorExists()) { HexLEDUpdate (0x00); } /* This is the background loop */ while (1) { // Used to measure CPU loading DebugUpdateLoadCounter(); /* Code that executes in the main while forever loop. All RealTime critical application code is interrupt driven */ DebugService(); } }
// PWM initialize void InitPWM(void) { // PWM = 0; // Initialize with 0% duty cycle InitTimer0(); // Initialize timer0 to start generating interrupts // PWM generation code is written inside the Timer0 ISR }
int main(int argc, char** argv) { //Initializations InitCLK(); InitGPIO(); InitADC(); //InitSPI(); InitTimer0(); InitTimer1(); InitWatchdog(); InitUART(); //Initialize UART module unsigned char periodicCounter = MIN_PERIOD; gpsIndex = 0; INTCONbits.GIE = 1; ToggleSleepGPS(); //Turn GPS on SetupGPS(); //Setup Lat/Long recording PORTBbits.PORTB = LATBbits.LATB & 0xDF; //turn red LED off PORTBbits.PORTB = LATBbits.LATB | 0x10; //turn green LED on __delay_ms(100); PORTBbits.PORTB = LATBbits.LATB & 0xEF; //turn green LED off SPI_CS = CS_IDLE;//prerecord while(1){ //PRE_RECORD FUNCTION //InitSPI(); //Start-up SPI again //PreRecordMode(); //SSPCON1bits.SSPEN=0; // Disable SPI Port //PORTCbits.RC5 = 0; //Set MOSI low //SPI_CS = CS_IDLE;//prerecord //__delay_ms(5); SPI_CS = CS_IDLE; //Check Flags if(PORTAbits.RA1) { //Strobe LED PORTBbits.RB0 = 1; __delay_ms(100); PORTBbits.RB0 = 0; } if(recordFlag) { RecordMode(); recordFlag = 0; __delay_ms(500); //trying to get gps to not hangup } //Not recording, Update the GPS if(gpsTimeoutState==0) UpdateGPS(); //tell GPS to send an update else if(gpsTimeoutState==1) { ToggleSleepGPS(); gpsTimeoutState = 2; } else if(gpsTimeoutState==2) { ToggleSleepGPS(); gpsTimeoutState = 3; } else if(gpsTimeoutState==3) { __delay_ms(1000); gpsTimeoutState = 0; } else { gpsTimeoutState = 0; } if(gpsInvalidFlag) //turn on red LED if invalid message { PORTBbits.PORTB = LATBbits.LATB | 0x20; //turn red LED on PORTBbits.PORTB = LATBbits.LATB & 0xEF; //turn green LED off __delay_ms(250); PORTBbits.PORTB = LATBbits.LATB & 0xDF; //turn red LED off if(periodicCounter < MAX_PERIOD) periodicCounter++; } else //turn on green LED if valid message { PORTBbits.PORTB = LATBbits.LATB | 0x10; //turn green LED on PORTBbits.PORTB = LATBbits.LATB & 0xDF; //turn red LED off __delay_ms(250); PORTBbits.PORTB = LATBbits.LATB & 0xEF; //turn green LED off periodicCounter = MIN_PERIOD; } if(!recordFlag) { if(PORTAbits.RA1) //check strobe GoToSleep(MIN_PERIOD); else if(gpsInvalidFlag) GoToSleep(periodicCounter); else { ToggleSleepGPS(); //Turn GPS off Hibernate(); ToggleSleepGPS(); //Turn GPS on } } } return (EXIT_SUCCESS); }