libitao 发表于 2012-12-22 21:38:58

关于C语言讨论一下 附代码

本帖最后由 libitao 于 2012-12-22 21:41 编辑

struct {
        void (*fun)(void);
        char *tip;
}CmdTip[] = {
                                { Temp_function, "Please input 1-14 to select test"},
                                { Uart2_Test, "COM port ( UART2 ) test"},
                                { UsbMain, "Download file from PC via USB port"},
                                //{ comdownload, "Download file from PC via COM port"},
                                { BUZZER_PWM_Test, "Buzzer test"},
                                { RTC_Display, "Real time clock display" },
                                { Test_Adc, "ADC test" },
                                { Key_Scan_Test, "8*2 key array test"},
                                { Touch_Screen_Init, "Touchpanel test" },
                                {Test_Lcd_AT070TN83, "7.0# TFT LCD 800*480 test"},
                                {Test_Lcd_AT080TN52, "8.0# TFT LCD 800*600 test"},
                                { Test_Lcd_WXCAT43,"4.3# TFT LCD 480*272 test"},
                                {Test_Lcd_CT35TF05,"3.5# TFT LCD 320*240 test"},
                                { Test_IrDA_Tx, "IRDA test"},
                                { Test_Iic, "IIC EEPROM test" },
                                { PlayMusicTest, "UDA1341 play audio test"},
                                { RecordTest, "UDA1341 record audio test"},
                                { SDI_test, "SD Card write and read test"},
                                {Led_Test,"led test"},
                                { 0, 0}                                               
                        };

/************************************************************/
void KeyScanInit(void);

int Main()
{
        int i;       
       
#if 0                        //bank0 modified to RO_START
    MMU_Init();        //MMU should be reconfigured or turned off for the debugger,
    //After downloading, MMU should be turned off for the MMU based program,such as WinCE.       
#else
    MMU_EnableICache();      
#endif                
        SetClockDivider(1, 1);
        SetSysFclk(DFT_FCLK_VAL);
        Delay( 0 ) ;
        Port_Init();
        Isr_Init();
        Uart_Select(0);
        Uart_Init(0, UART_BAUD);
        RequestBiosTimerEvent(10, Led1Flash);        //when request, auto open bios timer
        RequestBiosTimerEvent(20, Led2Flash);
        RequestBiosTimerEvent(50, Led3Flash);
        RequestBiosTimerEvent(100, Led4Flash);
        //GPIO,UART0,PWM TIMER,NAND FLASH
        EnableModuleClock(CLOCK_UART0|CLOCK_TIMER|CLOCK_GPIO|CLOCK_NAND|CLOCK_LCD);

    Lcd_Port_Init();
    Lcd_Init();
    rLCDCON1 |= 1;         // ENVID=ON
    Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x1f) );   //clear screen
        Beep( 2000, 2000 ) ;


        while(1)
        {
                U8 idx=0;
                puts("\nPlease select function : \n");       
                for(i=0; CmdTip.fun!=0; i++)
                        printf("%2d : %s\n", i, CmdTip.tip);
                idx = Uart_GetIntNum_GJ() ;
                {
                        (*CmdTip.fun)();
                }       
        }                 


这个是某开发板的硬件测试 界面想请教一下红色字体部分的是什么意思 谢谢各位了

myqiang1990 发表于 2012-12-22 21:56:29

执行函数指针指向的函数~~~

myqiang1990 发表于 2012-12-22 21:59:55

本帖最后由 myqiang1990 于 2012-12-22 22:07 编辑

就是把结构体数组CmdTip[]里面的void (*fun)(void)成员指向的函数全部执行一遍嘛~~

binaimei2007 发表于 2012-12-22 22:22:06

先打印每个要测试功能的名字,然后利用Uart_GetIntNum_GJ() 这个函数获取你在串口上输入的数字,来决定执行哪个功能

libitao 发表于 2012-12-22 23:29:08

本帖最后由 libitao 于 2012-12-22 23:30 编辑

{:2_31:}谢谢两位高手 明白了
页: [1]
查看完整版本: 关于C语言讨论一下 附代码