资源简介
基于msp430简单计算器的实现代码,其中后缀表达式的计算是用数组模拟栈的功能。
代码片段和文件信息
#include “io430.h“
#include
#include
#include
#include
//#include
#include “lcdoperate.h“
int count1;//操作数
int count2;//符号
float a[10];//操作数
char b[10];//符号
double result;
void OptrInIt2() /* 初始化运算符栈 */
{
count2=0;
b[count2]=‘\0‘;
}
void OpndInit1() /* 初始化操作数栈 */
{
count1=0;
a[count1]=‘\0‘;
}
int OptrEmpty1() /*判断操作符数组是否空 定义栈空事件 */
{
if(count1<=0) /*判断栈空*/
return 1; /* 栈空返回1,否则为0 */
else
return 0;
}
int OptrEmpty2()
{
if(count2<=0) /*判断操作符数组是否为空*/
return 1; /* 栈空返回1,否则为0 */
else
return 0;
}
void OptrPush2(char elem) /* 入栈操作符 */
{
b[count2]=elem; /*栈未满则elem入栈*/
count2++;
}
char OptrPop2() /* 操作符出栈 */
{
char elem;
count2--; /*定义字符变量*/
elem=b[count2];
return elem;
}
char OptrGetTop2() /* 获取操作数栈顶元素 */
{
char elem;
/*定义字符变量*/
count2--;
elem=b[count2];
count2++;
return elem;
}
int OpndEmpty1() /* 判断数栈是否为空 */
{
if(count1<0)
return 1; /*操作数数组为空则返回1*/
else
return 0; /*操作数数组不为空则返回0*/
}
void OpndPush1(float elem) /* 入栈操作数 */
{
a[count1]=elem;
count1++;
}
float OpndPop1() /*操作数出栈 */
{
float elem;
count1--;/*定义字符变量*/
elem=a[count1];
return elem;
}
float OpndGetTop1() /* 获取栈顶元素 */
{
float elem;
/* 将栈顶值传给elem*/
count1--;
elem=a[count1];
count1++;
return elem; /*返回值*/
}
int isoper(char c) /* 判断是否为运算符 */
{
if(c==‘+‘||c==‘-‘||c==‘*‘||c==‘/‘||c==‘%‘)
return 1; /*如果c是‘+‘‘-‘‘/‘‘*‘中的一种则返回1*/
else
return 0; /*否则返回0*/
}
int priority(char c) /* 判断优先级 */
{
int p; /*定义一个整型数*/
switch(c)
{
case ‘+‘:
case ‘-‘: p=1;break; /* +-的优先级为1*/
case ‘*‘:
case ‘%‘:
case ‘/‘: p=2;break; /* ‘*‘‘%‘‘/‘的优先级为2*/
case ‘(‘: p=0;break; /* (的优先级为0*/
}
return(p); /*返回值*/
}
float calculate(float s1float s2char oper) /* 计算表达式 */
{
float y; /*定义一个浮点型*/
switch(oper)
{
case ‘+‘: y=s2+s1;break;
case ‘-‘: y=s2-s1;break;
case ‘*‘: y=s2*s1;break;
case ‘%‘: y=(int)((int)s2%(int)s1); break;
case ‘/‘: y=s2/s1;break; /*情形为‘/‘时*/
}
return(y); /*返回值*/
}
float StrToFloat(char *sint *j) /* 将字符串转化成数字 */
{
int ik; /*定义两个整型变量*/
char n[100]; /*定义一个数组*/
float f; /*定义一个浮点型*/
i=*j;
for(k=0;s[i]>=‘0‘ && s[i]<=‘9‘ || s[i]==‘.‘;i++k++) /*当数组里为0~9的数值或
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 14098 2012-06-28 11:36 test\Debug\Exe\ftoch.d43
文件 83606 2012-07-09 10:23 test\Debug\Exe\LSD-TEST430F5529-01-LCD.d43
文件 544 2012-07-09 09:27 test\Debug\Obj\calculate.pbi
文件 46844 2012-07-07 16:19 test\Debug\Obj\calculate.r43
文件 138 2012-06-28 15:46 test\Debug\Obj\ftoch.pbd
文件 546 2012-07-09 09:27 test\Debug\Obj\lcdoperate.pbi
文件 68592 2012-06-30 09:40 test\Debug\Obj\lcdoperate.r43
文件 540 2012-07-09 09:27 test\Debug\Obj\LCDziku.pbi
文件 7333 2012-07-06 17:04 test\Debug\Obj\LCDziku.r43
文件 351 2012-07-09 10:23 test\Debug\Obj\LSD-TEST430F5529-01-LCD.pbd
文件 572 2012-07-09 10:23 test\Debug\Obj\LSD-TEST430F5529-01-LCD.pbi
文件 166839 2012-07-09 10:23 test\Debug\Obj\LSD-TEST430F5529-01-LCD.r43
文件 473 2012-06-28 15:46 test\Debug\Obj\main.pbi
文件 5503 2012-06-28 11:36 test\Debug\Obj\main.r43
文件 5348 2012-07-09 10:23 test\LSD-TEST430F5529-01-LCD.dep
文件 17863 2012-06-25 14:39 test\LSD-TEST430F5529-01-LCD.ewd
文件 47537 2012-06-28 09:04 test\LSD-TEST430F5529-01-LCD.ewp
文件 177 2010-11-22 19:27 test\LSD-TEST430F5529-01-LCD.eww
文件 2213 2012-06-28 15:46 test\settings\ftoch.cspy.bat
文件 9669 2012-06-28 15:43 test\settings\ftoch.dbgdt
文件 1245 2012-06-28 15:43 test\settings\ftoch.dni
文件 6319 2012-06-28 15:43 test\settings\fTocha.wsdt
文件 2796 2012-07-09 10:23 test\settings\LSD-TEST430F5529-01-LCD.cspy.bat
文件 5948 2012-07-09 08:38 test\settings\LSD-TEST430F5529-01-LCD.dbgdt
文件 1223 2012-07-09 10:23 test\settings\LSD-TEST430F5529-01-LCD.dni
文件 4966 2012-07-09 10:23 test\settings\LSD-TEST430F5529-01-LCD.wsdt
文件 5757 2012-07-07 16:06 test\src\calculate.c
文件 15864 2010-11-22 19:27 test\src\lcdoperate.c
文件 1024 2012-06-30 09:40 test\src\lcdoperate.h
文件 16463 2012-07-06 17:04 test\src\LCDziku.c
............此处省略11个文件信息
相关资源
- IAR for MSP430 v7.10.1 注册机
- 电脑卡西欧计算器 fx-991CN X Emulator19中
- 基于MSP430G2553的蓝牙控制小车
- 利用DS1302和msp430进行闹钟和万年历的
- 卡西欧工程计算器模拟器Casio FX
- msp430F149操作红外接收模块源码
- [免费]msp430f149控制PS2键盘并用1602显示
- MSP430f149读sd FAT txt
- PIC 单片机定时器初值计算器
- 湍流k-e经验值计算器
- PIC单片机延时计算器
- MVC模式实现的计算器
- powerbuilder 计算器小程序
- 简单计算器的实现(数据结构)
- 简单计算器的实现(数据结构 修正版
- 基于51单片机的计算器(C51编写,有
- labview计算器实例.vi88218
- 用8位spi实现16位spi
- 基于MSP430单片机的实时多任务操作系
- EGM2008重力模型计算器
- 基于AT89S52单片机简易计算器的设计
- 中兴电视盒ADB密码计算器
- MSP430系列单片机例程(msp430f235)
- MSP430控制AD9850产生频率可调的方波及
- msp430f449程序
- 实验1.zip arduino跑马灯led灯实验,串口
- 基于MSP430的数控直流电压源
- 汇率计算器
- MSP430F5438A Timer_B 操作实验
- MSP430F5438 UCS 时钟操作实验
评论
共有 条评论