void ram(void) { int c=0, pos=0,del=0; struct pos_s tail[MAX_SNAKE_LEN]; snake.tail = tail; // load the highscore highscore = highscore_get(); // initially reset everything reset(); while (1) { if(!(++c % snake.speed)) { handle_input(); pos = (snake.t_start+1) % MAX_SNAKE_LEN; snake.tail[pos].x = snake.tail[snake.t_start].x; snake.tail[pos].y = snake.tail[snake.t_start].y; if(snake.dir == 0) snake.tail[pos].x++; else if(snake.dir == 1) snake.tail[pos].y++; else if(snake.dir == 2) snake.tail[pos].x--; else if(snake.dir == 3) snake.tail[pos].y--; snake.t_start = pos; if (pos < snake.len) { del = MAX_SNAKE_LEN - (snake.len - pos); } else del = pos - snake.len; // remove last, add first line draw_block(snake.tail[del].x, snake.tail[del].y, 0xFF); draw_block(snake.tail[pos].x, snake.tail[pos].y, 0b00011000); // check for obstacle hit.. if (hitWall() || hitSelf()) { death_anim(); if (showHighscore()) break; reset(); } else if (hitFood()) next_level(); lcdDisplay(); } #ifdef SIMULATOR delayms(50); #else delayms(3); #endif } }
/** reaction.c * First l0dable for my r0ket * Improvement is welcome * * AUTHOR: hubba */ void ram(void) { char x = gpioGetValue(RB_LED1); int rand_wait = 0; int react_time=0; int start_time = 0; int end_time = 0; gpioSetValue (RB_LED1,0); //upperleft LED off lcdClear(); lcdPrintln("Hello"); lcdPrintln(GLOBAL(nickname)); lcdPrintln("ReACTION"); lcdRefresh(); delayms(500); while(1) { react_time = 0; lcdPrintln("Press ENTER if "); lcdPrintln("LED is on!"); lcdRefresh(); rand_wait = getRandom(); rand_wait = rand_wait%50; rand_wait = 40 + rand_wait*4; // Minimum pause time is 400ms for(int i =0; i<=rand_wait; i++) //directly calling delayms(rand_wait) didn't work { delayms(10); } gpioSetValue (RB_LED1, 1); //upperleft LED ON getInputWaitRelease(); start_time = getTimer()*(SYSTICKSPEED); while (getInputWait() != BTN_ENTER); //wait for user input { } end_time = getTimer()*(SYSTICKSPEED); react_time = end_time - start_time; //measure used time lcdClear(); lcdPrint("Needed "); lcdPrintInt(react_time); lcdPrintln(" ms"); lcdPrintln("DOWN: Exit"); lcdPrintln("0ther: New game"); lcdRefresh(); gpioSetValue (RB_LED1,0); //upperleft LED off getInputWaitRelease(); if(getInputWait() == BTN_DOWN) //Check for Exit/new game { gpioSetValue (RB_LED1, x); //upperleft LED as before l0dable executed return; } } /* NEVER LAND HERE */ lcdPrintln("Flow-Error"); lcdRefresh(); return; };
void mandelMove() { //long delta_r = (mandel.rmax - mandel.rmin)/10; //long delta_i = (mandel.imax - mandel.imin)/10; long rs =(mandel.rmax-mandel.rmin)/RESY; long is =(mandel.imax-mandel.imin)/RESX; char key = getInputWaitTimeout(10); if (key == BTN_LEFT) { mandel.imax -=is; mandel.imin -=is; mandel.dleft = true; } else if (key == BTN_RIGHT) { mandel.imax += is; mandel.imin += is; mandel.dright = true; } else if (key == BTN_DOWN) { mandel.rmax += rs; mandel.rmin += rs; mandel.ddown = true; } else if (key == BTN_UP) { mandel.rmax -= rs; mandel.rmin -= rs; mandel.dup = true; } else if (key == BTN_ENTER) { if (mandel.presscount < mandel.presslimitzin) { mandel.presscount = mandel.presscount + 1; } } else if (key == BTN_NONE) { //delayms_queue(15); if(mandel.presscount > 0 ) { mandel.presscount = mandel.presscount - 1; mandel.clickmark = true; } if (mandel.presscount == 0 ) { mandel.clickmark = false; } } if (mandel.presscount > mandel.presslimitzout && mandel.clickmark && key == BTN_ENTER && mandel.zoomlevel >= mandel.maxzoomout) { mandel.imin = mandel.imin - (mandel.imax-mandel.imin)/8; mandel.imax = mandel.imax + (mandel.imax-mandel.imin)/8; mandel.rmin = mandel.rmin -(mandel.rmax-mandel.rmin)/8; mandel.rmax = mandel.rmax +(mandel.rmax-mandel.rmin)/8; mandel.dirty = true; delayms(10); mandel.zoomlevel = mandel.zoomlevel - 1 ; } else if (mandel.presscount == mandel.presslimitzin && key == BTN_ENTER && mandel.zoomlevel <= mandel.maxzoomin ) { mandel.imin = mandel.imin + (mandel.imax-mandel.imin)/8; mandel.imax = mandel.imax - (mandel.imax-mandel.imin)/8; mandel.rmin = mandel.rmin +(mandel.rmax-mandel.rmin)/8; mandel.rmax = mandel.rmax -(mandel.rmax-mandel.rmin)/8; mandel.dirty = true; delayms(10); mandel.zoomlevel = mandel.zoomlevel + 1 ; } }
void lcd_init(unsigned char color) { P5DIR |= CSX + SDA + SCLK + RESX; P5OUT |= CSX; P5OUT &= ~SDA; P5OUT &= ~SCLK; P5OUT &= ~RESX; delayms(20); P5OUT |= RESX; delayms(20); // Sleep out... n6100_send(0x11,2); // Ajusta o contraste... n6100_sendcom1(0x25, 0x50); // Liga o display e o booster... n6100_send(0x29,2); n6100_send(0x03,2); delayms(10); // Color Format... (8bits/pixel) n6100_sendcom1(0x3a, 0x02); // Inicializa a tabela de cores 8bits/pixel n6100_send(0x2d,2); // red n6100_send(0x00,0); n6100_send(0x02,0); n6100_send(0x05,0); n6100_send(0x07,0); n6100_send(0x09,0); n6100_send(0x0b,0); n6100_send(0x0d,0); n6100_send(0x0f,0); // green n6100_send(0x00,0); n6100_send(0x02,0); n6100_send(0x05,0); n6100_send(0x07,0); n6100_send(0x09,0); n6100_send(0x0b,0); n6100_send(0x0d,0); n6100_send(0x0f,0); // blue n6100_send(0x00,0); n6100_send(0x05,0); n6100_send(0x0b,0); n6100_send(0x0f,0); // Memory Access Control... n6100_sendcom1(0x36, invertido); // Agradecimentos... lcd_fillrect(0, 0, 132, 132, color); //n6100_putlogo(2, 2, 128, 128, (unsigned char *)Matrix); //delayms(4000); }
void openLCD(void) { LCD_DIR = 0xFF; // configure LCD_DAT port for output delayms(10); cmd2LCD(0x28); // set 4-bit data, 2-line display, 5x7 font cmd2LCD(0x0E); // turn on display, cursor, not blinking cmd2LCD(0x06); // move cursor right cmd2LCD(0x01); // clear screen, move cursor to home delayms(2); // wait until "clear display" command is complete }
/*1602显示程序*/ void write_com(uchar com) { lcdrs=0; P0=com; delayms(5); lcden=1; delayms(5); lcden=0; }
void write_date(uchar date) { lcdrs=1; P0=date; delayms(5); lcden=1; delayms(5); lcden=0; }
void main() { while(1){ P2 = 0xff; delayms(499); P2 = 0x0; delayms(499); } }
void menu_conf_exit(Uint8 saved, Uint16 menu){ lcd_dis_saved[saved](); delayms(200); lcd_dis_menu[menu](); delayms(300); lcd_dis_saved[saved](); delayms(200); lcd_dis_menu[menu](); }
//LCD1602初始化 void lcdInitial() { writeCom(0x38);//显示模式设置 delayms(5); writeCom(0x08);//显示关闭 clear_scr();//清屏 writeCom(0x06); //显示光标移动设置 delayms(5); writeCom(0x0C); //显示开及光标设置 }
int main() { int wait; // Set up port for start switch lcdInit(); // Set up motors and encoders motorInit(); encodersInit(); servoInit(); // Set up IRs gp2d12Init(PIN_HEAD_IR); digitalSetDirection(PIN_IR,AVRRA_INPUT); digitalSetData(PIN_IR,AVRRA_LOW); // Set up OP599A - analog already initialized digitalSetDirection(PIN_PHOTO,AVRRA_INPUT); digitalSetData(PIN_PHOTO,AVRRA_LOW); // Set up fan & test digitalSetData(PIN_FAN, AVRRA_LOW); digitalSetDirection(PIN_FAN, AVRRA_OUTPUT); digitalSetData(PIN_FAN, AVRRA_HIGH); delayms(25); digitalSetData(PIN_FAN, AVRRA_LOW); lcdPrint("Wait... "); wait = digitalGetData(PIN_START); while(wait) { // standard delay .. delayms(10); wait = digitalGetData(PIN_START); } // Start our map mapInit(); lcdClear(); PrintHeading(lheading,nStart); sei(); // Run Behaviors while(1) { // update odometer while(rCount > COUNTS_CM(1) ) { // odometer is in CM odometer = odometer - 1; rCount = rCount - COUNTS_CM(1); } // now run behaviors if(arbitrate()>0) { // let motors wind down delayms(500); clearCounters; plan(); clearCounters; } } }
void led_blinking(void) { P0=ledout(0x88); delayms(100); P0=ledout(0x33); delayms(100); P0=ledout(0x44); delayms(100); }
void initBoard(void) { PORT_Arduino = 0xff; // Set Port ready for Input from Arduino, set DataAck=1 (Standy) PORT_Ctrl_Status = 0xff; // Turn all LED Off and ready to read Key#2 status WSN_RST = 0; // Reset WSN-02/03 Wireless module delayms(10); // Delay 50ms WSN_RST = 1; // Normal Operation delayms(10); // Wait for WSN-02/03 ready } /* initBoard */
void debug_stop(uint8_t data, int stoptime) { PORTD = data; if (stoptime == 0) { while (BUTTON_GetValue()); delayms(150); } else { delayms(stoptime); } }
void lcdInit(void) { SETUPgout(LCD_BL_EN); SETUPgout(LCD_RESET); SETUPgout(LCD_CS); /* prepare SPI */ SETUPpin(LCD_MOSI); SETUPpin(LCD_SCK); // Reset the display OFF(LCD_RESET); delayms(100); /* 1 ms */ ON(LCD_RESET); delayms(100); /* 5 ms */ lcd_select(); static uint8_t initseq_d[] = { /* The controller is a PCF8833 - documentation can be found online. */ 0x11, // SLEEP_OUT (wake up) 0x3A, 2, // mode 8bpp (2= 8bpp, 3= 12bpp, 5= 16bpp) 0x36, 0b11000000, // my,mx,v,lao,rgb,x,x,x 0x25, 0x3a, // set contrast 0x29, // display on 0x03, // BSTRON (booster voltage) 0x2A, 1, RESX, 0x2B, 1, RESY }; uint16_t initseq_c = ~ ( /* commands: 1, data: 0 */ (1<< 0) | (1<< 1) | (0<< 2) | (1<< 3) | (0<< 4) | (1<< 5) | (0<< 6) | (1<< 7) | (1<< 8) | (1<< 9) | (0<<10) | (0<<11) | (1<<12) | (0<<13) | (0<<14) | 0); int i = 0; lcdWrite(0, 0x01); /* most color displays need the pause */ delayms(10); while(i<sizeof(initseq_d)){ lcdWrite(initseq_c&1, initseq_d[i++]); initseq_c = initseq_c >> 1; } lcd_deselect(); lcdFill(0xff); /* Clear display buffer */ setSystemFont(); }
void display(unsigned char shi, unsigned char ge) { P1 = DIG_PLACE[0]; P0 = DIG_CODE[ge]; delayms(2); P0 = 0x0; P1 = DIG_PLACE[1]; P0 = DIG_CODE[shi]; delayms(2); P0 = 0x0; }
int dwConfigure(dwDevice_t* dev) { dwEnableClock(dev, dwClockAuto); delayms(5); // Reset the chip if (dev->ops->reset) { dev->ops->reset(dev); } else { dwSoftReset(dev); } if (dwGetDeviceId(dev) != 0xdeca0130) { return DW_ERROR_WRONG_ID; } // Set default address memset(dev->networkAndAddress, 0xff, LEN_PANADR); dwSpiWrite(dev, PANADR, NO_SUB, dev->networkAndAddress, LEN_PANADR); // default configuration memset(dev->syscfg, 0, LEN_SYS_CFG); dwSetDoubleBuffering(dev, false); dwSetInterruptPolarity(dev, true); dwWriteSystemConfigurationRegister(dev); // default interrupt mask, i.e. no interrupts dwClearInterrupts(dev); dwWriteSystemEventMaskRegister(dev); // load LDE micro-code dwEnableClock(dev, dwClockXti); delayms(5); dwManageLDE(dev); delayms(5); dwEnableClock(dev, dwClockPll); delayms(5); //dev->ops->spiSetSpeed(dev, dwSpiSpeedHigh); // //Enable LED clock // dwSpiWrite32(dev, PMSC, PMSC_CTRL0_SUB, dwSpiRead32(dev, PMSC, PMSC_CTRL0_SUB) | 0x008C0000); // // // Setup all LEDs // // dwSpiWrite32(dev, 0x26, 0x00, dwSpiRead32(dev, 0x26, 0x00) | 0x1540); // // // Start the pll // // delayms(1); // Initialize for default configuration (as per datasheet) return DW_ERROR_OK; }
void fastBlink(){ LED = 1; delayms(50); LED = 0; delayms(50); LED = 1; delayms(50); LED = 0; delayms(50); LED = 1; delayms(50); LED = 0; }
void main (void) { while(1) { P1=0xff; delayms(400); while(P1) { P1--; delayms(500); } } }
static uint8_t mainloop() { uint32_t ioconbak = IOCON_PIO1_11; uint32_t volatile oldCount=IntCtr; uint32_t perMin=0; // counts in last 60 s uint32_t startTime=_timectr; uint8_t button; IOCON_PIO1_11 = 0; while (1) { //GPIO_GPIO0DATA&=~(1<<11); IOCON_PIO1_11 = ioconbak; GPIO_GPIO1DATA &= ~(1 << 7); GPIO_GPIO1DATA &= ~(1 << 11); lcdClear(); lcdPrintln(" Geiger"); lcdPrintln(" Counter"); // #### for (int i=0; i< (14*( _timectr-startTime))/(60*100);i++) { lcdPrint("#"); } lcdPrintln(""); lcdPrintln("Counts:"); lcdPrint(" "); lcdPrintInt(IntCtr); lcdPrintln(" total"); lcdPrint(" "); lcdPrintInt( perMin); lcdPrintln("/min"); // remember: We have a 10ms Timer counter if ((startTime+60 *100 ) < _timectr) { // dumb algo: Just use last 60 seconds count perMin=IntCtr-oldCount; startTime=_timectr; oldCount=IntCtr; } lcdRefresh(); delayms(42); button = getInputRaw(); if (button != BTN_NONE) { delayms(23);// debounce and wait till user release button while (getInputRaw()!=BTN_NONE) delayms(23); break; } } IOCON_PIO1_11 = ioconbak; return button; }
/******************************************************************************* * Save the item value to EEPROM * *******************************************************************************/ void Save_Page2_Item() { BACK_COLOR = heading_color; POINT_COLOR = YELLOW; LCD_8x16_String(220,3,"SAVING"); // Heading delayms(500); // delay to slow the loop down for testing LCD_8x16_String(220,3," "); // Heading delayms(500); // delay to slow the loop down for testing LCD_8x16_String(220,3,"SAVING"); // Heading delayms(500); // delay to slow the loop down for testing LCD_8x16_String(220,3," "); // Heading BACK_COLOR = field_color; POINT_COLOR = char_norm_color; }
// //# MENU lcdread void lcdrtest(void){ lcdClear(); lcdPrint("ID1:"); lcdPrintInt(lcdRead(128+64+16+8 +2 )); lcdNl(); lcdPrint("ID2:"); lcdPrintInt(lcdRead(128+64+16+8 +2+1)); lcdNl(); lcdPrint("ID3:"); lcdPrintInt(lcdRead(128+64+16+8+4 )); lcdNl(); lcdPrint("ID4:"); lcdPrintInt(lcdRead(128+64+16+8+4 +1)); lcdNl(); lcdPrint("Tmp:"); lcdPrintInt(lcdRead(128+64+16+8+4+2 )); lcdNl(); lcdPrint("VM:"); lcdPrintInt(lcdRead(128+64+16+8+4+2+1)); lcdNl(); // lcd_select(); mylcdWrite(0,128+32+8+4+1); lcd_deselect(); delayms(10); lcdInit(); lcdRefresh(); while(!getInputRaw())delayms(10); };
void senddata1(char display_num) { unsigned i; TP_ON; CS_ON(display_num); DEBUG_DELAY delayms(1); CS_OFF(display_num); DEBUG_DELAY delayms(1); WR_OFF; DEBUG_DELAY sendBit(1); DEBUG_DELAY WR_ON; DEBUG_DELAY WR_OFF; DEBUG_DELAY sendBit(0); DEBUG_DELAY WR_ON; DEBUG_DELAY WR_OFF; DEBUG_DELAY sendBit(1); DEBUG_DELAY WR_ON; DEBUG_DELAY temp1 = 0x80; MCU_Address_2416(0x00); for (row = 0; row < 3; row++) { for (i = 0; i < 8; i++) { MCU_Data_2416(Array1, display_num); if (temp1 == 0x00) temp1 = 0x80; } } delayms(1); DEBUG_DELAY CS_ON(display_num); DEBUG_DELAY TP_OFF; DEBUG_DELAY tmpBit = tmpBit ^ 1; }
void LCD_CLR(void) { unsigned char cmd; cmd=0x01; //清除显示 W_1byte(0,0,cmd); //写指令 delayms(1); cmd=0x02; //地址归位 W_1byte(0,0,cmd); //写指令 delayms(1); cmd=0x80; //设置DDRAM 地址 W_1byte(0,0,cmd); //写指令 delayms(1); //延时 }
void Relay_Test(void) { PCF8574_Single_WriteI2C(UE_PCF8574_SlaveAddress,0xA0); delayms(1000); PCF8574_Single_WriteI2C(UE_PCF8574_SlaveAddress,0xC0); delayms(1000); PCF8574_Single_WriteI2C(UE_PCF8574_SlaveAddress,0x60); delayms(1000); PCF8574_Single_WriteI2C(UE_PCF8574_SlaveAddress,0xf0); delayms(1000); }
void displayByteOnLED(uchar answer){ uchar n = 8; while (n--){ LED = 0; delayms(400); if (answer & 0b10000000) { LED = 1; } delayms(100); answer = answer << 1; } delayms(1000); LED = 0; }
int initialize_empty_project(int argc, char *argv[]) { struct project_cache pc; delayms(100000); project_cache_init(&pc); if (parse_arguments(&pc, argc, argv) < 0) return -1; if (make_peg_directories() < 0) return -1; if (!create_description_file(&pc)) fprintf(stderr, BOLD_GREEN"Initialised an empty project\n"RESET); create_cache_files(&pc); create_database_files(&pc); delayms(200000); return 0; }
void stnSysDiagElwire(void) { unsigned char pkt, dancer, elwire; unsigned int t; t=100; // Delay 100ms per El-Wire // Turn off all wire for (dancer=0; dancer<5; dancer++) { for (elwire=0; elwire<4; elwire++) { pkt = elwire << 4; pkt |= dancer; pkt &= 0xf7; // Turn off the El-Wires stnElWireTxPacket(pkt); delayms(t); } } for (dancer=0; dancer<5; dancer++) { for (elwire=0; elwire<4; elwire++) { pkt = elwire << 4; pkt |= dancer; pkt |= ELWIRE_ON; // Turn on the El-Wire stnElWireTxPacket(pkt); delayms(t); } } // Turn off all wire backward for (dancer=0; dancer<5; dancer++) { for (elwire=0; elwire<4; elwire++) { pkt = (3-elwire) << 4; pkt |= (4-dancer); pkt &= 0xf7; // Turn off the El-Wire in reversed order stnElWireTxPacket(pkt); delayms(t); } } } /* stnSysDiagElwire */
void eepromWriteBytes(uint16_t addr, uint8_t *val, uint8_t n_bytes) { uint8_t ui2, ui3; DISABLE_ALL_INTERRUPTS; for (; n_bytes>0; n_bytes--, val++, addr++) { I2C_START_BIT; I2C_SEND_BYTE(EEPROM_CTRL_WRITE); I2C_GET_ACK(CY); #if EP24C > 2 ui2 = addr>>8; I2C_SEND_BYTE(ui2); I2C_GET_ACK(CY); #endif ui2 = (uint8_t)addr; I2C_SEND_BYTE(ui2); I2C_GET_ACK(CY); I2C_SEND_BYTE(val[0]); I2C_GET_ACK(CY); I2C_STOP_BIT; delayms(10); } ENABLE_ALL_INTERRUPTS; }
int main(void) { char msg[]="A nice long message for you to read !!!!" "A second very long message to read :) !!"; /* set up systick */ if(SysTick_Config(SystemCoreClock/1000)) { while(1); } /* set the pins up */ init_io(); /* start the lcd */ hd44780_init(); hd44780_write_string(msg); while(1) { delayms(300); hd44780_shift(0,1); } return 0; }