单片机lcd一位数加减乘除串行口程序如何进行加减乘除运算

串口实现简单加减乘除 - 单片机/MCU论坛 -
中国电子技术论坛 -
最好最受欢迎电子论坛!
后使用快捷导航没有帐号?
串口实现简单加减乘除
<div class=""
#include&reg52.h&
#include&stdio.h&
unsigned char j=0,flag=0,num1,num2,fh1,result,a,b,c;
unsigned char receive[4]={0,1,2,3};
void main()
& & & & TMOD=0x20;&&
& & & & TH1=0xE8;
& & & & TL1=0xE8;
& & & & TR1=1;
& & & & REN=1;
& & & & SM0=0;
& & & & SM1=1;
& & & & ES=1;
& & & & EA=1;
& & & & while(1)
& & & & & & & & if(flag==3)
& & & & & & & & {
& & & & & & & & & & & & ES=0;
& & & & & & & & & & & & num1=receive[0]-'0';
& & & & & & & & & & & & num2=receive[2]-'0';
& & & & & & & & & & & & if(receive[3]=='=')
& & & & & & & & & & & & {
& & & & & & & & & & & & if(receive[1]=='+')
& & & & & & & & & & & & & & & & result=num1+num2;
& & & & & & & & & & & & if(receive[1]=='-')
& & & & & & & & & & & & & & & & result=num1-num2;
& & & & & & & & & & & & if(receive[1]=='/')&&
& & & & & & & & & & & & & & & & result=num1/num2;
& & & & & & & & & & & & if(receive[1]=='*')
& & & & & & & & & & & & & & & & result=num1*num2;
& & & & & & & & & & & & SBUF=result+'0';
& & & & & & & && & }
& & & & & & & & & & & & while(!TI);
& & & & & & & & & & & & TI=0;
& & & & & & & & & & & & ES=1;
& & & & & & & & }
void serial_() interrupt 4&&
& & & & RI=0;
& & & & receive[j]=SBUF;
& & & & flag++;
& & & & j++;
为什么什么都没没有返回(我想实现简单的算法)
16:49:48  
很有想法。
大神们请赐教
Powered by
供应链服务
版权所有 (C) 深圳华强聚丰电子科技有限公司51单片机100内的加减乘除计算器C语言程序
> 51单片机100内的加减乘除计算器C语言程序
51单片机100内的加减乘除计算器C语言程序
//包含文件 #define uchar unsigned char
#define uint
unsigned int
char b[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,
0xa1,0x86,0x8e,0x8c,0xc1,0xce,0x91,0x89,0xc7,0xff};
// 共阴极字符码
//延时函数,用于实现程序中的短暂延时,表示延时cnt个毫秒
void delay(unsigned int cnt)
while(cnt--)
for(i=220;i>0;i--)
//键盘扫描程序
uchar keyboardscan(void)
uchar sccode,
//P1口附初值
if((P1&0xf0)!=0xf0)//如果P1口电平不等于0xf0,表示有按键按下
delay(20);
//延时20毫秒后再判断,看是否还有按键按下,次步为软件防抖
if((P1&0xf0)!=0xf0)//继续判断是否有按键按下
//进行逐行判断
while((sccode&0x10)!=0)
if((P1&0xf0)!=0xf0)
recode=(P1&0xf0|0x0f);
switch((~sccode)+(~recode))
// 下面是键盘的编码识别
case 0x11:
return(1);
case 0x21:
return(2);
case 0x41:
return(3);
case 0x81:
return(11);//返回对应的键值0~15
case 0x12:
return(4);
case 0x22:
return(5);
case 0x42:
return(6);
case 0x82:
return(12);
case 0x14:
return(7);
case 0x24:
return(8);
case 0x44:
return(9);
case 0x84:
return(13);
case 0x18:
return(10);
case 0x28:
return(15);
case 0x48:
return(16);
case 0x88:
return(14);
sccode = (sccode<<1)|0x01;
return(0xff); //如果没有按键按下,则返回0xff
void output(uchar number)
P0=b[number/10];
P2=b[number%10];
int yunsuan(uchar a,uchar b,uchar c)
case 1:return(a/b);
case 2:return(a*b);
case 3:return(a-b);
case 4:return(a+b);
void main(void)
unsigned char n1,n2,key,index,a;
n1=n2=index=0;
P0=P2=b[0];
key = keyboardscan();//键盘扫描,看是否有按键按下
if(key != 0xff)//如果有按键按下,则key不再是0xff了,显示该按键键值
if(key<10)
if(!index) n1=key%10;
else n2=key%10;
output(key%10);
else if(key==15)
n1=n2=index=0;
output(0);
else if(key==16)
if(!index) output(n1);
a=yunsuan(n1,n2,index);
output(a);
n2=index=0;
if(index==0||n2==0) index=key-10;
a=yunsuan(n1,n2,index);
output(a);
index=key-10;
分享给小伙伴们:
我来说两句……
微信公众号二
微信公众号一51单片机简易计算器可加减乘除_单片机吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:150,805贴子:
51单片机简易计算器可加减乘除收藏
求程序跟仿真图 AT89c52的单片机4#4矩阵键盘
零基础入学,高薪就业!由10年以上ARM实战经验资深工程师任教,研发主管全程任教,实际项目教学,让你来腾云学到真本事,让你成功加薪,转行,高升!
我有现成的
扣扣,3-1-7-9-4-5-8-9-2
我有做好的,加我vx
登录百度帐号&>&单片机设计计算器
实现加减乘除简单功能
单片机设计计算器
实现加减乘除简单功能
上传大小:8KB
单片机设计计算器
实现加减乘除简单功能
能处理四个字节的数据
综合评分:4
{%username%}回复{%com_username%}{%time%}\
/*点击出现回复框*/
$(".respond_btn").on("click", function (e) {
$(this).parents(".rightLi").children(".respond_box").show();
e.stopPropagation();
$(".cancel_res").on("click", function (e) {
$(this).parents(".res_b").siblings(".res_area").val("");
$(this).parents(".respond_box").hide();
e.stopPropagation();
/*删除评论*/
$(".del_comment_c").on("click", function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_invalid/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parents(".conLi").remove();
alert(data.msg);
$(".res_btn").click(function (e) {
var parentWrap = $(this).parents(".respond_box"),
q = parentWrap.find(".form1").serializeArray(),
resStr = $.trim(parentWrap.find(".res_area_r").val());
console.log(q);
//var res_area_r = $.trim($(".res_area_r").val());
if (resStr == '') {
$(".res_text").css({color: "red"});
$.post("/index.php/comment/do_comment_reply/", q,
function (data) {
if (data.succ == 1) {
var $target,
evt = e || window.
$target = $(evt.target || evt.srcElement);
var $dd = $target.parents('dd');
var $wrapReply = $dd.find('.respond_box');
console.log($wrapReply);
//var mess = $(".res_area_r").val();
var mess = resS
var str = str.replace(/{%header%}/g, data.header)
.replace(/{%href%}/g, 'http://' + window.location.host + '/user/' + data.username)
.replace(/{%username%}/g, data.username)
.replace(/{%com_username%}/g, data.com_username)
.replace(/{%time%}/g, data.time)
.replace(/{%id%}/g, data.id)
.replace(/{%mess%}/g, mess);
$dd.after(str);
$(".respond_box").hide();
$(".res_area_r").val("");
$(".res_area").val("");
$wrapReply.hide();
alert(data.msg);
}, "json");
/*删除回复*/
$(".rightLi").on("click", '.del_comment_r', function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_comment_del/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parent().parent().parent().parent().parent().remove();
$(e.target).parents('.res_list').remove()
alert(data.msg);
//填充回复
function KeyP(v) {
var parentWrap = $(v).parents(".respond_box");
parentWrap.find(".res_area_r").val($.trim(parentWrap.find(".res_area").val()));
评论共有2条
很好很强大,楼主期待你的佳作!
算法简单,容易理解
VIP会员动态
CSDN下载频道资源及相关规则调整公告V11.10
下载频道用户反馈专区
下载频道积分规则调整V1710.18
spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip
资源所需积分/C币
当前拥有积分
当前拥有C币
输入下载码
为了良好体验,不建议使用迅雷下载
单片机设计计算器
实现加减乘除简单功能
会员到期时间:
剩余下载个数:
剩余积分:0
为了良好体验,不建议使用迅雷下载
积分不足!
资源所需积分/C币
当前拥有积分
您可以选择
程序员的必选
绿色安全资源
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
您的积分不足,将扣除 10 C币
为了良好体验,不建议使用迅雷下载
无法举报自己的资源
你当前的下载分为234。
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可返还被扣除的积分
被举报人:
请选择类型
资源无法下载 ( 404页面、下载失败、资源本身问题)
资源无法使用 (文件损坏、内容缺失、题文不符)
侵犯版权资源 (侵犯公司或个人版权)
虚假资源 (恶意欺诈、刷分资源)
含色情、危害国家安全内容
含广告、木马病毒资源
*投诉人姓名:
*投诉人联系方式:
*版权证明:
*详细原因:
单片机设计计算器
实现加减乘除简单功能51单片机100内的加减乘除计算器C语言程序
单片机&嵌入式
单片机应用
嵌入式操作系统
学习工具&教程
学习和开发单片机的必备工具
(有问必答)
(带你轻松入门)
电子元件&电路模块
当前位置: >>
>> 浏览文章
51单片机100内的加减乘除计算器C语言程序
#include &reg52.h>
//包含文件
#define uchar unsigned char
#define uint
unsigned int
char b[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,
0xa1,0x86,0x8e,0x8c,0xc1,0xce,0x91,0x89,0xc7,0xff};
// 共阴极字符码
//延时函数,用于实现程序中的短暂延时,表示延时cnt个毫秒
void delay(unsigned int cnt)
while(cnt--)
for(i=220;i>0;i--)
//键盘扫描程序
uchar keyboardscan(void)
uchar sccode,
//P1口附初值
if((P1&0xf0)!=0xf0)//如果P1口电平不等于0xf0,表示有按键按下
delay(20);
//延时20毫秒后再判断,看是否还有按键按下,次步为软件防抖
if((P1&0xf0)!=0xf0)//继续判断是否有按键按下
//进行逐行判断
while((sccode&0x10)!=0)
if((P1&0xf0)!=0xf0)
recode=(P1&0xf0|0x0f);
switch((~sccode)+(~recode))
// 下面是键盘的编码识别
case 0x11:
return(1);
case 0x21:
return(2);
case 0x41:
return(3);
case 0x81:
return(11);//返回对应的键值0~15
case 0x12:
return(4);
case 0x22:
return(5);
case 0x42:
return(6);
case 0x82:
return(12);
case 0x14:
return(7);
case 0x24:
return(8);
case 0x44:
return(9);
case 0x84:
return(13);
case 0x18:
return(10);
case 0x28:
return(15);
case 0x48:
return(16);
case 0x88:
return(14);
sccode = (sccode&&1)|0x01;
return(0xff); //如果没有按键按下,则返回0xff
void output(uchar number)
P0=b[number/10];
P2=b[number%10];
int yunsuan(uchar a,uchar b,uchar c)
case 1:return(a/b);
case 2:return(a*b);
case 3:return(a-b);
case 4:return(a+b);
void main(void)
unsigned char n1,n2,key,index,a;
n1=n2=index=0;
P0=P2=b[0];
key = keyboardscan();//键盘扫描,看是否有按键按下
if(key != 0xff)//如果有按键按下,则key不再是0xff了,显示该按键键值
if(key&10)
if(!index) n1=key%10;
else n2=key%10;
output(key%10);
else if(key==15)
n1=n2=index=0;
output(0);
else if(key==16)
if(!index) output(n1);
a=yunsuan(n1,n2,index);
output(a);
n2=index=0;
if(index==0||n2==0) index=key-10;
a=yunsuan(n1,n2,index);
output(a);
index=key-10;
【】【】【】【】
上一篇:下一篇:
CopyRight @
单片机教程网 51hei.com , All Rights Reserved

我要回帖

更多关于 单片机程序两个数进行加减乘除 的文章

 

随机推荐