基于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