Exemple #1
0
int main(void)
{

	InitOsc();  
	InitPorts();           
	InitUART0();
	InitLCD();

	TCPLowLevelInit();                            //after TCPLowLevelInit() UCLK = ACLK = MCLK/4 = 2 000 000 Hz   

	UART_transmit (CR);
	UART_transmit (LF);  
	for (i=0; i!=26; i++)  UART_transmit (UART_Message[i]); 
	UART_transmit (CR);
	UART_transmit (LF);  

	for (i=0; i!=32; i++)  
	{
		SEND_CHAR(LCD_Message[i]);
		if (i==15) SEND_CMD (DD_RAM_ADDR2);
	}  

	SEND_CMD(DD_RAM_ADDR);    
	RX_flag=0; 
	cntr = 0;   

	HTTPStatus = 0;                                // clear HTTP-server's flag register
	TCPLocalPort = TCP_PORT_HTTP;                  // set port we want to listen to

	while (1)                                      // repeat forever
	{

		//--------------buttons scan---------------------------------------------------------

		if ((B1) == 0)                                 //B1 is pressed
		{
			STATUS_LED_ON;                             //switch on status_led
			SEND_CMD(CLR_DISP);
			SEND_CMD(DD_RAM_ADDR);
			cntr=0;
		}
		else  STATUS_LED_OFF;                           //B1 is released 

		if ((B2) == 0)
		{      
			//        time_out = BUTTON_TIME;
			//        while (time_out != 0) 
			//        if ((B2) == 0) time_out--;
			//        else time_out = BUTTON_TIME;  

			Delayx100us(50);
			RELAY1_ON;                                        
		}
		else
		{      
			//        time_out = BUTTON_TIME;
			//        while (time_out != 0) 
			//        if ((B2) != 0) time_out--;
			//        else time_out = BUTTON_TIME;  

			Delayx100us(50);
			RELAY1_OFF;                                        
		}                   

		if ((B3) == 0)   
		{
			Delayx100us(50);
			RELAY2_ON;                     //B3 is pressed
		}
		else  
		{
			Delayx100us(50);
			RELAY2_OFF;                               //B3 is released
		}  

		while ((B4) == 0)                               //B4 is pressed
		{
			BUZ1_OFF;                                 
			BUZ2_ON;
			Delay(_100us);
			Delay(_100us);                            //buzzer with 5 000 Hz
			BUZ2_OFF;
			BUZ1_ON;
			Delay(_100us);          
		}    
		BUZ1_OFF;                                      //B4 is released
		BUZ2_OFF;      

		//--------UART0 receiv scan------------------------------------------------------------------     

		if (RX_flag == 1)                              //new receiv byte
		{                    
			STATUS_LED_ON;
			if (cntr == 0) 
			{
				SEND_CMD(CLR_DISP);
				SEND_CMD(DD_RAM_ADDR);                //set address for first row
			}
			SEND_CHAR(RXData);          
			if(cntr == 15) SEND_CMD(DD_RAM_ADDR2);    //set address for second row
			if(cntr++ == 31) cntr = 0;           
			RX_flag = 0;            
			STATUS_LED_OFF;
		}
		//---------Digital Inputs scan--------------------------------------------------------------

		if ((DI1) == 0)  for (i=0 ; i != 5; i++)UART_transmit(DI1_Message[i]);  
		if ((DI2) == 0)  for (i=0 ; i != 5; i++)UART_transmit(DI2_Message[i]);  
		if ((DI3) == 0)  for (i=0 ; i != 5; i++)UART_transmit(DI3_Message[i]);  
		if ((DI4) == 0)  for (i=0 ; i != 5; i++)UART_transmit(DI4_Message[i]);  

		//---------DALLAS scan ---------------------------------------------------------------------

		if ((DALLAS) == 0)                      
		{
			cntr=0;
			SEND_CMD(CLR_DISP);
			SEND_CMD(DD_RAM_ADDR);
			for (i=0 ; i!= 14; i++) SEND_CHAR(DALLAS_Message[i]);
		}   

		//---------FREQ scan ----------------------------------------------------------------------      

		if ((FREQ) != 0) 
		{
			cntr=0;
			SEND_CMD(CLR_DISP);
			SEND_CMD(DD_RAM_ADDR);
			for (i=0 ; i!= 16; i++) SEND_CHAR(FREQ_Message[i]);
		}   

		//***********************************************************************************    
		//this is the end of my programm
		//***********************************************************************************

		if (!(SocketStatus & SOCK_ACTIVE)) {
			TCPPassiveOpen();   // listen for incoming TCP-connection
		}
		DoNetworkStuff();                                      // handle network and easyWEB-stack
		// events
		HTTPServer();
	}                               
	return 0;
}
Exemple #2
0
void str9Renderer(GameBoard *gameBoard)
{
	int x,y;
	int startx, stopx;
	char board[4][16];
	
	
	for(y = 0; y < gameBoard->mHeight; y++)
	{
		for(x = 0; x < gameBoard->mWidth; x++)
		{
			//set_cursor(y,x);
			//lcd_print("x");
			board[x][y] = ' ';
			//DoNetworkStuff();
		}		
	}	
	
	{
		Pong *pong;
		pong = gameBoard->mPong1;
		for(x = 0 ;x < pong->mLength; x++)
		{
			board[pong->mX + x][0] = '|';
		}
		
		pong = gameBoard->mPong2;
		for(x = 0 ;x < pong->mLength; x++)
		{
			board[pong->mX + x][gameBoard->mHeight-1] = '|';
		}
	}
	
	{
		Ball *ball;
		ball = gameBoard->mBall;
		board[ball->mX][ball->mY] = 'O';
	}
	
	#ifdef MASTER
		startx = 0;
		stopx = 2;
	#else
		startx = 2;
		stopx = 4;
	#endif
	
	for(y = 0; y < gameBoard->mHeight; y++)
	{
		for(x = startx; x < stopx; x++)
		{
			int disx;
			int disy;
			#ifdef MASTER
				disx = y;
				disy = 1-x;
			#else
				disx = 15-y;
				disy = x-2;
			#endif
			set_cursor(disx,disy);
			lcd_putchar(board[x][y]);
			DoNetworkStuff();
		}		
	}
	set_cursor(1,17);
}