// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv DO NOT ALTER vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv //****************************************************************************** // Call display_results after every generation // // returns TRUE when MAX_TIME is reached or switch is pressed // int display_results(uint16 generation) { static uint16 old_seconds; lcd_mode(0); lcd_cursor(4, 1); lcd_printf("%d", generation); // only update when seconds changes if (!seconds) old_seconds = 0; if (seconds != old_seconds) { old_seconds = seconds; printf("/%d", seconds); lcd_cursor(145, 1); printf("%2d", generation / seconds); } // check for max time exceeded if (seconds >= MAX_TIME) { lcd_cursor(50, 80); lcd_printf("\a\b\t%d.%02d", generation / MAX_TIME, generation % MAX_TIME); if (generation < MAX_TIME * 5) { lcd_cursor(30, 30); lcd_printf("\a\b\tTOO SLOW!"); } switches = 0; // clear any pending switches while (!switches); // wait for any switch } return switches; // return switch value }
/******************************************************************************** PUCK: 函数功能:获取屏幕显示信息,并显示 入口: type-----模式参数;curs-----光标位置 返回: ********************************************************************************/ void screen (u8 type, curs_t curs) { const scrn_t* p; //在此前,vlist的信息已经更新-----PUCK static scrn_t scrn={0xff,0xff,"",{0}}; //不为0,保证第一次就能更新,因为0x000000有可能第一次就是0---PUCK if(scrn.code != vlist.code) //按照全显代码检索:编码已经更新,需要根据vlist的编码获取新的显示元素-----------PUCK { for (p=&table[0];p!=&table[MAXCOUNT];++p) { if ( p->code==vlist.code) //按照显示代码检索 { scrn = *p; break; } } } if(p==&table[MAXCOUNT]) //找不到显示的代码,只显示代码,事件,其他不显示-------PUCK { lcd_code (vlist.user, curs, vlist.dlen); lcd_events(); lcd_update(); return ; } curs %= vlist.dlen; lcd_data (scrn.item, scrn.frmt,scrn.elem.signpos); //18ms lcd_code (vlist.user, curs, vlist.dlen); //26ms lcd_mode (type); ///A/B/C 3种模式 lcd_total (scrn.elem.total ); ///< "总", lcd_phase (scrn.elem.phase ); ///< "A/B/C相", lcd_voltage (scrn.elem.voltage ); ///< "电压", lcd_current (scrn.elem.current ); ///< "电流", lcd_positive (scrn.elem.positive ); ///< mode4.bit4 ? "输入" : "正向"; lcd_negative (scrn.elem.negative ); ///< mode4.bit4 ? "输出" : "反向"; lcd_reactive (scrn.elem.reactive ); ///< "无功", lcd_active (scrn.elem.active ); ///< "有功", lcd_power (scrn.elem.power ); ///< "功率", lcd_factor (scrn.elem.factor ); ///< "因数", lcd_angle (scrn.elem.angle ); ///< "相角", lcd_energy (scrn.elem.energy ); ///< "电量", lcd_demand (scrn.elem.demand ); ///< "需量", lcd_time (scrn.elem.time ); ///< "时间", lcd_charge (scrn.elem.charge ); ///< "电费", lcd_lostvolt (scrn.elem.lostvolt ); ///< "失压", lcd_lostcurt (scrn.elem.lostcurt ); ///< "失流", lcd_periods (scrn.elem.periods ); ///< "时段", lcd_feerate (scrn.elem.feerate ); ///< "费率", lcd_thismonth(scrn.elem.thismonth); ///< "本月", lcd_lastmonth(scrn.elem.lastmonth); ///< mode4.bit5 ? "上月", "上上月" : "上1月", "上2月"; lcd_assemble (scrn.elem.assemble ); ///< "无功组合方式1 or 2", mode4.bit7 ? "逆时针" : "顺时针"; lcd_quadrant (scrn.elem.quadrant ); ///< "XX象限", lcd_tariff (scrn.elem.tariff ); ///< 显示"费率Tx", lcd_times (scrn.elem.times ); ///< 显示"上XX次", lcd_events (); //8ms lcd_update (); }
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv DO NOT ALTER vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv //****************************************************************************** // Call display_results after every generation // // returns TRUE when MAX_TIME is reached or switch is pressed // int display_results(void) { //LED_RED_ON; // turn red LED on generation++; // next generation lcd_mode(0); lcd_cursor(4, 1); lcd_printf("%d", generation); // only update when seconds changes if (seconds != old_seconds) { old_seconds = seconds; printf("/%d", seconds); lcd_cursor(145, 1); printf("%2d", generation / seconds); } // check for MAX_GENERATION or MAX_TIME exceeded if ((generation >= MAX_GENERATION) || (seconds >= MAX_TIME)) { long hSecs, hGensPerSec; _BIC_SR(GIE); lcd_cursor(4, 1); // output results lcd_printf("%d/%d", generation, seconds); lcd_cursor(145, 1); printf("%2d", generation / seconds); lcd_cursor(50, 80); hSecs = ((long)seconds * 100) + (((WDT_1SEC_CNT - WDT_sec_cnt) * 100) / WDT_1SEC_CNT); hGensPerSec = ((long)generation * 100 * 100) / hSecs; lcd_printf("\a\b\t%ld.%02ld", hGensPerSec / 100, hGensPerSec % 100); if (generation < MAX_TIME * 5) { lcd_cursor(30, 30); lcd_printf("\a\b\tTOO SLOW!"); } _BIS_SR(GIE); switches = 0; // clear any pending switches while (!switches); // wait for any switch } //LED_RED_OFF; // turn red LED off return switches; // return switch value } // end display_results
//------------------------------------------------------------------------------ // main ------------------------------------------------------------------------ void main(void) { RBX430_init(_16MHZ); // init board ERROR2(lcd_init()); // init LCD // configure Watchdog WDTCTL = WDT_CTL; // Set Watchdog interval WDT_Sec_Cnt = WDT_1SEC_CNT; // set WD 1 second counter IE1 |= WDTIE; // enable WDT interrupt lcd_clear(); // clear LCD lcd_backlight(ON); // turn on LCD backlight lcd_rectangle(0, 0, NUM_COLS*2, NUM_ROWS*2, 1); // draw border __bis_SR_register(GIE); // enable interrupts // output splash screen & wait for switch lcd_wordImage(life_image, (159-126)/2, 50, 1); lcd_mode(LCD_PROPORTIONAL | LCD_2X_FONT); lcd_cursor(10, 20); printf("Press Any Key"); lcd_mode(0); while (1) if ((P1IN & 0x0f) ^ 0x0f) break; while (1) { uint16 row, col; // for each live row (78 down to 1) for (row = NUM_ROWS-2; row; --row) { // for each live column (78 down to 1) for (col = NUM_COLS-2; col; --col) { cell_death(row, col); } } char str[] = "x = 2, y = 2, rule = B3/S23\n2o$2o!"; char* ptr; int x_number = 0; int y_number = 0; const uint8 pttrn; for (ptr = str; *ptr; ptr++); { if (*ptr != 'x') continue; if ((*ptr < '0') && (*ptr > '9')) continue; while ((*ptr >= '0') && (*ptr <= '9')) { x_number = x_number * 10 + (*ptr++ - '0'); } if (*ptr != 'y') continue; if ((*ptr < '0') && (*ptr > '9')) continue; while ((*ptr >= '0') && (*ptr <= '9')) { y_number = y_number * 10 + (*ptr++ - '0'); } if (*ptr != 'n') continue; } } while (1) // new pattern seed { // load initial seed patterns uint16 generation = 0; // generation counter uint8 pen = BIRTH; // temp variable WDT_Sec_Cnt = WDT_1SEC_CNT; // set WD 1 second counter seconds = 0; // clear second counter while (1) { uint16 row, col; // for each live row (78 down to 1) for (row = NUM_ROWS-2; row; --row) { // for each live column (78 down to 1) for (col = NUM_COLS-2; col; --col) { if (pen == BIRTH) { cell_birth(row, col); } else { cell_death(row, col); } } } lcd_wordImage(life_image, (159-126)/2, 50, (BIRTH == pen) ? 3 : 1); lcd_cursor(4, 1); // output life generation printf("%d/%d", ++generation, seconds); if (seconds == 100) while (1); pen = (pen == BIRTH) ? DEATH : BIRTH; } } } // end main()