main.c

来自「用于三星S3C44BOX ARM7芯片的Demon板测试」· C语言 代码 · 共 382 行

C
382
字号
/*********************************************************************************************
* File:	main.c
* Author:	embest
* Desc:	c main entry
* History:	
*********************************************************************************************/

/*--- include files ---*/
#include "44blib.h"
#include "44b.h"
#include "rtc.h"
char *date[8];// = {"","SUN","MON","TUE","WED","THU","FRI","SAT"};
extern STRU_BITMAP Stru_Bitmap_gbMouse;
char yn;
	
/*--- function declare ---*/
void Main(void);
void user_input_action(int value);
int User_Getch(void);
void FuncTest_view(int stdio);
void LCD_menu(void);
void LCD_view(INT16 col, INT16 row, INT8U color, INT8U * info);
void RTC_LCD(INT16 col, INT16 row, INT8U color);
void CLR_view();
void Key_map();

extern void (*run)(void);//=(void (*)(void))DOWNLOAD_ADDRESS;

INT8U * info[][2]={
        //" "," Embest S3C44B0X Evaluation Board(S3CEV40)",
		"-","      *====  Embest Info&Tech Co.,LTD. ====*",
		"-"," Please select test item:",
		"-"," 1: 8LED test  2: LCD test    3: Keyboard test",
		"-"," 4: Sound test 5: Timer test  6: Ethernet DHCP test",
		"-"," 7: Flash test 8: IIC test    9: Ethernet TFTP test",
		"-"," 0: TouchScreen test",
		"-"," >",
		"-","Note: Please connect UART0(115.2K,8,N,1) to PC COMx",
                0,0};
INT8U * Func_info[][2]={
        "0"," -- Touch Screen test... ",
        "1"," -- 8-segment LED test... ",
        "2"," -- LCD Screen usage test... ",
        "3"," -- User Keyboard (4x4) test... ",
        "4"," -- IIS function test... ",
        "5"," -- Timer function test... ",
        "6"," -- DHCP application test... ",
        "7"," -- Flash program test... ",
        "8"," -- IIC function test... ",
        "9"," -- TFTP translation test... ",
        "t"," -- RTC display... ",
        //"T"," -- Set date and time... ",
                0,0};

/*--- function code ---*/
/*********************************************************************************************
* name:		main
* func:		c code entry
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Main(void)
{
    int RTC_OK,i=0;
    int  input_ch;
    
	vcol = 20;
	vrow = 220;
	pad = 10; // between of two character
	
    input_char='>';
    sys_init();        /* Initial 44B0X's Interrupt,Port and UART */
    _Link();           /* Print Misc info */
	
	/******************/
	/* user interface */
	/******************/
	Lcd_Init();		
	Lcd_Clr(); // clear screen 
	Lcd_Active_Clr();
	
	init_keyboard();
	for(;;)
	 {
		input_char = -1;
		/* printf interface */
		FuncTest_view(UART);
		LCD_menu();
		/* get user input */
		input_char = User_Getch();
		input_ch = input_char;
		if(!(input_char<'0'|input_char>'f'))
		 {
			if(input_char>='0'|input_char<='9') Uart_Printf("\r  > %s",&input_char);
			Lcd_DspAscII6x8(25,vrow-28,BLACK,&input_char); // 
			Lcd_DspAscII6x8(30,vrow-28,BLACK,Func_info[input_char-0x30][1]); // 
			Lcd_Dma_Trans();
		 }	
		
		input_char = input_ch;
		
		user_input_action(input_char);
		Delay(100);
	 }
}

/*********************************************************************************************
* name:		User_Getch
* func:		waitting for the test function item input
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
char whichUart = 0;
int User_Getch(void)
{
    int i;
    char fg = 0;
    
    LED8ADDR = 0;
    
    if(whichUart==0)
    {	    
		while(!(rUTRSTAT0 & 0x1)) //Receive data read
		 {
		   if (fg)
		       { led1_off(); led2_on();}
		   else
		       { led1_on(); led2_off();}
		         
		   i++;		        
		   if (i > 30000)
		       { i = 0; fg = ~fg;}

		   if(input_char != -1) return input_char += 0x30; // read from 4x4 keyboard
		   
		   if(sec > 58) { RTC_LCD(200,228,BLACK); Lcd_Dma_Trans(); }

		   rINTMSK = ~(BIT_GLOBAL|BIT_EINT1);
		         
		 }
		return RdURXH0();
    }
    else
    {
		while(!(rUTRSTAT1 & 0x1)); //Receive data ready
		return	rURXH1;
    }
}

/*********************************************************************************************
* name:		FuncTest_view
* func:		display the test function interface to LCD or UARTx
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void FuncTest_view(int stdio)
{
	int i=0;

	if (stdio == LCD )
	 {
		while(1)
		 {  //display menu
			Lcd_DspAscII6x8(10,i*12+50,BLACK,info[i][1]);
			i++;
			if((int)(info[i][0]) == 0)	break;
		 }
	//void Lcd_Draw_Box(INT16 usLeft, INT16 usTop, INT16 usRight, INT16 usBottom, INT8U ucColor)
		vcol = 16;
		vrow = i*12+58;
		Lcd_Draw_Box(2,i*12+50,318,238);		
		 
	 }
	if (stdio == UART )
	 {
		/* printf interface */
		Uart_Printf("\n Embest S3C44B0X Evaluation Board(S3CEV40)\n");
		Uart_Printf("  *==================================*\n");
		Uart_Printf("  *=    Embest Info&Tech Co.,LTD.   =*\n");
		Uart_Printf("  *==================================*\n");
		Uart_Printf("  *==========  R&D CENTER  ==========*\n");
		Uart_Printf("  *=======  86-755-25631365  ========*\n");
		Uart_Printf("  *===== support@embedinfo.com ======*\n");
		Uart_Printf("  *===       Version 2.2          ===*\n");
		//RTC_OK = Test_Rtc_Alarm();
		//if(RTC_OK) Display_Rtc();
		Uart_Printf(" Please select test item:\n");
		Uart_Printf("  1: 8LED test\t 2: LCD test\t 3: Keyboard test\n");
		Uart_Printf("  4: Sound test\t 5: Timer test \t 6: Ethernet DHCP test\n");
		Uart_Printf("  7: Flash test\t 8: IIC test \t 9: Ethernet TFTP test\n");
		Uart_Printf("  0: TouchScreen test\n");
		Uart_Printf("  >");
	 }
}

/*********************************************************************************************
* name:		LCD_menu
* func:		display the test function interface to LCD
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void LCD_menu(void)
{
	Lcd_Clr(); // clear screen 
	Lcd_Active_Clr();
	Lcd_Draw_Box(4,4,318,48,BLACK-45);		
	Lcd_Draw_Box(6,6,316,46,BLACK-55);		
	Lcd_Draw_Box(8,8,314,44,BLACK-65);
	Lcd_DspAscII6x8(35,20,BLACK,"Embest S3C44B0X Evaluation Board (S3CEV40)");
		
	BitmapView(180,20,Stru_Bitmap_gbMouse);
	FuncTest_view(LCD);
	Key_map();
	RTC_LCD(200,228,BLACK);
	Lcd_Dma_Trans();
}

/*********************************************************************************************
* name:		LCD_view
* func:		print message to LCD
* para:		col   -- y value
			row   -- x value
			color -- color
			info  -- deplay message pointer 
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void LCD_view(INT16 col, INT16 row, INT8U color, INT8U * info)
{
//void LcdClrRect(INT16 usLeft, INT16 usTop, INT16 usRight, INT16 usBottom, INT8U ucColor)
	LcdClrRect(col,row,316,row+8,WHITE);
	Lcd_Dma_Trans();
	
	Lcd_DspAscII6x8(col,row,BLACK,info); // 
	Lcd_Dma_Trans();
}

/*********************************************************************************************
* name:		RTC_LCD
* func:		display the RTC clock to LCD
* para:		col   -- y value
			row   -- x value
			color -- color
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void RTC_LCD(INT16 col, INT16 row, INT8U color)
{
	Read_Rtc();
	sprintf(buf, "%02x-%02x-%02x %s %02x:%02x"\
	       ,year,month,day,date[weekday],hour,min);//,sec);
	Lcd_DspAscII6x8(col,row,color,(INT8U *)buf);
}

/*********************************************************************************************
* name:		CLR_view
* func:		clear the message area
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void CLR_view()
{
	LcdClrRect(vcol,vrow,316,vrow+pad*7,WHITE);
	Lcd_Dma_Trans();
		
}

/*********************************************************************************************
* name:		Key_map
* func:		keyboard image
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void Key_map()
{
	int i,j;
	int wx,wy;
	char * datt[][4] = {"0","1","2","3",
	                    "4","5","6","7",
	                    "8","9","A","B",
	                    "C","D","E","F.",
	                    0,0};
	wx = 32;
	wy = 16;
//void Lcd_Draw_Box(INT16 usLeft, INT16 usTop, INT16 usRight, INT16 usBottom, INT8U ucColor)
	/* draw rectangle pattern */ 
	for (j = 0; j<4; j++)
	 {
		for (i = 0; i<4; i++)
		 {
		   Lcd_Draw_Box(vcol+(pad+wx)*i,vrow+(pad-5+wy)*j,\
		                vcol+pad*i+wx*(i+1),vrow+(pad-5)*j+wy*(j+1),BLACK);
		   Lcd_DspAscII6x8(vcol+(pad+wx)*i+wx/2-4,vrow+(pad-5+wy)*j+wy/2-4,BLACK,datt[j][i]);
	 	 }
	 }
}


/*********************************************************************************************
* name:		user_input_actionin
* func:		action depend on user input value
* para:		value -- user input value
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void user_input_action(int value)
{
	char * in_g[4];
	switch(value)
	{
	case '0':
		TS_Test();
		break;	
	case '1':
		Digit_Led_Test();
		break;	
	case '2':
		Uart_Printf("\nLook at LCD ...\n");
		//Lcd_Test();
		run = (void (*)(void))0x0;
		(*run)();		
		break;	
	case '3':
		Test_Keyboard();
		break;	
	case '4':
		Test_Iis();
		break;	
	case '5':
		Test_Timer();
		break;	
	case '6':
		Dhcp_Test();
		break;	
	case '7':
		Test_Flash();
		break;	
	case '8':
		Test_Iic();
		break;
	case '9':
		Tftp_Test();
		break;
	case 'A':
	case 'a':
		break;
	case 'B':
	case 'b':
		break;
	case 'T':
		if(Test_Rtc_Alarm())
		USE_RTC();
		break;
	case 't':
		Display_Rtc();
		break;
	case 0x20:
		Uart_Printf("\nJump to run:");
		Uart_GetString(&in_g);
		run = (void (*)(void))strtoul((unsigned char *)in_g);
		(*run)();
		break;
	default:
		break;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?