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

📄 simple_term.c

📁 SHARP_ARM720T_LH79524/5软件开发包_支持TFT_LCD_NAND_FLASH_ETH_USB
💻 C
字号:
/**********************************************************************
 * Copyright (c) 2002 Sharp Microelectronics of the Americas
 *
 *        All rights reserved
 *      
 * $Workfile:   simple_term.c  $
 * $Revision:   1.0  $
 * $Author:   ZhangJ  $
 * $Date:   Oct 20 2004 09:27:40  $
 *
 * SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
 * OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
 * AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES, 
 * SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
 *
 * SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY 
 * FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A 
 * SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
 * FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
 *
 * Project: LH79524 SWIM Example Code
 *
 * Description:
 *    This example shows how to use SWIM (Sharp Windows GUI package) 
 *
 * Notes:
 *  
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh79524/bsps/sdk79524/examples/simple_terminal/simple_term.c-arc  $
 * 
 *    Rev 1.0   Oct 20 2004 09:27:40   ZhangJ
 * Initial revision.
 * 
 *    Rev 1.0   Sep 07 2004 09:13:50   ZhangJ
 * Initial revision.
 * 
 * 
 *********************************************************************/

#include "abl_swim.h"
#include "abl_swim_font.h" 
#include "abl_lcd_params.h"
#include "lh79524_chip.h"
#include "lh79524_clcdc_driver.h"
#include <string.h>
#include "lh79524_uart_driver.h"
#include "lh79524_gpio.h"


/* Board specific definition */
#define SDK79524_XTAL_IN    11289600 

/* Display related variables */
#define DISPLAY_WIDTH  (240)
#define DISPLAY_HEIGHT (320)
#define FRAME 0x21000000        /* LCD frame buffer address */
#define LCD_DISPLAY sharp_lq035 /* Display type */

/* UART related variables */
#define ESC_KEY     27
#define STR_SIZE    80
static  CHAR * greeting =   "You can enter something now! \r\n";
static  CHAR * end_string = "Example done! \r\n";
static  CHAR output[STR_SIZE];
static  CHAR buffer[8];



/**********************************************************************
*
* Function: c_entry
*
* Purpose:
*   Function entry point from the startup code.
*  
* Processing:
*   
*
* Parameters:
*   None
*
* Outputs:
*   None
*
* Returns:
*   Nothing
*
* Notes:
*   None
*
**********************************************************************/
INT_32 c_entry (void)
{
    INT_32 dev_lcd;
    INT_32 dev_uart;
    SWIM_WINDOW_T win1;
    SWIM_WINDOW_T win2;
    SWIM_WINDOW_T win3;
    CLCDC_SETTINGS_T lcdcfg = {(LCD_PARAM_T*)&LCD_DISPLAY, SDK79524_XTAL_IN};
    INT_32 index;
    
    /* Open a window on the left side of the display */
    swim_window_open(&win1,
                     DISPLAY_WIDTH,
                     DISPLAY_HEIGHT,
                     (COLOR_T *) FRAME,
                     DISPLAY_WIDTH-(DISPLAY_WIDTH-5), 
                     DISPLAY_HEIGHT-(DISPLAY_HEIGHT-5), 
                     DISPLAY_WIDTH-5, 
                     DISPLAY_HEIGHT-5, 
                     1,
                     WHITE,
                     BLACK,
                     DARKGRAY);
    swim_set_title (&win1, "Simple Terminal - Displaying UART Inputs", RED);
            
    /* Open LCD */
    if ((dev_lcd = lcd_open(LCD_BASE, (INT_32) &lcdcfg)) == 0x0)
    {
        /* Error opening the device */
        return 0;
    }
    
    /* Set LCD display pointer */
    lcd_ioctl(dev_lcd, LCD_SET_FB, (INT_32)FRAME );
    
    /* Turn on LCD */
    lcd_ioctl(dev_lcd, LCD_PW_ENABLE, 0);

    /* Output the next iteration message in the window */
    swim_put_text(&win1, " Text in window 1:\n\n");

    /* 
     * Open UART. By default, it is configured as 115200 baud rate,
     * 8 bit data, none parity check, and 1 stop bit. 
     */
    if ((dev_uart = uart_open(UART0_BASE, SDK79524_XTAL_IN)) == 0x0)
    {
        /* Error */
        return 1;
    }
    
    /* Operation mode configuration */
    uart_ioctl(dev_uart, UART_ENABLE_FIFO, 0);
    uart_ioctl(dev_uart, UART_ENABLE_RX, 0);
    uart_ioctl(dev_uart, UART_ENABLE_TX, 0);
    uart_ioctl(dev_uart, UART_START, 0);
    uart_ioctl(dev_uart, UART_SET_POLL_MODE, 0);        

    /* Output a string */
    uart_write(dev_uart, greeting, strlen(greeting));

    /* Set variables to accept new input chars */
    index = 0;
    output[0] = '\0';
    
    /* 
     * If the ESC key is pressed, exit from the while() loop.
     * If the ENTER key is pressed, or the number of input chars 
     * are more than the predefined string length, Echo back the string.
     */
    while (1)
    {
        /* Read in one char */
        while(uart_read(dev_uart, buffer, 1) == 0);
            
        buffer[1] = '\0';
        
        if(buffer[0] == ESC_KEY)
        {
            /* ESC key, exit */
            break;
        }
        else if((buffer[0] == '\r') || (index >= STR_SIZE))
        {
            /* Send string out */
            uart_write(dev_uart,"\r\n",2);
            /* Echo the input to LCD */
            swim_put_text(&win1,"\r\n");
            uart_write(dev_uart, "You entered - ", 15);
            /* Echo the input to LCD */
            swim_put_text(&win1, "You entered - ");            
            uart_write(dev_uart, output, strlen(output));
            /* Echo the input to LCD */
            swim_put_text(&win1, output);            
            uart_write(dev_uart,"\r\n",2);
            /* Echo the input to LCD */
            swim_put_text(&win1, "\r\n");            
            uart_write(dev_uart,"\r\n",2);
            /* Echo the input to LCD */
            swim_put_text(&win1, "\r\n");            
            /* Send out a greeting string. Set variables to accept a new string. */
            uart_write(dev_uart, greeting, strlen(greeting));
            /* Echo the input to LCD */
            swim_put_text(&win1, greeting);

            output[0] = '\0';
            index = 0;
        }
        else
        {
            /* Received something */
            strcat(output, buffer);
            /* Echo the input to UART */
            uart_write(dev_uart, buffer, 1);
            /* Echo the input to LCD */
            swim_put_text(&win1, buffer);
            
        }
        index++;
    }

    /* Send out the prompt string before exit */
    uart_write(dev_uart, end_string, strlen(end_string));
    /* Echo the input to LCD */
    swim_put_text(&win1, end_string);
    
    /* Close device */
    uart_close(dev_uart);

    return 2;
}


#ifdef __iar

void main(void)
{
	c_entry();
	while(1);
}

#endif


⌨️ 快捷键说明

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