zoukankan      html  css  js  c++  java
  • 基于STM32F1 的BASIC解码实验 vb basic 液晶显示执行过程及结果

    基于STM32F1 的BASIC解码实验

    1、basic程序以文件形式存储

    2、程序文件存储在sd卡

    3、解释结果显示在液晶屏上

    主函数部分

    int main(void)
    {
    u16 i,j;

    delay_init(72); //延时初始化
    Init_Io();
    GLCD_Init(); //初始化液晶

    BACK_COLOR=0x001F;
    LCD_ShowString(30,10,"Mini STM32 SD Card TEST");
    LCD_ShowString(30,30,__DATE__);
    LCD_ShowString(150,30,__TIME__);

    ffext_mount(0, &fs);

    ffext_read("0:3.bas", wbuff2, 1024, FA_OPEN_ALWAYS | FA_READ);
    BACK_COLOR=0x001F;
    POINT_COLOR=0xF800;

    basic(wbuff2);

    while (1)
    {

    }
    }

    basic关键字部分

    struct commands /* 关键字查找表 */
    {
    char command[20];
    char tok;
    }table[] ={ /* 命令必须输入小写 */
    "print", PRINT,
    "input", INPUT,
    "if", IF,
    "then", THEN,
    "goto", GOTO,
    "for", FOR,
    "next", NEXT,
    "to", TO,
    "gosub", GOSUB,
    "return", RETURN,
    "end", END,
    "", END /* 单词表的结束 */
    };

    执行部分

    void basic(char *buf)
    {
    char *p_buf;


    /* 载入源文件 */

    p_buf=buf;
    if(setjmp(e_buf)) exit(1); /* 初始化长跳缓冲区 */

    prog = p_buf;
    scan_labels(); /* 在程序中找到标签 */
    ftos = 0; /* 初始化FOR堆栈索引 */
    gtos = 0; /* 初始化GOSUB堆栈索引 */
    do
    {
    token_type = get_token();
    /* 检查赋值语句 */
    if(token_type==VARIABLE)
    {
    putback(); /* 将变量返回到输入流 */
    assignment(); /* 必须是赋值语句 */
    }
    else /* 是命令 */
    switch(tok)
    {
    case PRINT:
    print();
    break;
    case GOTO:
    exec_goto();
    break;
    case IF:
    exec_if();
    break;
    case FOR:
    exec_for();
    break;
    case NEXT:
    next();
    break;
    case INPUT:
    input();
    break;
    case GOSUB:
    gosub();
    break;
    case RETURN:
    greturn();
    break;
    case END:
    printf("run basic end!");
    while(1);
    exit(0);
    }
    }while (tok != FINISHED);

    }

    //////////////////////////////////////////////////////////////////////////

    参考资料下载地址:http://pan.baidu.com/s/1nt2y7O1

    测试硬件:http://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-2613737244.27.uf9NEY&id=43666799360

  • 相关阅读:
    hdoj 2803 The MAX【简单规律题】
    hdoj 2579 Dating with girls(2)【三重数组标记去重】
    hdoj 1495 非常可乐【bfs隐式图】
    poj 1149 PIGS【最大流经典建图】
    poj 3281 Dining【拆点网络流】
    hdoj 3572 Task Schedule【建立超级源点超级汇点】
    hdoj 1532 Drainage Ditches【最大流模板题】
    poj 1459 Power Network【建立超级源点,超级汇点】
    hdoj 3861 The King’s Problem【强连通缩点建图&&最小路径覆盖】
    hdoj 1012 u Calculate e
  • 原文地址:https://www.cnblogs.com/ccjt/p/4302323.html
Copyright © 2011-2022 走看看