/*---------------------------------------------------------------------------*/ void enc28j60_arch_spi_deselect(void) { GPIO_SET(SPI_CS_PORT, SPI_CS_BIT); }
/************************************************************************************************** * @fn MT_SysGpio * * @brief ZAccel RPC interface for controlling the available GPIO pins. * * @param uint8 pData - Pointer to the data. * * @return None *************************************************************************************************/ void MT_SysGpio(uint8 *pBuf) { uint8 cmd, val; GPIO_Op_t op; cmd = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; op = (GPIO_Op_t)(*pBuf++); val = *pBuf; switch (op) { case GPIO_DIR: if (val & BV(0)) {GPIO_DIR_OUT(0);} else {GPIO_DIR_IN(0);} if (val & BV(1)) {GPIO_DIR_OUT(1);} else {GPIO_DIR_IN(1);} if (val & BV(2)) {GPIO_DIR_OUT(2);} else {GPIO_DIR_IN(2);} if (val & BV(3)) {GPIO_DIR_OUT(3);} else {GPIO_DIR_IN(3);} break; case GPIO_TRI: if(val & BV(0)) {GPIO_TRI(0);} else if(val & BV(4)) {GPIO_PULL_DN(0);} else {GPIO_PULL_UP(0);} if(val & BV(1)) {GPIO_TRI(1);} else if(val & BV(5)) {GPIO_PULL_DN(1);} else {GPIO_PULL_UP(1);} if(val & BV(2)) {GPIO_TRI(2);} else if(val & BV(6)) {GPIO_PULL_DN(2);} else {GPIO_PULL_UP(2);} if(val & BV(3)) {GPIO_TRI(3);} else if(val & BV(7)) {GPIO_PULL_DN(3);} else {GPIO_PULL_UP(3);} break; case GPIO_SET: if (val & BV(0)) {GPIO_SET(0);} if (val & BV(1)) {GPIO_SET(1);} if (val & BV(2)) {GPIO_SET(2);} if (val & BV(3)) {GPIO_SET(3);} break; case GPIO_CLR: if (val & BV(0)) {GPIO_CLR(0);} if (val & BV(1)) {GPIO_CLR(1);} if (val & BV(2)) {GPIO_CLR(2);} if (val & BV(3)) {GPIO_CLR(3);} break; case GPIO_TOG: if (val & BV(0)) {GPIO_TOG(0);} if (val & BV(1)) {GPIO_TOG(1);} if (val & BV(2)) {GPIO_TOG(2);} if (val & BV(3)) {GPIO_TOG(3);} break; case GPIO_GET: break; case GPIO_HiD: (val) ? GPIO_HiD_SET() : GPIO_HiD_CLR(); break; default: break; } val = (GPIO_GET(0)) ? BV(0) : 0; val |= (GPIO_GET(1)) ? BV(1) : 0; val |= (GPIO_GET(2)) ? BV(2) : 0; val |= (GPIO_GET(3)) ? BV(3) : 0; /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS), cmd, 1, &val); }
/**************************************************************************** * 名 称:void fLCD_LEDON(void) * 功 能:打开LCD背光 * 入口参数: * 出口参数: * 说 明:无 ****************************************************************************/ void fLCD_LEDON(void) { GPIO_SET(LED); }
void loop() { int i, j; // delay(1); GPIO_SET(CLK); delay(1); GPIO_SET(CLK); clkCountHi = 1; clkCount++; T++; tracePauseCount++; ReadControlState(); GetAddressFromAB(); if (Mlast==1 && m1==0) T = 1, m1Count++; Mlast = m1; bool suppressDump = false; if (!traceRefresh & !rfsh) suppressDump = true; // If the number of M1 cycles has been reached, skip the rest since we dont // want to execute this M1 phase if (m1Count==stopAtM1) { sprintf(extraInfo, "Number of M1 cycles reached"), running = false; printf("-----------------------------------------------------------+\r\n"); goto control; } // If the address is tri-stated, skip checking various combinations of // control signals since they may also be floating and we can't detect that if (!abTristated) { // Simulate read from RAM if (!mreq && !rd) { SetDataToDB(ram[ab & 0xFFFF]); if (!m1) sprintf(extraInfo, "Opcode read from %03X -> %02X", ab, ram[ab & 0xFF]); else sprintf(extraInfo, "Memory read from %03X -> %02X", ab, ram[ab & 0xFF]); if (++ab % 0x1000 == 0) printf("%04X\n",ab); } else // Simulate interrupt requesting a vector if (!m1 && !iorq) { SetDataToDB(iorqVector); sprintf(extraInfo, "Pushing vector %02X", iorqVector); } else GetDataFromDB(); // Simulate write to RAM if (!mreq && !wr) { ram[ab & 0xFFFF] = db; sprintf(extraInfo, "Memory write to %03X <- %02X", ab, db); } // Detect I/O read: We don't place anything on the bus if (!iorq && !rd) { sprintf(extraInfo, "I/O read from %03X", ab); } // Detect I/O write if (!iorq && !wr) { sprintf(extraInfo, "I/O write to %03X <- %02X", ab, db); } // Capture memory refresh cycle if (!mreq && !rfsh) { sprintf(extraInfo, "Refresh address %03X", ab); } } else GetDataFromDB(); DumpState(suppressDump); // If the user wanted to pause simulation after a certain number of // clocks, handle it here. If the key pressed to continue was not Enter, // stop the simulation to issue that command if (tracePause==tracePauseCount) { tracePauseCount = 0; } //-------------------------------------------------------- // Clock goes low //-------------------------------------------------------- //delay(1); digitalWrite(CLK, LOW); delay(1); digitalWrite(CLK, LOW); clkCountHi = 0; if (traceShowBothPhases) { ReadControlState(); GetAddressFromAB(); DumpState(suppressDump); } // Perform various actions at the requested clock number // if the count is positive (we start it at -2 to skip initial 2T) if (clkCount>=0) { if (clkCount==intAtClk) zint = 0; if (clkCount==nmiAtClk) nmi = 0; if (clkCount==busrqAtClk) busrq = 0; if (clkCount==resetAtClk) reset = 0; if (clkCount==waitAtClk) wait = 0; // De-assert all control pins at this clock number if (clkCount==clearAtClk) zint = nmi = busrq = reset = wait = 1; WriteControlPins(); // Stop the simulation under some conditions if (clkCount==stopAtClk) sprintf(extraInfo, "Number of clocks reached"), running = false; if (stopAtHalt&!halt) sprintf(extraInfo, "HALT instruction"), running = false; } //-------------------------------------------------------- // Trace/simulation control handler //-------------------------------------------------------- control: if (!running) { printf(":Simulation stopped: %s\r\n", extraInfo); extraInfo[0] = 0; digitalWrite(CLK, HIGH); zint = nmi = busrq = wait = 1; WriteControlPins(); while(!running) { // Expect a command from the serial port // if (Serial.available()>0) { memset((void *)temp, 0, TEMP_SIZE); gets(temp); //Serial.readBytesUntil('\r', temp, TEMP_SIZE-1); // Option ":" : this is not really a user option. This is used to // Intel HEX format values into the RAM buffer // Multiple lines may be pasted. They are separated by a space character. char *pTemp = temp; while (*pTemp==':') { byte bytes = hexFromTemprintf(pTemp, 0); if (bytes>0) { int address = (hexFromTemprintf(pTemp, 1)<<8) + hexFromTemprintf(pTemp, 2); byte recordType = hexFromTemprintf(pTemp, 3); printf("%04X:", address); for (i=0; i<bytes; i++) { ram[(address + i) & 0xFF] = hexFromTemprintf(pTemp, 4+i); printf(" %02X", hexFromTemprintf(pTemp, 4+i)); } printf("\r\n"); } pTemp += bytes*2 + 12; // Skip to the next possible line of hex entry } // Option "r" : reset and run the simulation if (temp[0]=='r') { // If the variable 9 (Issue RESET) is not set, perform a RESET and run the simulation. // If the variable was set, skip reset sequence since we might be testing it. if (resetAtClk<0) DoReset(); running = true; } // Option "sc" : clear simulation variables to their default values if (temp[0]=='s' && temp[1]=='c') { ResetSimulationVars(); temp[1] = 0; // Proceed to dump all variables... } // Option "s" : show and set internal control variables if (temp[0]=='s' && temp[1]!='c') { // Show or set the simulation parameters int var = 0, value; int args = sscanf(&temp[1], "%d %d\r\n", &var, &value); // Parameter for the option #12 is read in as a hex; others are decimal by default if (var==12) args = sscanf(&temp[1], "%d %x\r\n", &var, &value); if (args==2) { if (var==0) traceShowBothPhases = value; if (var==1) traceRefresh = value; if (var==2) tracePause = value; if (var==3) stopAtClk = value; if (var==4) stopAtM1 = value; if (var==5) stopAtHalt = value; if (var==6) intAtClk = value; if (var==7) nmiAtClk = value; if (var==8) busrqAtClk = value; if (var==9) resetAtClk = value; if (var==10) waitAtClk = value; if (var==11) clearAtClk = value; if (var==12) iorqVector = value & 0xFF; } printf("------ Simulation variables ------\r\n"); printf("#0 Trace both clock phases = %d\r\n", traceShowBothPhases); printf("#1 Trace refresh cycles = %d\r\n", traceRefresh); printf("#2 Pause for keypress every = %d\r\n", tracePause); printf("#3 Stop after clock # = %d\r\n", stopAtClk); printf("#4 Stop after # M1 cycles = %d\r\n", stopAtM1); printf("#5 Stop at HALT = %d\r\n", stopAtHalt); printf("#6 Issue INT at clock # = %d\r\n", intAtClk); printf("#7 Issue NMI at clock # = %d\r\n", nmiAtClk); printf("#8 Issue BUSRQ at clock # = %d\r\n", busrqAtClk); printf("#9 Issue RESET at clock # = %d\r\n", resetAtClk); printf("#10 Issue WAIT at clock # = %d\r\n", waitAtClk); printf("#11 Clear all at clock # = %d\r\n", clearAtClk); printf("#12 Push IORQ vector #(hex) = %2X\r\n", iorqVector); } // Option "m" : dump RAM memory if (temp[0]=='m' && temp[1]!='c') { // Dump the content of a RAM buffer printf(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\r\n"); printf(" +-----------------------------------------------\r\n"); for(i=0; i<16; i++) { printf("%02X |", i); for(j=0; j<16; j++) { printf("%02X ", ram[i*16+j]); } printf("\r\n"); } } // Option "mc" : clear RAM memory if (temp[0]=='m' && temp[1]=='c') { memset(ram, 0, sizeof(ram)); printf("RAM cleared\r\n"); } // Option "?" : print help if (temp[0]=='?' || temp[0]=='h') { printf("s - show simulation variables\r\n"); printf("s #var value - set simulation variable number to a value\r\n"); printf("sc - clear simulation variables to their default values\r\n"); printf("r - restart the simulation\r\n"); printf(":INTEL-HEX - reload RAM buffer with a given data stream\r\n"); printf("m - dump the content of the RAM buffer\r\n"); printf("mc - clear the RAM buffer\r\n"); } } } } //return 0; } // main
int main ( int argc, char **argv ) { int result; int period, half_period, half_period2; uint32_t volatile * gpio_base = 0; /* Retreive the mapped GPIO memory. */ result = setup_gpio_mmap ( &gpio_base ); if ( result < 0 ) { printf ( "-- error: cannot setup mapped GPIO.\n" ); exit ( 1 ); } period = 1000; /* default = 1Hz */ if ( argc > 1 ) { period = atoi ( argv[1] ); } half_period = set_frequency(1000); half_period2 = set_frequency(500); /* Setup GPIO of LED0 to output. */ GPIO_CONF_AS_OUTPUT ( gpio_base, GPIO_LED0 ); GPIO_CONF_AS_OUTPUT ( gpio_base, GPIO_LED1 ); GPIO_CONF_AS_INPUT ( gpio_base, GPIO_BTN0 ); printf ( "-- info: start blinking.\n" ); /* Blink led at frequency of 1Hz. */ while (1) { /*GPIO_SET ( gpio_base, GPIO_LED0 ); GPIO_SET ( gpio_base, GPIO_LED1 ); delay ( half_period ); GPIO_CLR ( gpio_base, GPIO_LED0 ); delay ( half_period2 ); GPIO_CLR ( gpio_base, GPIO_LED1 ); delay ( half_period2 );*/ if(GPIO_VALUE( gpio_base, GPIO_BTN0 )==0) { GPIO_SET ( gpio_base, GPIO_LED0 ); GPIO_SET ( gpio_base, GPIO_LED1 ); delay ( half_period ); GPIO_CLR ( gpio_base, GPIO_LED0 ); delay ( half_period2 ); GPIO_CLR ( gpio_base, GPIO_LED1 ); delay ( half_period2 ); } } return 0; }
/*! * @brief LCD_ILI9341初始化 * @since v5.0 */ void LCD_ILI9341_init() { gpio_init (LCD_BL, GPO, 1); //LCD背光管脚输出1,表示关闭LCD背光 //复位LCD gpio_init (LCD_RST, GPO, 0); ILI9341_DELAYMS(1); GPIO_SET (LCD_RST, 1); //初始化总线 flexbus_8080_init(); //ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0xCF); LCD_ILI9341_WR_DATA(0x00); LCD_ILI9341_WR_DATA(0x81); LCD_ILI9341_WR_DATA(0x30); //ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0xED); LCD_ILI9341_WR_DATA(0x64); LCD_ILI9341_WR_DATA(0x03); LCD_ILI9341_WR_DATA(0x12); LCD_ILI9341_WR_DATA(0x81); //ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0xE8); LCD_ILI9341_WR_DATA(0x85); LCD_ILI9341_WR_DATA(0x10); LCD_ILI9341_WR_DATA(0x78); ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0xCB); LCD_ILI9341_WR_DATA(0x39); LCD_ILI9341_WR_DATA(0x2C); LCD_ILI9341_WR_DATA(0x00); LCD_ILI9341_WR_DATA(0x34); LCD_ILI9341_WR_DATA(0x02); ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0xF7); LCD_ILI9341_WR_DATA(0x20); ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0xEA); LCD_ILI9341_WR_DATA(0x00); LCD_ILI9341_WR_DATA(0x00); ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0xB1); LCD_ILI9341_WR_DATA(0x00); LCD_ILI9341_WR_DATA(0x1B); ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0xB6); LCD_ILI9341_WR_DATA(0x0A); LCD_ILI9341_WR_DATA(0xA2); ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0xC0); LCD_ILI9341_WR_DATA(0x35); ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0xC1); LCD_ILI9341_WR_DATA(0x11); LCD_ILI9341_WR_CMD(0xC5); LCD_ILI9341_WR_DATA(0x45); LCD_ILI9341_WR_DATA(0x45); LCD_ILI9341_WR_CMD(0xC7); LCD_ILI9341_WR_DATA(0xA2); LCD_ILI9341_WR_CMD(0xF2); LCD_ILI9341_WR_DATA(0x00); LCD_ILI9341_WR_CMD(0x26); LCD_ILI9341_WR_DATA(0x01); ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0xE0); //Set Gamma LCD_ILI9341_WR_DATA(0x0F); LCD_ILI9341_WR_DATA(0x26); LCD_ILI9341_WR_DATA(0x24); LCD_ILI9341_WR_DATA(0x0B); LCD_ILI9341_WR_DATA(0x0E); LCD_ILI9341_WR_DATA(0x09); LCD_ILI9341_WR_DATA(0x54); LCD_ILI9341_WR_DATA(0xA8); LCD_ILI9341_WR_DATA(0x46); LCD_ILI9341_WR_DATA(0x0C); LCD_ILI9341_WR_DATA(0x17); LCD_ILI9341_WR_DATA(0x09); LCD_ILI9341_WR_DATA(0x0F); LCD_ILI9341_WR_DATA(0x07); LCD_ILI9341_WR_DATA(0x00); LCD_ILI9341_WR_CMD(0XE1); //Set Gamma LCD_ILI9341_WR_DATA(0x00); LCD_ILI9341_WR_DATA(0x19); LCD_ILI9341_WR_DATA(0x1B); LCD_ILI9341_WR_DATA(0x04); LCD_ILI9341_WR_DATA(0x10); LCD_ILI9341_WR_DATA(0x07); LCD_ILI9341_WR_DATA(0x2A); LCD_ILI9341_WR_DATA(0x47); LCD_ILI9341_WR_DATA(0x39); LCD_ILI9341_WR_DATA(0x03); LCD_ILI9341_WR_DATA(0x06); LCD_ILI9341_WR_DATA(0x06); LCD_ILI9341_WR_DATA(0x30); LCD_ILI9341_WR_DATA(0x38); LCD_ILI9341_WR_DATA(0x0F); ILI9341_DELAY(); ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0x3a); // Memory Access Control LCD_ILI9341_WR_DATA(0x55); LCD_ILI9341_WR_CMD(0x11); //Exit Sleep ILI9341_DELAY(); LCD_ILI9341_WR_CMD(0x29); //display on LCD_SET_DIR(ili9341_dir); //液晶方向显示函数 LCD_ILI9341_WR_CMD(0x2c); PTXn_T(LCD_BL,OUT) = 0; //开LCD背光 }
void gpio_set(uint32_t gpioport, uint32_t gpios) { GPIO_SET(gpioport) = gpios; }
///////////////// // main routine ///////////////// void main (void) { int8_t ret1, ret2; int16_t accX1, accY1, accZ1; int16_t accX2, accY2, accZ2; char buf[100]; uint8_t count=0, len=0; ///////////////// // init peripherals ///////////////// // disable interrupts DISABLE_INTERRUPTS; // switch to 16MHz (default is 2MHz) CLK.CKDIVR.byte = 0x00; // set default option bytes to assert bootloader is running flash_OPT_default(); // init timer TIM3 for sleep and timeout (required by I2C) tim3_init(); // init timer TIM4 for 1ms clock with interrupts tim4_init(); // init I2C bus i2c_init(); // init and reset LCD display lcd_init(); // init pins for UART1 Rx(=PA4) and Tx(=PA5) gpio_init(&PORT_A, PIN_4, INPUT_PULLUP_NOEXINT); gpio_init(&PORT_A, PIN_5, OUTPUT_PUSHPULL_FAST); // init UART1 to high speed (connected to PC on muBoard) uart1_init(230400L); // init LEDs on muBoard for visual feedback GPIO_SET(PORT_H,PIN_2|PIN_3, 1); gpio_init(&PORT_H, PIN_2|PIN_3, OUTPUT_PUSHPULL_FAST); // enable interrupts ENABLE_INTERRUPTS; // init I2C routine pointers I2C_routine(); // initialize sensors do { bno055.dev_addr = BNO055_I2C_ADDR1; ret1 = bno055_init(&bno055); ret1 |= bno055_set_power_mode(POWER_MODE_NORMAL); ret1 |= bno055_set_operation_mode(OPERATION_MODE_AMG); } while (ret1 && USE_I2C_ADDR1); do { bno055.dev_addr = BNO055_I2C_ADDR2; ret2 = bno055_init(&bno055); ret2 |= bno055_set_power_mode(POWER_MODE_NORMAL); ret2 |= bno055_set_operation_mode(OPERATION_MODE_AMG); } while (ret2 && USE_I2C_ADDR2); ///////////////// // main loop ///////////////// while (1) { // every 1ms do if (g_flagClock) { g_flagClock = 0; // every 10ms do if (g_clock > 10) { g_clock = 0; // just to be sure accX1 = accY1 = accZ1 = ret1 = 0; accX2 = accY2 = accZ2 = ret2 = 0; // read data from sensor 1 #if USE_I2C_ADDR1 bno055.dev_addr = BNO055_I2C_ADDR1; ret1 = bno055_read_accel_x(&accX1); ret1 |= bno055_read_accel_y(&accY1); ret1 |= bno055_read_accel_z(&accZ1); if (ret1 != 0) { accX1 = accY1 = accZ1 = 0; } #endif // USE_I2C_ADDR1 // read data from sensor 2 #if USE_I2C_ADDR2 bno055.dev_addr = BNO055_I2C_ADDR2; ret2 = bno055_read_accel_x(&accX2); ret2 |= bno055_read_accel_y(&accY2); ret2 |= bno055_read_accel_z(&accZ2); if (ret2 != 0) { accX2 = accY2 = accZ2 = 0; } #endif // USE_I2C_ADDR2 // send data to PC via UART1. Use SW FIFO for background operation len = 0; buf[len++] = (uint8_t)(accX1 >> 8); // x1-acc (MSB first) buf[len++] = (uint8_t) accX1; buf[len++] = (uint8_t)(accY1 >> 8); // y1-acc (MSB first) buf[len++] = (uint8_t) accY1; buf[len++] = (uint8_t)(accZ1 >> 8); // z1-acc (MSB first) buf[len++] = (uint8_t) accZ1; buf[len++] = (uint8_t)(accX2 >> 8); // x2-acc (MSB first) buf[len++] = (uint8_t) accX2; buf[len++] = (uint8_t)(accY2 >> 8); // y2-acc (MSB first) buf[len++] = (uint8_t) accY2; buf[len++] = (uint8_t)(accZ2 >> 8); // z2-acc (MSB first) buf[len++] = (uint8_t) accZ2; uart1_send_buf(len, buf); // indicate I2C status via red LED (on=ok) GPIO_SET(PORT_H,PIN_3, ret1|ret2); // show life beat via green LED if (++count > 20) { count = 0; GPIO_TOGGLE(PORT_H,PIN_2); // print to LCD sprintf(buf, "%02d %03d %03d %03d", (int) ret1, (int) accX1, (int) accY1, (int) accZ1); lcd_print(1, 1, buf); sprintf(buf, "%02d %03d %03d %03d", (int) ret2, (int) accX2, (int) accY2, (int) accZ2); lcd_print(2, 1, buf); } } // loop 10ms } // loop 1ms } // main loop
void tick_clk() { GPIO_SET(JTAG_TCK); //nop_sleep(WAIT); GPIO_CLR(JTAG_TCK); }
void boardInit() { SysTick_Config(SystemCoreClock/1000 - 1); /* A note about interrupt priorities A smaller numeric priority means that the priority is higher, thus the most important interrupt has priority 0, the least import 31. If an interrupt arrives while servicing an interrupt with a lower priority, then the lesser interrupt is interrupted to service the high priority one, if the high priority interrupt is of a different preemption priority group. IOW: an IRQ in PP group 3 will be interrupted if an IRQ arrives with PP group 2,1 or 0. The sub priority is only used to order the interrupts at the same PE level. NVIC_SetPriorityGrouping is used here to divide the 32 levels of IRQ priorities into 8 preemption groups and 4 sub priorities. */ NVIC_SetPriorityGrouping(4); for (int i=0;i<35;i++) { NVIC_SetPriority(i, GROUP_PRIORITY_DEFAULT); } NVIC_SetPriority(TIMER2_IRQn, GROUP_PRIORITY_STEPPER); NVIC_SetPriority(SysTick_IRQn, GROUP_PRIORITY_1000HZ); NVIC_SetPriority(TIMER3_IRQn, GROUP_PRIORITY_100HZ); NVIC_SetPriority(USB_IRQn, GROUP_PRIORITY_USB); initUARTs(); initADC(); initPWM(); // Motor drivers are active low, so let's disable all of them, until the drivers turn them on: GPIO_SET(IO_X_ENABLE); GPIO_SET(IO_Y_ENABLE); GPIO_SET(IO_Z_ENABLE); GPIO_SET(IO_A_ENABLE); /* Set the simple I/O configuration for all the pins we use, this will ensure that all pins have had its function selected */ for (int i=0;i<ALL_PINS_SIZE;i++) { configPin(ALL_PINS[i]); } /* Set up timer3 to poke the "slow" 100Hz maintainance routine */ TIM_TIMERCFG_Type timerCfg; timerCfg.PrescaleOption = TIM_PRESCALE_USVAL; timerCfg.PrescaleValue = 1000; // 1 ms interval TIM_Init(LPC_TIM3, TIM_TIMER_MODE, &timerCfg); TIM_MATCHCFG_Type timerMatch; timerMatch.MatchChannel = 0; timerMatch.IntOnMatch = TRUE; timerMatch.ResetOnMatch = TRUE; timerMatch.StopOnMatch = FALSE; timerMatch.ExtMatchOutputType = TIM_EXTMATCH_NOTHING; timerMatch.MatchValue = 10-1; TIM_ConfigMatch(LPC_TIM3,&timerMatch); NVIC_EnableIRQ(TIMER3_IRQn); TIM_Cmd(LPC_TIM3,ENABLE); initAPI(); }
static inline void blink(void) { GPIO_SET(1 << PIN); await(1000000); GPIO_CLR(1 << PIN); }