⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 MSP acquires data and sends through USB to PC. Check the link for PC capture software and project d
💻 C
📖 第 1 页 / 共 3 页
字号:

/**
 * Menu point which displays all characters.
 */
void showFont ()
{
    KBD_buttonPressed_t buttonPressed;
    const uint16_t charNum = 128;
    uint16_t c = 0;
    bool_t printChars = TRUE;
    uint8_t i;

    do
    {
        if (printChars)
        {
            LCD_clear ();
            LCD_setXY (0, 0);
            LCD_setFGColor (LCD_COLOR_BLUE);
            LCD_printf ("0x%02X-0x%02X:\n", (int) c, (int) c + charNum - 1);
            LCD_setFGColor (LCD_COLOR_BLACK);
            for (i = 0; i < charNum; i++)
            {
                if (c != 0xA && c != 0) // skip \n character
                {
                    LCD_printf ("%c", (char) (c++ & 0xFF));
                }
                else
                {
                    LCD_printf (" ", c++);
                }
            }
            if (c > 0xFF)
            {
                c = 0;
            }
            printChars = FALSE;
            LCD_setXY (0, LCD_HEIGHT - FONT_HEIGHT);
            LCD_setFGColor (LCD_COLOR_BLUE);
            LCD_printf ("Press OK/Quit");
        }

        buttonPressed = KBD_getButtonPressed ();

        if (buttonPressed & KBD_OK)
        {
            printChars = TRUE;
        }

        mdelay (20);
    } while (!(buttonPressed & KBD_QUIT));
}

/**
 * Menu point to test keyboard.
 */
void keyboardTest ()
{
    JOY_pos_t jpos;

    LCD_setXY (0, LCD_HEIGHT - (FONT_HEIGHT * 2));
    LCD_printf ("Press B1 & B2 toquit!");
    do
    {
        LCD_setXY (0, 0);
        jpos = JOY_getPosition();
        if (jpos & JOY_POS_RIGHT)
        {
            LCD_printf ("R");
        }
        else
        {
            LCD_printf ("\xB7");
        }
        if (jpos & JOY_POS_LEFT)
        {
            LCD_printf ("L");
        }
        else
        {
            LCD_printf ("\xB7");
        }
        if (jpos & JOY_POS_DOWN)
        {
            LCD_printf ("D");
        }
        else
        {
            LCD_printf ("\xB7");
        }
        if (jpos & JOY_POS_UP)
        {
            LCD_printf ("U");
        }
        else
        {
            LCD_printf ("\xB7");
        }
        if (jpos & JOY_POS_CENTER)
        {
            LCD_printf ("C");
        }
        else
        {
            LCD_printf ("\xB7");
        }
        if (KBD_getB1 ())
        {
            LCD_printf ("1");
        }
        else
        {
            LCD_printf ("\xB7");
        }
        if (KBD_getB2 ())
        {
            LCD_printf ("2");
        }
        else
        {
            LCD_printf ("\xB7");
        }
    } while (!(KBD_getB1 () && KBD_getB2 ()));
    KBD_getButtonPressed ();
}

#ifdef NRF24L01
/**
 * Menu point to test extension module MOD-RF24Lx (2.4 GHz transceiver module) in master mode.
 */
void rf24lMasterTest ()
{
    KBD_buttonPressed_t buttonPressed;
    uint8_t outByte = 0x7F;
    uint8_t inByte;

    LCD_clear ();
    LCD_printf ("NRF init... ");
    NRF_init ();
    LCD_printf ("OK.\n");
    LCD_printf ("Press OK to send");

    do
    {
        buttonPressed = KBD_getButtonPressed ();

        if (buttonPressed & KBD_OK)
        {
            LCD_clear ();
            NRF_send (outByte);
            NRF_prepareForReceive ();
            LCD_printf ("Out: 0x%02X\n", outByte);
            outByte++;
        }
        if (NRF_receive (&inByte))
        {
            LCD_printf ("In: 0x%02X\n", inByte);
            if (inByte == (256 - outByte))
            {
                LCD_printf ("OK\n");
            }
            else
            {
                LCD_printf ("Error.\nExpected: 0x%02X\n", 256 - outByte);
            }
        }
        if (LCD_getY () >= LCD_HEIGHT)
        {
            LCD_clear ();
        }
        mdelay (20);
    } while (!(buttonPressed & KBD_QUIT));
}

/**
 * Menu point to test extension module MOD-RF24Lx (2.4 GHz transceiver module) in slave mode.
 */
void rf24lSlaveTest ()
{
    KBD_buttonPressed_t buttonPressed;
    uint8_t outByte = 0x7F;
    uint8_t inByte;
    uint8_t cnt = 0;
    bool_t waitForAnswer = FALSE;

    LCD_clear ();
    LCD_printf ("NRF init... ");
    NRF_init ();
    LCD_printf ("OK.\n");

    do
    {
        buttonPressed = KBD_getButtonPressed ();

        if (NRF_receive (&inByte))
        {
            //LCD_printf ("In: 0x%02X\n", inByte);
            outByte = 255 - inByte;
            mdelay (50); // wait for the other side to switch to RX mode!
            NRF_send (outByte);
            NRF_prepareForReceive ();
            LCD_printf ("0x%02X -> 0x%02X\n", inByte, outByte);
        }
        if (LCD_getY () >= LCD_HEIGHT)
        {
            LCD_clear ();
        }
        mdelay (20);
    } while (!(buttonPressed & KBD_QUIT));
}
#endif

/**
 * RF24L test sub-menu.
 */
menuPoint_t rf24lTestMenu[] = 
{
    //1234567890123456
    {"Master mode",         NULL, rf24lMasterTest},
    {"Slave mode",          NULL, rf24lSlaveTest},
    {NULL,                  NULL, NULL}             // end of menu
};

/**
 * Date/time sub-menu.
 */
menuPoint_t dateTimeMenu[] = 
{
    //1234567890123456
    {"Set date/time",       NULL, setDateTime},
    {"Show date/time",      NULL, showDateTime},
    {NULL,                  NULL, NULL}             // end of menu
};

/**
 * SD/MMC sub-menu.
 */
menuPoint_t sdMmcMenu[] = 
{
    //1234567890123456
    {"Mount card",          NULL, FF_init},
    {"Umount card",         NULL, FF_done},
    {"Show status",         NULL, FF_showStatus},
    {"List root dir",       NULL, FF_listRootDir},
    {"Show bitmap",         NULL, FF_showBitmap},
    {"File test",           NULL, FF_fileTest},
    {NULL,                  NULL, NULL}             // end of menu
};

/**
 * MMA (accelerator) sub-menu.
 */
menuPoint_t mmaMenu[] = 
{
    //1234567890123456
    {"Ball test",           NULL, mmaBallTest},
    {"Show raw values",     NULL, mmaRawValues},
    {NULL,                  NULL, NULL}             // end of menu
};

/**
 * Root menu.
 */
menuPoint_t rootMenu[] = 
{
    //1234567890123456
#ifdef NRF24L01
    {"RF24L test",          rf24lTestMenu, NULL},
#endif
    {"Date/time",           dateTimeMenu, NULL},
    {"SD/MMC",              sdMmcMenu, NULL},
    {"MMA",                 mmaMenu, NULL},
    {"VCC",                 NULL, showVcc},
    {"Temperature",         NULL, showTemp},
    {"Show font",           NULL, showFont},
    {"Keyboard test",       NULL, keyboardTest},
    {NULL,                  NULL, NULL}             // end of menu
};

/**
 * Initialize application.
 */
void init ()
{
    uint16_t i;

    // Freq init
    InitFreq ();     // (DCO: 8MHz)
    // GPIO init
    GPIO_init ();
    // Buttons init
    KBD_init ();
    // Joystick init
    JOY_init ();
    // Timing & RTC init
    TIME_init ();
    // Interrupt enable
    //_EINT();
    // MMA init
    MMA_init ();

    //InitIRDA();
    // Init LCD
    LCD_init ();
    // Initialize FAT filesystem
    //FF_init ();
    // Initialize menu system
    MENU_init (rootMenu);
}

/**
 * Infinite loop of application.
 */
void run ()
{
    uint8_t oldSec = 0xFF;
    TIME_date_t date;
    
    while (1) 
    {
        MENU_handler (KBD_getButtonPressed ());
        
        // get current date
        TIME_getDate (&date);
        if (date.sec != oldSec)
        {
            // show current date
            LCD_setXY (0, LCD_HEIGHT - FONT_HEIGHT);
            LCD_setColor (LCD_COLOR_RED, LCD_COLOR_WHITE);
            LCD_printf ("%02i.%02i.%02i   %02i-%02i", date.hour, date.min, date.sec, date.month, date.day);
            oldSec = date.sec;
        }

        mdelay (20);
    }
}

/**
 * Entry point of program.
 */
int main ()
{

    init ();
    run ();
    return 0;
}

/**
 * @mainpage
 * This is an example project for the MSP430-4619LCD development board,
 * which is produced by Olimex Ltd. I've used Linux, but maybe you can use any
 * operating system which has GNU make and mspgcc. The code is from Olimex,
 * ChaN (FatFs) and me.
 *
 * Features:
 * - Simple menu system:
 *   MENU_handler()
 * - MMA test:
 *   mmaBallTest() mmaRawValues()
 * - Measuring VCC and temperature:
 *   showVcc() showTemp()
 * - Keyboard and joystick test:
 *   keyboardTest()
 * - LCD handling. Writing text to display with printf, displaying RGB
 * bitmaps:
 *   LCD_printf() LCD_write130x130bmp()
 *   <br>Usable font included (ProggySquareSZ)!
 * - SD card and DOS filesystem handling: creating, reading files, etc: 
 *   FF_fileTest()
 *   Thanks to ChaN for the FatFs module: http://elm-chan.org/fsw/ff/00index_e.html
 * - MOD-NRF24Lx extension board handling: NRF_send() NRF_receive() <br>
 *   The P85 points of P85/SDA jumper and the P84 points of P84/SCL jumper should be shortened.
 * - Timing functions: RTC, delay, etc.:
 *   TIME_setDate() TIME_getDate() delay() mdelay()
 * 
 * You should set your LCD type (GE8/GE12) in lcd.h! I've got GE8, so if you set GE12
 * maybe doesn't work.
 *
 * Additional tools:
 *  - font2c.pl: PERL script to convert .hex font files to C code. You can create Hex font files
 *  with 'gbdfed'.
 *  - img2c.pl: PERL script to convert pictures (.png, .jpg, etc.) to C code
 *  (12-bit RGB format).
 *
 * Quick how-to for make:
 *  - Type <code>make</code> to compile the code.
 *  - Type <code>make flash</code> to flash program to the MSP430's ROM.
 *  - Type <code>make doc</code> to generate documentation.
 *
 * You can download this sample here:
 * http://dev.ivanov.eu/projects/msp430-4619lcd_sample/msp430-4619lcd_sample.tar.gz
 * http://dev.ivanov.eu/projects/msp430-4619lcd_sample/msp430-4619lcd_sample.zip
 *
 * Contact: Peter Ivanov 
 * E-mail: ivanovp__AT__gmail__DOT__com__NOSPAM
 */

⌨️ 快捷键说明

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