Beispiel #1
0
static void scan_keypad(void)
{ 
	volatile unsigned int temp = 0;
	volatile int i;

 	port1_init();

	temp = readl(S3C64XX_GPNDAT);
	
	if((temp & (1 << 0)) == 0){
		key_delay();	//去延时抖动
		row_value= 1;
	}
	else if((temp & (1 << 1)) == 0){
		key_delay();
		row_value= 2;
	}
	else if((temp & (1 << 2)) == 0){
		key_delay();
		row_value = 3;
	}
	else if((temp & (1 << 3)) == 0)	{
		key_delay();
		row_value = 4;
	}

	for (i=0; i<10000; i++) asm ("");

	port2_init();
	
	temp = readl(S3C64XX_GPNDAT);
	if(temp & (1 << 5)){
		col_value = 1;
	}
	else if(temp & (1 << 6)){
		col_value = 2;
	}
	else if(temp & (1 << 9)){
		col_value = 3;
	}
	else if(temp & (1 << 10)){
		col_value = 4;
	}
	else if(temp & (1 << 12)){
		col_value = 5;
	}
	/*reset GPNDAT 5 6 9 10 12 low level */
	/*The most important step*/
	temp  = readl(S3C64XX_GPNDAT);
	temp &= ~(1 << 5) & ~(1 << 6) & ~(1 << 9) & ~(1 << 10) & ~(1 << 12);
	temp |= (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3);
	writel( temp, S3C64XX_GPNDAT);
}
Beispiel #2
0
void ports_init(void) // initializes all 11 ports
{
    port0_init();
    port1_init();
    port2_init();
    port3_init();
    port4_init();
    port5_init();
    port6_init();
    port7_init();
    port8_init();
    port9_init();
    port10_init();
}
//------------------------------------------------------------------------------
//
void main(void)
{

	ERROR2(RBX430_init(_12MHZ));		// init board to 12 MHz
	ERROR2(lcd_init());					// init LCD
	ERROR2(port1_init());				// init switches
	ERROR2(ADC_init());					// init ADC
	ERROR2(watchdog_init());			// init watchdog
	ERROR2(timerA_init());				// init TimerA
	ERROR2(timerB_init());				// init TimerB
	__bis_SR_register(GIE);				// enable interrupts
	sys_event = NEW_GAME;				// start w/new game

	//-----------------------------------------------------------
	//	play forever
	while (1)
	{
		//-----------------------------------------------------------
		//	event service routine loop
		//-----------------------------------------------------------
		while (1)
		{
			// disable interrupts while checking sys_event
			_disable_interrupts();

			// if event pending, enable interrupts
			if (sys_event) _enable_interrupt();

			// else enable interrupts and goto sleep
			else __bis_SR_register(LPM0_bits | GIE);

			//-------------------------------------------------------
			//	I'm AWAKE!!!  What needs service?




			if (sys_event == SWITCH_1)

			{

				sys_event = sys_event & ~SWITCH_1;

				SWITCH_1_event();

			}

			else if (sys_event == NEW_GAME)			// new game event

			{
				sys_event &= ~NEW_GAME;				// clear new game event

				NEW_GAME_event();					// process new game

			}

			else if (sys_event == MOVE_BALL)				// timer A event

			{

				sys_event &= ~MOVE_BALL;			// clear TimerA event

				MOVE_BALL_event(ball);				// update ball position

			}

			else if (sys_event == ADC_READ)			// read ADC event

			{

				sys_event &= ~ADC_READ;				// clear ADC event

				ADC_READ_event(rightPaddle);		// process ADC read

				ADC_READ_event(leftPaddle);

			}

			else if (sys_event == LCD_UPDATE)

			{

				LCD_UPDATE_event();

			}

			else if (sys_event == START_GAME)

			{

				sys_event = sys_event & ~START_GAME;

				START_GAME_event();

			}

			else if (sys_event == NEW_RALLY)

			{

				sys_event = sys_event & ~ NEW_RALLY;

				NEW_RALLY_event();

			}

			else if (sys_event == MISSED_BALL)

			{

				sys_event = sys_event & ~MISSED_BALL;

				MISSED_BALL_event();

			}

			else if (sys_event == END_GAME)

			{

				sys_event = sys_event | END_GAME;

				END_GAME_event();

			}



			else									// ????

			{

				ERROR2(SYS_ERR_EVENT);				// unrecognized event

			}
		}
	}
} // end main
Beispiel #4
0
//------------------------------------------------------------------------------
// main ------------------------------------------------------------------------
void main(void)
{
	RBX430_init(_16MHZ);				// init board
	ERROR2(lcd_init());					// init LCD
	//lcd_volume(376);					// increase LCD brightness
	watchdog_init();					// init watchdog
	port1_init();						// init P1.0-3 switches
	__bis_SR_register(GIE);				// enable interrupts

	lcd_clear();
	memset(life, 0, sizeof(life));		// clear life array
	lcd_backlight(ON);
	lcd_wordImage(life_image, (HD_X_MAX - 126) / 2, 50, 1);
	lcd_cursor(10, 20);
	printf("\b\tPress Any Key");
	switches = 0;						// clear switches flag

	life_pr = life_prev;
	life_cr = life_cur;
	life_nr = life_nex;

	while (!switches);					// wait for any switch

	while (1)							// new pattern seed
	{

		uint16 generation;				// generation counter
		uint16 row, col;

		WDT_Sec_Cnt = WDT_1SEC_CNT;		// reset WD 1 second counter
		seconds = 0;					// clear second counter
		generation = 0;					// start generation counter
		int loop;
		int neighbors;
		int left;
		int middle;
		int current;
		int right;
		loop = 1;
		memset(life, 0, sizeof(life));				// clear life array
		memset(life_pr, 0, 10 * sizeof(uint8));		// clear slider
		memset(life_cr, 0, 10 * sizeof(uint8));		// clear slider
		memset(life_nr, 0, 10 * sizeof(uint8));		// clear slider
		init_life(switches);						// load seed based on switch
		switches = 0;								// reset switches



		while (loop)								// next generation
		{
			RED_TOGGLE;
			memcpy(life_pr, life[79], 10 * sizeof(uint8));
			memcpy(life_cr, life[78], 10 * sizeof(uint8));
			memcpy(life_nr, life[77], 10 * sizeof(uint8));
			// for each life row (78 down to 1)
			for (row = NUM_ROWS-2; row > 0; row--)
			{
				left = 0;
				neighbors = 0;
				current = TEST_CELL(life_cr, 1);
				right = TEST_CELL(life_pr, 2) + TEST_CELL(life_cr, 2) + TEST_CELL(life_nr, 2);
				middle = TEST_CELL(life_pr, 1) + current + TEST_CELL(life_nr, 1);

				// for each life column (78 down to 1)
				for (col = 1; col < 79; col++)
				{
					neighbors = left + (middle - current) + right;

					//neighbors += (TEST_CELL(life_pr, (col - 1)) + TEST_CELL(life_pr, col) + TEST_CELL(life_pr, (col + 1)));		// add number of neighbors on row above
					//neighbors += (TEST_CELL(life_cr, (col - 1)) + TEST_CELL(life_cr, (col + 1)));												// add number of neighbors on current row
					//neighbors += (TEST_CELL(life_nr, (col - 1)) + TEST_CELL(life_nr, col) + TEST_CELL(life_nr, (col + 1)));		// add number of neighbors on row below

					if(current == 1)												// if the cell is currently alive
					{
						if(neighbors == 2 || neighbors == 3)							// the cell has 2 or 3 neighbors
						{
																						// do nothing, the cell remains alive
						}

						else															// the cell doesn't have necessary neighbors
						{
							CELL_DEATH(row, col);										// clear cell bit in life array
							CELL_DELETE(row, col);										// clear LCD 2x2 pixel point
						}
					}

					else																// the cell is currently dead
					{
						if(neighbors == 3)												// the cell has 3 live neighbors
						{
							CELL_BIRTH(row, col);										// set cell bit in life array
							CELL_DRAW(row, col);										// set LCD 2x2 pixel point
						}
					}

					neighbors = 0;														// reset neighbors
					left = middle;
					current = TEST_CELL(life_cr, col + 1);
					middle = right;
					right = TEST_CELL(life_pr, col + 2) + TEST_CELL(life_cr, col + 2) + TEST_CELL(life_nr, col + 2);
				}

				temp = life_pr;
				life_pr = life_cr;
				life_cr = life_nr;
				life_nr = temp;
				//memcpy(life_pr, life_cr, 10 * sizeof(uint8));			// sets next row
				//memcpy(life_cr, life_nr, 10 * sizeof(uint8));			// sets next row
				memcpy(life_nr, life[row - 2], 10 * sizeof(uint8));			// sets next row


			}

			// display life generation and generations/second on LCD
			if (display_results(++generation)) break;
			if(switches)
			{
				loop = 0;					// when a switch is pressed, exit the while loop
			}
		}

	}
} // end main()