void main(void) { /* disable all interrupts before peripherals are initialized */ __disable_irq(); /* init application ports */ InitPORT(); InitPWM(); InitADC(); //Init_PIT(); int i = 0; for(i = 0; i < 1000; i++){}; ADC_WR_CTRL1_START0(ADC, 1); /* LED for test */ PORT_WR_PCR_MUX(PORTB, 22, 1); GPIO_SET_PDDR(PTB, 1<<22); GPIO_WR_PSOR(PTB, 1<<22); /* enable interrupts */ __enable_irq(); /* infinite loop */ while(1){} }
/*************************************************** * Function: InitializeDevice(void) * * OverView: Initialize Device Port, LED, Switches, ADC, PWM, TIMER, ETC.. * * Note: None ***************************************************/ void InitializeDevice(void) { //Initialize all of the LED pins mInitAllLEDs(); LED_INIT(); //Initialize all of the push buttons mInitAllSwitches(); //initialize adc for ntc sensor InitADC(); //initialize lid heater InitHeater(); //initialize fan Init_ChamberFan(); Init_SystemFan(); //initialize pwm Stop_PWM_MODE(); //initialize fan & heater control with timer0 TIMR0_init(); //pcr task tick TIMR1_init(); }
void main() { P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P6M0 = 0x00; P6M1 = 0x00; P7M0 = 0x00; P7M1 = 0x00; InitUart(); //初始化串口 InitADC(); //初始化ADC IE = 0xa0; //使能ADC中断 //开始AD转换 while (1); }
int main(void) { //uses a 12MHz crystal because I messed the fuses ... so let's go slowly and run 1/256th of that speed to save electricity //EDIT: I managed to rechange the fuses to internal 8MHz oscillator, save 3 mA power CLKPR = (1 << CLKPCE) | (1 << CLKPS3); //PORTD is the 7segment control, everybody goes output DDRD = 0xFF; //PORTC bits [5-2] control which 7segment is selected //bits [1-0] are for input of temperature DDRC = 0b11111100; //start with all segments off PORTC = 0x00; //init the ADC InitADC(); //SimpleTestDigit(); //numbers99dot9(); //TestAllSegments(); /*********************************************************************/ cli(); // quiet for just a moment ShutOffADC(); // prepare ADC for sleep PRR = (1<<PRTWI) | (1<<PRTIM0) | (1<<PRTIM1) | (1<<PRTIM2) | (1<<PRSPI) | (1<<PRADC) | (1<<PRUSART0); /*********************************************************************/ ReadTemp(); }
int main(void) { // Setup any needed hardware SetupUART(8); SetupTimer(); SetupAccelerometer(TWOG, EIGHTBITS); InitADC(); // Enable global interrupts sei(); PORTB &= ~(_BV(PORTB5)); // Clear PB5, so it drives low by default (need to do this before switching it to an output) DDRB |= _BV(PORTB5); // Set PB5 as an output // Test data struct SensorData data; while(1) { if(ready_to_send) { SetupPulseSensor(); while(ADCSRA & _BV(ADSC)); //wait for conversion to finish DISCARD RESULT ADCSRA |= _BV(ADSC); //Start real conversion while(ADCSRA & _BV(ADSC)); //wait for conversion to finish USE RESULT data.pulse_val = ADCH; //save result of pulse sensor _delay_us(9); SetupGSR(); while(ADCSRA & _BV(ADSC)); //wait for conversion to finish DISCARD RESULT ADCSRA |= _BV(ADSC); //Start real conversion while(ADCSRA & _BV(ADSC)); //wait for conversion to finish USE RESULT data.gsr_val = ADCH; //save result of GSR sensor _delay_us(9); // Grab the accelerometer data AccelGetData(&data); // Send some bytes so RealTerm can sync to it UARTTransmit(0xAA); UARTTransmit(24); // Send the data UARTTransmit(data.pulse_val); UARTTransmit(data.gsr_val + 15); UARTTransmit(data.accel_x + 128); UARTTransmit(data.accel_y + 128); UARTTransmit(data.accel_z + 128); UARTTransmit(0); UARTTransmit(0); //to fill the UART receive fifo buffer in the tiva board for interrupt ready_to_send = false; } } }
//todo: This has been generalized into the multi-channel function below. It can probably be removed. void initFreeRunADCAllChannels() { //disable global interrupts cli(); //set a variable so the ISR know we want to sample all the channels ADCVars.ADCSampleAllChannels = 1; ADCVars.ADCMultiChannelMask = 0; //initialize the ADC for(char channel=0; channel < 8; channel++) { InitADC(channel); } //Enable auto trigger ADCSRAbits._ADATE = 1; //Set ADC to free run mode ADCSRBbits._ADTS0 = 0; ADCSRBbits._ADTS1 = 0; ADCSRBbits._ADTS2 = 0; //Enable ADC interrupts ADCSRAbits._ADIE = 1; //Set first for autoADC ADMUX &= 0b11100000; //Start first conversion, ADC will automatically start subsequent conversions after each is completed ADCSRAbits._ADSC = 1; //enable global interrupts sei(); }
/***** Initialisation *****/ void init() { unsigned char i ; cli(); // Désactiver toutes les interruptions sDDR(DDRD,1); // mettre port TX en sortie sbiBF(PORTD,0); // mettre pull-up sur RX for(i=0;i<=4;i++) // Initialiser les demandes à 0 qui signifie qu'il n'y a pas de demande de la part de la FoxBoard { data[i]=0x00; } i2c_init(); // Initialisation interface I2C init_3964r(); // Initialisation de la communication en protocole 3964 avec la FoxBoard ENABLE_RX_INT_USART; // Autoriser les interruption série RX fonctionnement_RX = 1; // mode de réception init_watchdog(); // Initilise les reset InitADC(); // Initialise les ADC sei(); // Activer toutes les interruptions }
int main(void) { /* Setup serial port */ uart_init(); stdout = &uart_output; stdin = &uart_input; printf("Hello world!\r\n"); InitADC(); moveStop(); // Setup ports DDRB |= (1<<1) | (1<<0); PORTB |= (1<<0); PORTB &= ~(1<<1); /* Print hello and then echo serial ** port data while blinking LED */ //printf("Hello world!\r\n"); //PORTB ^= 0x01; while(1) { manual_mode(); } }
int main(void) { int counter = 0; int buffer[1024]; InitLED(); InitADC(); for(;;) { counter++; buffer[counter%1024]=singleCapture()-32768; // wait(); if ((counter%1024)==0) { /* blink LED slowly so it is better visible */ NegLED(); } // buffer[counter%64]=counter; /* printf("Enter a string:\r\n"); if (gets(buffer)!=NULL) { printf("you entered: %s\r\n", buffer); } */ } return 0; }
int main( void ) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1=0x00; //&= ~XT2OFF; // XT2= HF XTAL do{ IFG1 &= ~OFIFG; // Clear OSCFault flag for (int i = 0xFF; i > 0; i--); // Time for flag to set }while ((IFG1 & OFIFG)); // OSCFault flag still set? BCSCTL2 |= SELM_2+SELS; // MCLK=SMCLK=XT2 (safe) //Init System Service InitialPort(); InitFileSystem(); Init_Pipe(); InitTB(); //Init Device InitialRTC(); Init_UART(); InitADC(); Creat_Command_Task(); //After the bluetooth has beed connected SCH_Init(); SCH_Start(); // SCH_Add_Task(Task_UART_Send,0,5); //creat a task for sending data via uart,after bluetooth connect // SCH_Add_Task(Acquire_ECG,0,4); //32768/4*32 = 256hz // CommandSwitchList(1); while(1){ SCH_Dispatch_Task(); } }
void main(void) { //------- INTERNAL INIT------------// InitSysCtrl(); DINT; //Disable CPU interrupts InitPieCtrl(); IER = 0x0000; //Disable CPU interrupts and clear all CPU interrupt flags: IFR = 0x0000; InitPieVectTable(); //------- END INTERNAL INIT--------// InitPWM3(); InitDACA(); InitDACC(); InitADC(); //PLL 1PHASE// SPLL_1ph_F_init(50,((float)(1.0/200000.0F)), &spll1); SPLL_1ph_F_notch_coeff_update(((float)(1.0/50000.0F)), (float)(2*PI*50*2),(float)0.00001,(float)0.1, &spll1); while(1) { } }
int main() { int tmren = 0; ini_lcd(); InitADC(); timer1_init(); cli(); CLR_BIT(DDRA, 1); puts_lcd2("I:---- AVG:----"); pos_lcd(1, 0); puts_lcd2("Mi:---- Ma:----"); while(1) { wait_btn(); if(tmren) { cli(); tmren = 0; } else { sei(); tmren = 1; } } }
int main(void) { uint16_t tempSensor, battery; uint8_t capPushA, capPushB; uint8_t it=1; InitWDT(); InitCLOCK(); InitUART(); InitLED(); InitADC(); InitBuzzer(); InitCapPush(); EnableInterrupts(); while (1) { it--; if(it == 0) { it = 4; capPushA = senseCapPushA(); capPushB = senseCapPushB(); tempSensor = ReadTemp(); battery = ReadBattery(); MainLoop(capPushA, capPushB, tempSensor, battery); } SetupWDTToWakeUpCPU(2); // Wake up in 16 mS Sleep(); } return 0; }
int main(void) { uint16_t adc_result; int i; char value[10]; sbi(DDRB, 4); sbi(DDRC, 5); cbi(PORTB,4); sbi(PORTC,5); UART_init(250000); InitADC(); sei(); while(1) { adc_result=ReadADC(2); // Read Analog value from channel-2 // Voltage = adc_result*5/1024 // Temperature = (V - 1035 mV)/(-5.5 (mV/oC)) itoa(adc_result,value,10); for(i=0;i<=2;i++){ UART_TxChar(value[i]);} UART_TxStr("\n\r\0"); PORTB ^= (1<<PB4); _delay_ms(100); } }
//Initialize system void Init() { unsigned int i; IFG1 &= ~OFIFG; // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; //Adjust DCO frequency // //DCOCTL = DCO0 + DOC1 +DOC2; // DCOCTL = 0x80; // BCSCTL1 = XT2OFF + RSEL0 + RSEL1 + RSEL2; // BCSCTL2 = 0; //调整DCO的频率 DCOCTL = 0xE0; //切换MCLK到外部高速晶振(需要检测是否起振) //BCSCTL1 &= ~XT2OFF; //启动高速晶振 BCSCTL1 = RSEL0 + RSEL1 + RSEL2; do { //清除振荡器失效标志位,再延迟检查 IFG1 &= ~OFIFG; for (i = 0; i < 1000; i++) { __no_operation(); } } while (IFG1 & OFIFG); //使用XT2, SMCLK = MCLK = 8MHz BCSCTL2 = SELM1 + SELS; //允许外部振荡器失效后,重启系统 IE1 |= OFIE; InitPort(); InitUART(); InitADC(); InitSPI(); InitRF(); InitSensors(); InitTimer(); ShutdownModule(); }
/** ****************************************************************************** ** Main application to control the program flow *****************************************************************************/ void main(void) { // Initialize all interrupt levels of resources Vectors_InitIrqLevels(); // Allow all interrupt levels __set_il(7); // Enable interrupts __EI(); Flash_EnableWriting(); InitLCD(); #if ((SMC_TYPE != SMC_TYPE_R200) && (ZPD == ZPD_ENABLE)) ZPD_Init(); //ќжидание окончани¤ ZPD while (m_enSmcMode == Zpd) { WDTCP = 0x00; } #else m_enSmcMode = NormalDriving; #endif InitSMC(20); Timer_Init(); InitADC(); InitRTC(); // ≈сли двигатель R200 или ZPD не активно #if ((SMC_TYPE == SMC_TYPE_R200) || (ZPD == ZPD_DISABLE)) ZeroPosSMC(); Timer_Wait(TIMER_ID_MAIN, 2000, TRUE); #endif ClearPosSMC(); DriverInit(); InitFRTimer0(); InitExtInt0(); //test Init_4_imp(); InitBacklight(); Button_Init(ButtonCallback); CAN_Init(); J1939_init(); InitUsart0(); if (Button_GetCurrentButtonState(BUTTON_ID_B1) == StateLow) SetModePass(); while(1) { WDTCP_ = 0x00; Timer_Main(); } }
void Init(void) { InitPort(); InitTris(); InitAnsel(); InitMiscellaneous(); InitTransmission(); InitADC(); InitVar(); InitInterrupt(); }
void main(void) { initialize_ports(); //initialize ports InitADC(); while(1){//main loop new_digital = ReadADC(0x20);//read analog input on PORTC pin0, left justify if(new_digital != old_digital){ //process change PORTB=new_digital; //in PORTB input } //end if new_PORTC old_digital=new_digital;//update PORTC } //end while(1) } //end main
/* Description: Initialises the teensy, SPI module, transceiver and ADC module. */ void Init() { // Set inputs. DDRD |= SHIFT(DDD1) | SHIFT(NIRQ); PORTD |= SHIFT(PORTD1) | SHIFT(NIRQ); InitADC(); InitSPI(); InitAlpha(); }
void user_io_init() { // no sd card image selected, SD card accesses will go directly // to the card sd_image.size = 0; // mark remap table as unused memset(key_remap_table, 0, sizeof(key_remap_table)); InitADC(); ikbd_init(); }
int main(void) //main body calls all other functions to initialize the proper values of the Transmission protocol, timer and ADC module, then starts them { InitialzeLCD(); //initializes LCD SetADCChannel(5); // sets ADC channel for temperature sensor InitADC(); // Initializes ADC and timer below to 1 second InitTimer(); startTimer(); startADC(); while(1) { // Main loop } }
/***************************************************************************** * showADC - Displays ADC reading on the LCD display. *****************************************************************************/ void showADC(void) { InitADC(); while (!(getkey() == 1)) { gyroRaw = GetADC(gyro_sensor); accelRaw = GetADC(accel_sensor); TimerWait(100); show12bits(gyroRaw, accelRaw); } LCD_ShowColons(0); }
/* * * The channels to be sampled are specified by a bit mask. E.x. 0b01100001 would automatically sample ADC channels 0, 5, and 6. The results are still stored in the ADCValues register corresponding to the sampled channel. * */ void initFreeRunMultiADCChannels(uint8_t channelMask){ //ensure a proper channelMask was passed in with at least 1 selected channel if (channelMask) { //disable global interrupts cli(); //set a variable so the ISR knows we want to sample only certain channels as specified by the channel mask ADCVars.ADCSampleAllChannels = 1; ADCVars.ADCMultiChannelMask = channelMask; //initialize the ADC for(char channel=0; channel < 8; channel++) { if((channelMask >> channel) & 1) { InitADC(channel); } } //Enable auto trigger ADCSRAbits._ADATE = 1; //Set ADC to free run mode ADCSRBbits._ADTS0 = 0; ADCSRBbits._ADTS1 = 0; ADCSRBbits._ADTS2 = 0; //Enable ADC interrupts ADCSRAbits._ADIE = 1; //Set first channel for autoADC ADMUX &= 0b11100000; char channel = 0; while (!((channelMask >> channel) & 1)) { channel++; } ADMUX |= channel; ADCVars.MultiChannelStart = channel; //Find last channel for use in ISR channel = 7; while (!((channelMask >> channel) & 1)) { channel--; } ADCVars.MultiChannelEnd = channel; //Start first conversion, ADC will automatically start subsequent conversions after each is completed ADCSRAbits._ADSC = 1; //enable global interrupts sei(); } }
void init_hw(void){ //Init I2C bus i2c_init(I2C_ADDRESS,1); sei(); // sbi( DDR_IR, E_IR ); // Set IR Enable as Output // DDRB = E_IR; Init_PWM(); InitADC(ADC_REFERENCE_AVCC, ADC_PRESCALE_DIV8); // OCR1B = 0x01; // GREEN RGB[0] = 0xf9; // RED RGB[1] = 0xf9; // GREEN RGB[2] = 0xf9; // BLUE }
int main(void) { float tempf; InitRCC(); InitGPIO(); InitADC(); I2CInit(); InitIT(); Delay_Init(24); // reset pot value PotWrite(0x00); while(1) { if (mode == MODE_CAL) { LED_GREEN_ON(); LED_RED_OFF(); uint16_t av = ADC_GetConversionValue(AN_ADCx); if (av > trig_level) { trig_level = av; tempf = GetADCVolt(trig_level)*VOLT_DIV; // get voltage from piezo tempf = GetTargetK(tempf); // get target amp coefficient tempf = GetTargetR(tempf); // get R2 for opamp feedback tempf = GetPotR(tempf); // get target resistance for pot as part of R2 PotWrite(GetWStep(tempf)); // write step to pot } } else { // turn on red for working mode indication, turn green if mcu gets opamp output high LED_RED_ON(); if (GPIO_ReadInputDataBit(OP_PORT, OP_PIN) == SET) { LED_GREEN_ON(); delay_ms(500); } else { LED_GREEN_OFF(); } } } }
int main(void) { uint8_t count, second=0; uint32_t val; InitUART0 (); InitRTC(); UART0_dbg_msg ( "********************************************************************************\n\r" " Internal DAC test of LPC1788\n\r" "\t - UART Comunication: 9600 bps \n\r" " Write to debug console current voltage on AD[2]-AD[3]\n\r" "********************************************************************************\n\r"); if (!InitADC (2)) { UART0_dbg_msg ("InitADC exception, channel must be 0..7\n\r"); while (1); } InitDAC (0x03FF); while (1) { //input DAC value do { UART0_dbg_msg ("Input DAC value in range 0..1023, as a sample 0983\n\r"); while (!UART0_get_dec (&val,4)) UART0_dbg_msg ("DAC value is 10-bit number\n\r"); if (val>1024) { UART0_dbg_msg ("DAC value isn't in range 0..1023\n\r"); UART0_clear_rx_buffer(); } } while (val>1024); count=0; //Set DAC value SetDAC(val); //Convert DAC value through ADC 5 times while(count<5) { if (second != LPC_RTC->SEC) { second=LPC_RTC->SEC; ADC_dbg(GetADC()); count++; } } } }
int main(int argc, char** argv) { ADPCFG = 0xFFFF; //RA only digit InitADC(); FramInitialization(); //WriteAllParameters(); ReadConfig(); TRISDbits.TRISD8 = 0;//set output on RD8 TRISDbits.TRISD9 = 0;//set output on RD9 LATDbits.LATD8 = 0; // LE1 LATDbits.LATD9 = 0; // LE2 Delay(3000000); TRISCbits.TRISC13 = 0;//set output on RC13 LATCbits.LATC13 = 1; halfS = (labs(_lowEdge)+labs(_highEdge))/2 - labs(_highEdge); halfV = Vmax/2; halfVstart = Vstart/2; //int i = 0; //for(i; i < 10000; i++) //{ //ForwardDirectionStroke(); //Delay(2000); //LATCbits.LATC13 = 1 - LATCbits.LATC13; // RC13 value (LED VD1 => ON) //} Can1Initialization(); InitCounter(); WriteOutputSignals(1); // float distancePerMark = DISTANCE_PER_MARK; /* StartTimer1(); StartTimer2(); StartTimer3(); */ while(1) { if(in_ptr != out_ptr) { CanOpenParseRSDO(sdoBuf[out_ptr].sId,sdoBuf[out_ptr].rxData,1); //parse message and send response out_ptr++; out_ptr &= BUF_PACK_MASK; } } return (EXIT_SUCCESS); }
void StartCore(void) { PORTB = 0xAA; DDRB = 0xFF; // 初始化小按键 DDRP_DDRP0 = 0; PPSP_PPSP0 = 0; PERP_PERP0 = 1; /********************************/ /* 初始化 */ InitServo(); StartServo(); SetServo(90); InitSpeeder(); irInit(); InitADC(); InitSCI0(); WaitEnable(); /*******************************/ GetBlackAndWhite(); PORTB = 0x55; Wait(1500); PORTB = 0xAA; while (PTIP_PTIP0); PORTB = 0x5A; Wait(1000); PORTB = 0xA5; CoreControl(); }
int main(void) { // Check that you flashed to the correct microcontroller uint32_t chipId1 = TM_ID_GetUnique32(0); uint32_t chipId2 = TM_ID_GetUnique32(1); uint32_t chipId3 = TM_ID_GetUnique32(2); if(chipId1 != 0x00290044 || chipId2 != 0x30345117 || chipId3 != 0x37333838){ while(1); } // Configure the system clock. // The system clock is 168Mhz. RCC_HSEConfig(RCC_HSE_ON); // ENABLE HSE (HSE = 8Mhz) while(!RCC_WaitForHSEStartUp()); // Wait for HSE to stabilize SystemCoreClockUpdate(); RCC_PCLK1Config(RCC_HCLK_Div4); // Set APB1=42Mhz (168/4) // Initialize peripheral modules InitGPIO(); InitNVIC(); InitPedalIntegrity(); InitADC(); InitCAN(); // MCO_Config(); // Clock output /* Main code */ while(1) { Delay(0xFF); /* if(CAN_GetITStatus(CAN1,CAN_IT_FMP0) == SET){ CAN_Receive(CAN1,CAN_FIFO0,&msgRx); if(msgRx.StdId == 0x1){ GPIOC->ODR |= GPIO_Pin_6; } } */ } }
int main(void) { //factory settings is to divide internal clock 8MHz by 8. //don't, and just run at 8 MHz (set the clock divider to 1 so no effect) CLKPR = (1<<CLKPCE); CLKPR = 0; // Divide by 1 setup7seg(); InitADC(); setupTimer0(); //start the interrupts sei(); while(1) { showNumber((uint16_t)(mLatestPower), 0, 2, false); } }