基于Proteus的计算器仿真

/******************************************************************

* 实验名称:Calculation 显示仿真 (MSP430F249) 

*        

* 实验说明:

*     通设置系统主时钟(MCLK=8Mhz ) 、辅助时钟(ACLK=8Mhz )、

*      子系统时钟(SMCLK=8Mhz )

* 编译软件:Embedded Workbench 6.4

*

*仿真软件:proteus7.8 sp 2

******************************************************************/

本实验采用的单片机是MSP430F249,用4x5的矩阵式非编码键盘作为计算器的输入按键,显示模块采用LM3229,该计算器的功能包括“+、-、*、/ 、^、 清除、返回上一次计算”等功能。

void main(void)
{
    /*str为表达式数组*/
    char str[MAX]="7+(8*9)+1";
    char result[10];
    unsigned char inputc='E', pos=0;
    char next = 0;
    
    init();   
    keyInit();
    LCD_Init();
     

    writeString(1,0,"hello!");

    while(1)
    {
        //scan key value
        inputc = scanKey();
        //whether it is vaild
        if(inputc != '_')
        {
            if(next)
            {
                clearCaculation();
                next = 0;
            }            
            if(inputc == '=')
            {
                str[pos]='\0';
                caculation(str, result);
                {
                    writeChar(6,0,'=');
                    writeString(6,1,result);
                    memset(result,0,10);
                    next = 1;
                }
                pos = 0;
                continue;
            }
            if(inputc == 'c')
            {
                //clear caculation result.
                clearCaculation();
                pos=0;
                continue;
            }
            if(inputc == 'b')
            {
                //back one step
                pos--;
                writeChar(5,pos,' ');
                continue;
            }     
            str[pos] = inputc;
            writeChar(5,pos,inputc);
            pos++;
        }
    }    
}

实验结果如下所示:

 

需要下载代码的朋友可以关注微信公众号:时沿科技,或者下方二维码免费下载

 

 

 

 

  • 2
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NemoYxc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值