int main(void) { DDRA=0xFF; PORTA=0x00; uint8_t time[3]; uint8_t Flag,Flag1; usartInit(); printf("*--------------------------------------------------- *\r\n"); printf("*-------------------AT24CXX experiment-------------- *\r\n"); printf("*--------------------------------------------------- *\r\n"); twi_init(); PCF8563_init(); PCF8563_setTime(0,0,0); while(1) { while(1) { PCF8563_getTime(time); if(Flag1 != Flag) { PORTA = time[0]; printf("Real time clock %d:%d:%d \r \n",time[2],time[1],time[0]); Flag1=Flag; } Flag = time[0]; } } }
/************************************************************* * Main function ************************************************************/ int main(void) { int err; bootparam_t bootparam; //Initial initialisation pmClkInit(FCPU, FPBA); usartInit(USART0, &usart0_options, FPBA); //Init serial communication usartWriteLine(USART0, version); ledInit(); usartWriteLine(USART0, "Preinit done.\nGetting bootparm.txt...\n"); //Load boot parameters from SD-card bootparam = bootparamLoad("bootparm.txt"); done(); //Second init according to boot parameters //pmClkReInit(bootparam.fcpu, bootparam.fpba); usartWriteLine(USART0, "reinit USART"); usartSetBaudrate(USART0, bootparam.baudrate, bootparam.fpba); done(); usartWriteLine(USART0, "Init SDRAM..."); sdramInit(bootparam.fcpu); done(); spiReset(&AVR32_SPI1); //Optional loading a banner from SD-card and display on terminal. usartWriteLine(USART0, "Loading banner..."); banner(&bootparam); done(); //Boot file from SD-card, according to the bootparam.txt that should exist //on the SD-card. Otherwise default settings will be used. //If the boot is successful we (probably) never come back here. //If the boot is unsuccessful we come back here. usartWriteLine(USART0, "Loading bootfile, wait at least 15 sec..."); err = boot(&bootparam); if(err) { //TODO: Booting another file might NOT be the proper way to handle failure to load the user specified file. Reconsider! usartWriteLine(USART0, "\nCould not boot "); usartWriteLine(USART0, bootparam.bootfile); usartWriteLine(USART0, "\nWarning: Trying to boot "); usartWriteLine(USART0, DEFAULT_AUTORUN_FILE); strcpy(bootparam.bootfile, DEFAULT_AUTORUN_FILE); err = boot(&bootparam); } if(err) { /* Execution will only return to here on error */ usartWriteLine(USART0, "\nError booting, stopping here."); while(1); //TODO: Sleep } while(1); //TODO: Sleep }
int main (void){ usartInit(); initLCD(); while (1){ LCDGotoXY(0,0); LCDstring(LCDBuffer, 1); } return 0; }
void setupDefault() { //UIO as Input UIO_DIRECTION = UIO_DEFAULT_DIRECTION; UIO_OUTPUT = 0b00000000; //DDRB = 0x00; //DDRC = 0x00; //DDRD = 0x00; //PORTB = 0xff; //PORTC = 0xff; //PORTD = 0xff; //DBG_LEDS DDRD |= (1 << DBG_LED1); DDRD |= (1 << DBG_LED2); DDRD |= (1 << DBG_LED3); //DAC1 DDRB |= (1 << DS_DAC1); DDRB |= (1 << STCP_DAC1); DDRB |= (1 << SHCP_DAC1); DDRB |= (1 << MR_DAC1); //DAC2 DDRC |= (1 << DS_DAC2); DDRC |= (1 << STCP_DAC2); DDRC |= (1 << SHCP_DAC2); DDRC |= (1 << MR_DAC2); DDRC |= (1 << EEPROM_WP); dacPinHigh(DAC1, MR_DAC1); dacPinHigh(DAC2, MR_DAC2); resetDac(DAC1); resetDac(DAC2); //EEPROM WP disableEepromWriteProtect(); //ADC //adcInit(); //USART usartInit(); //I2C i2cInit(); //Enable interrupts sei(); }
int main(void) { uint8_t num; uint8_t tmp[255]; uint8_t f_value=0; usartInit(); printf("*--------------------------------------------------- *\r\n"); printf("*-------------------AT45DBXX experiment-------------- *\r\n"); printf("*--------------------------------------------------- *\r\n"); DDRA=0xFF; spiInitAt45db(); printf("FALSH AT45DBXX Write Test \r\n"); for(num=0;num<255;num++) /*Written to the flash*/ { write_buffer((uint16_t)num,num); _delay_ms(1); } printf("FALSH AT45DBXX Read Test \r\n"); for(num=0;num<255;num++) /*Read the flash*/ { tmp[num]=read_buffer(num); _delay_ms(1); } for(num=0;num<255;num++) { if(tmp[num]==num) { f_value++; // printf("FALSH AT45DBXX Read :%x \r\n",tmp[num]); } } if(f_value==0xff) { f_value=0; printf("FALSH AT45DBXX Read Test OK \r\n"); } else printf("FALSH AT45DBXX Read Test failure\r\n"); while(1); }
int main(void) { usartInit(); printf("*--------------------------------------------------- *\r\n"); printf("*-------------------DS18B20 experiment-------------- *\r\n"); printf("*--------------------------------------------------- *\r\n"); while(1) { printf("Temperture:%d.%d¡æ\n\r ",readTemp()/100,readTemp()%100); _delay_ms(1000); } }
int main(void) { /*Change Baud Rate */ usartInit(); /* Initialize analog converter */ adc_init(); adc_resolution(ADC_10BIT); //check 8 bit! /* Set up 2 second Clock */ interval_clock_init(); sei(); while(1); }
int main(void) { DDRB=0xFF; PORTB=0x00; sei(); //turn on global interrupt usartInit(); while(1) { putUsart0(0x55); /* putUsart0(tmp); _delay_ms(10); PORTB=(uint8_t)getUsart0(); tmp++; _delay_ms(500);*/ } }
THD_TABLE_END /* * Application entry point. */ int main(void) { /* * System initializations: * - HW specific initialization. * - Nil RTOS initialization. */ halInit(); settingsInit(); usartInit(DBG_USART); chSysInit(); /* This is now the idle thread loop, you may perform here a low priority task but you must never try to sleep or wait in this loop.*/ while (true) {}; }
int main() { usartInit(57600); usartEnableReceiver(); usartEnableTransmitter(); usartStdio(); setBit(DDRB, M1_DIR); setBit(DDRD, M1_PWM); setBit(DDRD, M2_DIR); setBit(DDRD, M2_PWM); clrBit(PORTB, M1_DIR); clrBit(PORTD, M1_PWM); clrBit(PORTD, M2_PWM); clrBit(PORTD, M2_DIR); timer0FastPWMMaxMode(); timer0ClockPrescaller64(); timer0OC0ANonInvertedMode(); timer0OC0BNonInvertedMode(); timer0SetCompareAValue(0); timer0SetCompareBValue(0); timer0DeactivateCompareAInterrupt(); timer0DeactivateCompareBInterrupt(); timer2ClockPrescaller256(); timer2NormalMode(); timer2OC2AOff(); timer2OC2BOff(); timer2ActivateOverflowInterrupt(); i2c_init(); adxl345_init(); l3g4200d_init(); l3g4200d_setoffset(0.11, -1.71, -0.46); //l3g4200d_settemperatureref(); PID_init(&PID, 15,0.2,1, 0); PID_SetMode(&PID, 1); PID_SetOutputLimits(&PID, -255, 255); PID.mySetpoint = 0; motor1(0); motor2(0); // printf("\e[1;1H\e[2J"); // printf("STARTED!\r\n"); // _delay_ms(200); // motor1(120); // printf("Motor1 = 120\r\n"); // _delay_ms(500); // motor1(-120); // printf("Motor1 = -120\r\n"); // _delay_ms(500); // motor1(120); // printf("Motor1 = 120\r\n"); // _delay_ms(500); // motor1(0); // printf("Motor1 = 0\r\n"); sei(); while(1); return 0; }
// Called once at startup // void mainInit(void) { xdata uint8 thisByte = 0xFF; xdata uint16 blockSize; // This is only necessary for cases where you want to load firmware into the RAM of an FX2 that // has already loaded firmware from an EEPROM. It should definitely be removed for firmwares // which are themselves to be loaded from EEPROM. #ifndef EEPROM RENUMERATE_UNCOND(); #endif // Disable alternate functions for PORTA 0,1,3 & 7. PORTACFG = 0x00; // Return FIFO setings back to default just in case previous firmware messed with them. SYNCDELAY; PINFLAGSAB = 0x00; SYNCDELAY; PINFLAGSCD = 0x00; SYNCDELAY; FIFOPINPOLAR = 0x00; // Global settings SYNCDELAY; REVCTL = (bmDYN_OUT | bmENH_PKT); SYNCDELAY; CPUCS = bmCLKSPD1; // 48MHz // Drive IFCLK at 48MHz, enable slave FIFOs SYNCDELAY; IFCONFIG = (bmIFCLKSRC | bm3048MHZ | bmIFCLKOE | bmFIFOS); // EP4 & EP8 are unused SYNCDELAY; EP4CFG = 0x00; SYNCDELAY; EP8CFG = 0x00; SYNCDELAY; EP4FIFOCFG = 0x00; SYNCDELAY; EP8FIFOCFG = 0x00; // EP1OUT & EP1IN SYNCDELAY; EP1OUTCFG = (bmVALID | bmBULK); SYNCDELAY; EP1INCFG = (bmVALID | bmBULK); // EP2OUT & EP6IN are quad-buffered bulk endpoints SYNCDELAY; EP2CFG = (bmVALID | bmBULK); SYNCDELAY; EP6CFG = (bmVALID | bmBULK | bmDIR); // Reset FIFOs for EP2OUT & EP6IN SYNCDELAY; FIFORESET = bmNAKALL; SYNCDELAY; FIFORESET = 2; // reset EP2OUT SYNCDELAY; FIFORESET = 6; // reset EP6IN SYNCDELAY; FIFORESET = 0x00; // Arm EP1OUT EP1OUTBC = 0x00; // Arm the EP2OUT buffers. Done four times because it's quad-buffered SYNCDELAY; OUTPKTEND = bmSKIP | 2; // EP2OUT SYNCDELAY; OUTPKTEND = bmSKIP | 2; SYNCDELAY; OUTPKTEND = bmSKIP | 2; SYNCDELAY; OUTPKTEND = bmSKIP | 2; // EP2OUT & EP6IN automatically commit packets SYNCDELAY; EP2FIFOCFG = bmAUTOOUT; SYNCDELAY; EP6FIFOCFG = bmAUTOIN; // Auto-commit 512-byte packets from EP6IN (master may commit early by asserting PKTEND) SYNCDELAY; EP6AUTOINLENH = 0x02; SYNCDELAY; EP6AUTOINLENL = 0x00; // Turbo I2C I2CTL |= bm400KHZ; // Auto-pointers AUTOPTRSETUP = bmAPTREN | bmAPTR1INC | bmAPTR2INC; // Port lines... IOA = 0x00; OEA = 0x00; IOC = 0x00; OEC = 0x00; IOD = 0x00; OED = 0x00; IOE = 0x00; OEE = 0x00; // Disable JTAG mode by default (i.e don't drive JTAG pins) jtagSetEnabled(false); #ifdef BOOT promStartRead(false, 0x0000); if ( promPeekByte() == 0xC2 ) { promNextByte(); // VID(L) promNextByte(); // VID(H) promNextByte(); // PID(L) promNextByte(); // PID(H) promNextByte(); // DID(L) promNextByte(); // DID(H) promNextByte(); // Config byte promNextByte(); // Length(H) thisByte = promPeekByte(); while ( !(thisByte & 0x80) ) { blockSize = thisByte; blockSize <<= 8; promNextByte(); // Length(L) blockSize |= promPeekByte(); blockSize += 2; // Space taken by address while ( blockSize-- ) { promNextByte(); } promNextByte(); // Length(H) thisByte = promPeekByte(); } promNextByte(); // Length(L) promNextByte(); // Address(H) promNextByte(); // Address(L) promNextByte(); // Last byte promNextByte(); // First byte after the end of the firmware } jtagSetEnabled(true); jtagCsvfInit(); m_diagnosticCode = jtagCsvfPlay(); jtagSetEnabled(false); thisByte = promPeekByte(); promNextByte(); blockSize = promPeekByte(); promNextByte(); blockSize <<= 8; blockSize |= promPeekByte(); promNextByte(); if ( thisByte ) { if ( blockSize ) { fifoSendPromData(0x10000UL + blockSize); } } else if ( blockSize ) { fifoSendPromData(blockSize); } promStopRead(); USBCS &= ~bmDISCON; #endif #ifdef DEBUG usartInit(); usartSendString("MakeStuff FPGALink/FX2 v1.1\r"); #endif initPorts(); }
// Called once at startup // void mainInit(void) { xdata uint8 thisByte = 0xFF; xdata uint16 blockSize; setIntCount = 23; // This is only necessary for cases where you want to load firmware into the RAM of an FX2 that // has already loaded firmware from an EEPROM. It should definitely be removed for firmwares // which are themselves to be loaded from EEPROM. #ifndef EEPROM RENUMERATE_UNCOND(); #endif // Disable alternate functions for PORTA 0,1,3 & 7. PORTACFG = 0x00; // Return FIFO setings back to default just in case previous firmware messed with them. SYNCDELAY; PINFLAGSAB = 0x00; SYNCDELAY; PINFLAGSCD = 0x00; SYNCDELAY; FIFOPINPOLAR = 0x00; // Global settings SYNCDELAY; REVCTL = (bmDYN_OUT | bmENH_PKT); SYNCDELAY; CPUCS = bmCLKSPD1; // 48MHz // Drive IFCLK at 48MHz, enable slave FIFOs //SYNCDELAY; IFCONFIG = (bmIFCLKSRC | bm3048MHZ | bmIFCLKOE | bmFIFOS); SYNCDELAY; IFCONFIG = (bmIFCLKSRC | bm3048MHZ | bmIFCLKOE | bmPORTS); // EP4 & EP8 are unused SYNCDELAY; EP4CFG = 0x00; SYNCDELAY; EP8CFG = 0x00; SYNCDELAY; EP4FIFOCFG = 0x00; SYNCDELAY; EP8FIFOCFG = 0x00; // EP1OUT & EP1IN SYNCDELAY; EP1OUTCFG = (bmVALID | bmBULK); SYNCDELAY; EP1INCFG = (bmVALID | bmBULK); // EP2OUT & EP6IN are quad-buffered bulk endpoints SYNCDELAY; EP2CFG = (bmVALID | bmBULK); SYNCDELAY; EP6CFG = (bmVALID | bmBULK | bmDIR); // Reset FIFOs for EP2OUT & EP6IN SYNCDELAY; FIFORESET = bmNAKALL; SYNCDELAY; FIFORESET = 2; // reset EP2OUT SYNCDELAY; FIFORESET = 6; // reset EP6IN SYNCDELAY; FIFORESET = 0x00; // Arm EP1OUT EP1OUTBC = 0x00; // Arm the EP2OUT buffers. Done four times because it's quad-buffered SYNCDELAY; OUTPKTEND = bmSKIP | 2; // EP2OUT SYNCDELAY; OUTPKTEND = bmSKIP | 2; SYNCDELAY; OUTPKTEND = bmSKIP | 2; SYNCDELAY; OUTPKTEND = bmSKIP | 2; // EP2OUT & EP6IN automatically commit packets SYNCDELAY; EP2FIFOCFG = bmAUTOOUT; SYNCDELAY; EP6FIFOCFG = bmAUTOIN; // Auto-commit 512-byte packets from EP6IN (master may commit early by asserting PKTEND) SYNCDELAY; EP6AUTOINLENH = 0x02; SYNCDELAY; EP6AUTOINLENL = 0x00; // Turbo I2C I2CTL |= bm400KHZ; // Auto-pointers AUTOPTRSETUP = bmAPTREN | bmAPTR1INC | bmAPTR2INC; // Port lines all inputs... IOA = 0xFF; OEA = 0x00; IOB = 0xFF; OEB = 0x00; IOC = 0xFF; OEC = 0x00; IOD = 0xFF; OED = 0x00; IOE = 0xFF; OEE = 0x00; #ifdef EEPROM #include "init.inc" #endif #ifdef DEBUG usartInit(); usartSendString("MakeStuff FPGALink/FX2 v1.1\r"); #endif }
// Private functions void usartTask_initHW(void) { usartInit(); rtcInit(); consoleInit(); }
// Init a typical hc05 bluetooth module void hc05Init(char uart, bool atMode) { FILE *uFile = uart == 1 ? uart1 : uart2; usartInit(uFile, atMode ? 38400 : 9600, SERIAL_STOPBITS_1 | SERIAL_PARITY_NONE | SERIAL_DATABITS_8); }
// Called once at startup // void mainInit(void) { __xdata uint8 thisByte = 0xFF; __xdata uint16 blockSize; // This is only necessary for cases where you want to load firmware into the RAM of an FX2 that // has already loaded firmware from an EEPROM. It should definitely be removed for firmwares // which are themselves to be loaded from EEPROM. #ifndef EEPROM RENUMERATE_UNCOND(); #endif // Needs to be matched to stuff in HDMI2USB/cypress/hdmi2usb.c TD_Init // void TD_Init(void) // Called once at startup // Clear wakeup (see AN15813: http://www.cypress.com/?docID=4633) WAKEUPCS = bmWU | bmDPEN | bmWUEN; WAKEUPCS = bmWU | bmDPEN | bmWUEN; // Disable alternate functions for PORTA 0,1,3 & 7. PORTACFG = 0x00; /* // Return FIFO settings back to default just in case previous firmware messed with them. SYNCDELAY; PINFLAGSAB = 0x00; SYNCDELAY; PINFLAGSCD = 0x00; SYNCDELAY; FIFOPINPOLAR = 0x00; // Global settings SYNCDELAY; REVCTL = (bmDYN_OUT | bmENH_PKT); // 0x03 SYNCDELAY; CPUCS = bmCLKSPD1; // 48MHz 0x10 // Drive IFCLK at 48MHz, enable slave FIFOs //SYNCDELAY; IFCONFIG = (bmIFCLKSRC | bm3048MHZ | bmIFCLKOE | bmFIFOS); SYNCDELAY; IFCONFIG = (bmIFCLKSRC | bm3048MHZ | bmIFCLKOE | bmPORTS); // 0xe0 // EP1OUT & EP1IN SYNCDELAY; EP1OUTCFG = (bmVALID | bmBULK); // 0xa0 SYNCDELAY; EP1INCFG = (bmVALID | bmBULK); // 0xa0 // EP2OUT & EP6IN are quad-buffered bulk endpoints SYNCDELAY; EP2CFG = (bmVALID | bmBULK); // 0xa0 SYNCDELAY; EP4CFG = 0x00; SYNCDELAY; EP6CFG = (bmVALID | bmBULK | bmDIR); // 0xe0 SYNCDELAY; EP8CFG = 0x00; // EP2OUT & EP6IN automatically commit packets SYNCDELAY; EP2FIFOCFG = bmAUTOOUT; // 0x10 SYNCDELAY; EP4FIFOCFG = 0x00; SYNCDELAY; EP6FIFOCFG = bmAUTOIN; // 0x08 SYNCDELAY; EP8FIFOCFG = 0x00; // Reset FIFOs for EP2OUT & EP6IN SYNCDELAY; FIFORESET = bmNAKALL; // 0x80 SYNCDELAY; FIFORESET = 2; // reset EP2OUT SYNCDELAY; FIFORESET = 6; // reset EP6IN SYNCDELAY; FIFORESET = 0x00; // Arm EP1OUT EP1OUTBC = 0x00; // Arm the EP2OUT buffers. Done four times because it's quad-buffered SYNCDELAY; OUTPKTEND = bmSKIP | 2; // EP2OUT 0x82 SYNCDELAY; OUTPKTEND = bmSKIP | 2; SYNCDELAY; OUTPKTEND = bmSKIP | 2; SYNCDELAY; OUTPKTEND = bmSKIP | 2; // Auto-commit 512-byte packets from EP6IN (master may commit early by asserting PKTEND) SYNCDELAY; EP6AUTOINLENH = 0x02; SYNCDELAY; EP6AUTOINLENL = 0x00; // Turbo I2C I2CTL |= bm400KHZ; // Auto-pointers AUTOPTRSETUP = bmAPTREN | bmAPTR1INC | bmAPTR2INC; // 0x07 // Port lines all inputs... IOA = 0xFF; OEA = 0x00; IOB = 0xFF; OEB = 0x00; IOC = 0xFF; OEC = 0x00; IOD = 0xFF; OED = 0x00; IOE = 0xFF; OEE = 0x00; #ifdef EEPROM #ifdef BSP #include STR(boards/BSP.c) #endif #endif */ I2CTL |= bm400KHZ; TD_Init(); #ifdef DEBUG usartInit(); { const uint8 *s = dev_strings; uint8 len; s = s + *s; len = (*s)/2 - 1; s += 2; while ( len ) { usartSendByte(*s); s += 2; len--; } usartSendByte(' '); len = (*s)/2 - 1; s += 2; while ( len ) { usartSendByte(*s); s += 2; len--; } usartSendByte('\r'); } #endif }
int main(void) { //init system //init timer //init watchdog /* Initialize Leds mounted on STM32 board */ GPIO_InitTypeDef GPIO_InitStructure; /* Initialize LED which connected to PC6,9, Enable the Clock*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); /* Configure the GPIO_LED pin */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_4|GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_Init(GPIOA, &GPIO_InitStructure); gpioInit(); usartInit(); pwmInit(); systickInit(); /* RCC_APB1PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); TIM_TimeBaseInitTypeDef timTbItd; // set prescaler to count every millisecond timTbItd.TIM_Prescaler = (uint16_t) (SystemCoreClock / 24) - 1; timTbItd.TIM_Period = 65535; timTbItd.TIM_ClockDivision = TIM_CKD_DIV1; timTbItd.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM1, &timTbItd); */ /* TIM_OCInitTypeDef timOcItd; timOcItd.TIM_OCMode = TIM_OCMode_Timing; timOcItd.TIM_OutputState = TIM_OutputState_Enable; TIM_OC1Init(TIM15, &timOcItd); */ //TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable); //TIM_ARRPreloadConfig(TIM1, ENABLE); /* TIM_Cmd(TIM1, ENABLE); TIM1->CR1 |= TIM_CR1_CEN; */ //Copy from GPIO_Blink example, while testing usart data interupt. int i; uint16_t tempPwm = 0; uint16_t tempTim = TIM1->CNT; GPIOC->ODR ^= GPIO_Pin_8; while (1) { if (0 == TIM1->CNT) { tempTim = TIM1->CNT; GPIOC->ODR ^= GPIO_Pin_8; } //TIM2->CCR1 = getUsartData(); //USART_SendData(USART1, 255); /* Toggle LEDs which connected to PC6*/ //GPIOC->ODR ^= GPIO_Pin_8; /* delay */ for(i=0;i<0x10000;i++); /* Toggle LEDs which connected to PC9*/ GPIOC->ODR ^= GPIO_Pin_9; /* delay */ //for(i=0;i<0x10000;i++); } }
/* * Runs pre-initialization code. This function will be started in kernel mode one time while the * VEX Cortex is starting up. As the scheduler is still paused, most API functions will fail. * * The purpose of this function is solely to set the default pin modes (pinMode()) and port * states (digitalWrite()) of limit switches, push buttons, and solenoids. It can also safely * configure a UART port (usartOpen()) but cannot set up an LCD (lcdInit()). */ void initializeIO() { usartInit(uart1, 115200, SERIAL_8N1); }