STC89c52单片机 计算器C语言程序

合集下载

基于STC89C52的简易计算器设计..

基于STC89C52的简易计算器设计..

福建电力职业技术学院课程设计课程名称:《智能仪器》题目:基于STC89C52的简易计算器设计专业班次:姓名:学号:指导教师:学期:2011-2012学年第2学期日期:2012.2目录目录1.引言 (1)1.1 设计意义 (1)1.2 设计任务和主要内容 (1)2. 硬件设计 (2)2.1 系统框图 (2)2.2 最小系统 (2)2.3 矩阵键盘 (3)2.4 LCD1602 (4)3. 软件设计 (5)3.1矩阵键盘扫描原理 (5)3.2 LCD1602的软件设计 (6)3.3 主程序设计 (8)3.4 源程序 (9)3.5 调试结果 (9)4. 设计小结 (9)参考文献 (10)附录 (10)1.引言随着社会的发展,人们生活水平的提高,单片机的应用越来越贴近生活了,人们常用单片机来实现一些简单的电子设计。

计算器在人们的日常生活中是不可或缺的电子产品之一,目前市场上的计算器基本可以满足我们的日常需求,但它还在发展之中,我们要继续研究出更加强大的计算器。

基于这样的理念,本设计采用单片机来设计简易计算器。

本设计是以STC89C52为单片机,LCD为显示器设计的简易计算器,所设计的计算器将完成两位数的加、减、乘、除等功能。

1.1 设计意义通过本次课程设计,进一步掌握单片机知识,知道AT89S52单片机的原理、编程和各种功能的应用,了解简易计算器的工作原理,初步掌握计算器的硬软件设计、编写、调试和仿真,充分提高动手能力和排除故障的能力,同时通过课程设计加深我们对单片机的认识和兴趣,发挥我们的创新能力和动手能力。

1.2 设计任务和主要内容本设计要制作的就是单片机于生活中最为常见的一种应用——简易计算器,以STC89C52单片机作为核心来进行的数字计算器模拟系统设计,可以完成计算器的键盘输入,进行加、减、乘、除两位数范围内的基本四则运算,并在LCD 上显示相应的结果。

设计电路采用AT89C51单片机为主要控制电路,显示采用LCD静态显示,软件方面使用C语言编程,并用PROTUES仿真。

STC89C52单片机的一些程序,包括串口通信,定时中断

STC89C52单片机的一些程序,包括串口通信,定时中断

针对STC89C52RC单片机的一些程序基本串口通信程序:#include<reg52.h>#define uint unsigned int#define uchar unsigned char#define SEND 0#define RECEIVE 1uchar flag_Serial = SEND;uchar Rx_Buf;sbit SMG = P1^7;//0 1 2 3 4 5 6 7 8 9 a b c d e fuchar code Show[16]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x19,0x11,0xc1,0x63,0x85,0x61,0x71};void Serial_Init();void Serial_send();void Display();void Delay_1ms(uchar z);/****************************************************/ //main function///****************************************************/ void main(){Serial_Init();while(1){switch(flag_Serial){case SEND:flag_Serial = RECEIVE;Serial_send();break;case RECEIVE:Display();break;}}}/****************************************************/ //serial initial///****************************************************/ void Serial_Init(){TMOD = 0X20; //work in mode 2PCON = 0X00;SCON = 0X50;TH1 = 0XFD; //BRUD 9600TL1 = 0XFD;TR1 = 1; //open interrupt 1ES = 1; //open the serialEA = 1; //open the key interruptflag_Serial = SEND;SMG = 0;}/****************************************************/ //serial interrupt function///****************************************************/ void Serial() interrupt 4 using 2{EA = 0;if(RI!=0&&flag_Serial==RECEIVE){RI = 0;Rx_Buf = SBUF;flag_Serial = SEND;}EA = 1;}/****************************************************/ //mcu send data to serial///****************************************************/ void Serial_send(){SBUF = Rx_Buf;while(TI==0);TI=0;}/****************************************************/ //display the data by SMG///****************************************************/ void Display(){P2 = Show[Rx_Buf];Delay_1ms(3);}/****************************************************/ //delay for z*1ms///****************************************************/ void Delay_1ms(uchar z){uchar i,j;for(i=z;i>0;i--)for(j=110;j>0;j--);}串口通信,按键加减#include<reg52.h>#define uint unsigned int#define uchar unsigned char#define SEND 0#define RECEIVE 1sbit KEY1 = P1^4;sbit KEY2 = P1^5;sbit LED1 = P1^0;sbit LED2 = P1^1;sbit SMG = P1^7;uchar flag_Serial = SEND;uchar Rx_Buf;uchar Smg_Buf;//0 1 2 3 4 5 6 7 8 9 a b c d e fuchar code Show[16]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x19,0x11,0xc1,0x63,0x85,0x61,0x71};void Serial_Init();void Serial_send();void Display();void Delay_1ms(uchar z);void Scan();/****************************************************/ //main function///****************************************************/ void main(){Serial_Init();while(1){switch(flag_Serial){case SEND:flag_Serial = RECEIVE;Serial_send();break;case RECEIVE:Display();break;}Scan();}}/****************************************************/ //serial initial///****************************************************/ void Serial_Init(){TMOD = 0X20; //work in mode 2PCON = 0X00;SCON = 0X50;TH1 = 0XFD; //BRUD 9600TL1 = 0XFD;TR1 = 1; //open interrupt 1ES = 1; //open the serialEA = 1; //open the key interruptflag_Serial = SEND;SMG = 0;}/****************************************************/ //serial interrupt function///****************************************************/ void Serial() interrupt 4 using 2{EA = 0;if(RI!=0&&flag_Serial==RECEIVE){RI = 0;Rx_Buf = SBUF;flag_Serial = SEND;}EA = 1;}/****************************************************/ //mcu send data to serial///****************************************************/ void Serial_send(){SBUF = Rx_Buf;while(TI==0);TI=0;}/****************************************************/ //display the data by SMG///****************************************************/ void Display(){P2 = Show[Rx_Buf];Delay_1ms(3);}/****************************************************/ //delay for z*1ms/****************************************************/ void Delay_1ms(uchar z){uchar i,j;for(i=z;i>0;i--)for(j=110;j>0;j--);}/****************************************************/ //scan the keys///****************************************************/ void Scan(){if(KEY1==0){Delay_1ms(10);if(KEY1==0){LED1 = ~LED1;Rx_Buf++;if(Rx_Buf==16)Rx_Buf = 0;Display();while(KEY1==0);}}if(KEY2==0){Delay_1ms(10);if(KEY2==0){LED2 = ~LED2;if(Rx_Buf==0)Rx_Buf = 15;elseRx_Buf--;Display();while(KEY2==0);}}}串口通信,按键加减提示音,(利用定时中断)快速加减提示音#include<reg52.h>#define uint unsigned int#define uchar unsigned char#define SEND 0#define RECEIVE 1#define NORMAL 0#define INCREASE 1#define DECREASE 2sbit KEY1 = P1^4;sbit KEY2 = P1^5;sbit LED1 = P1^0;sbit LED2 = P1^1;sbit SMG = P1^7;sbit SPEAKER = P1^6;uchar flag_Serial = SEND;uchar Rx_Buf;uchar count_2s;uchar flag_KS;//0 1 2 3 4 5 6 7 8 9 a b c d e fuchar code Show[16]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x19,0x11,0xc1,0x63,0x85,0x61,0x71};void Serial_Init();void Serial_send();void Display();void Delay_1ms(uchar z);void Scan();/****************************************************/ //main function///****************************************************/ void main(){Serial_Init();while(1){switch(flag_Serial){case SEND:flag_Serial = RECEIVE;Serial_send();break;case RECEIVE:Display();break;}Scan();}}/****************************************************/ //serial initial///****************************************************/ void Serial_Init(){TMOD = 0X21; //work in mode 2PCON = 0X00;SCON = 0X50;TH1 = 0XFD; //BRUD 9600TL1 = 0XFD;TR1 = 1; //open interrupt 1ES = 1; //open the serialTH0 = (65536-50000)/256;TL0 = (65536-50000)%256;ET0 = 1;TR0 = 0;EA = 1; //open the key interruptflag_Serial = SEND;SMG = 0;}/****************************************************/ //serial interrupt function///****************************************************/ void Serial() interrupt 4{EA = 0;if(RI!=0&&flag_Serial==RECEIVE){RI = 0;Rx_Buf = SBUF;flag_Serial = SEND;}EA = 1;}/****************************************************/ //interrupt zero function///****************************************************/ void Timer0() interrupt 1{TH0 = (65536-50000)/256;TL0 = (65536-50000)%256;count_2s++;if(count_2s==40) //50ms*40=2s{count_2s=0;if(KEY1==0)flag_KS = INCREASE;elseflag_KS = DECREASE;}}/****************************************************/ //mcu send data to serial///****************************************************/ void Serial_send(){SBUF = Rx_Buf;while(TI==0);TI=0;}/****************************************************/ //display the data by SMG///****************************************************/void Display(){P2 = Show[Rx_Buf];}/****************************************************/ //delay for z*1ms///****************************************************/ void Delay_1ms(uchar z){uchar i,j;for(i=z;i>0;i--)for(j=110;j>0;j--);}/****************************************************/ //scan the keys///****************************************************/ void Scan(){if(KEY1==0){Delay_1ms(10);if(KEY1==0){LED1 = 0;SPEAKER = 0;Delay_1ms(250);SPEAKER = 1;Delay_1ms(250);LED1 = 1;flag_Serial = SEND;Rx_Buf++;if(Rx_Buf==16)Rx_Buf = 0;Display();while(KEY1==0){TR0 = 1;ES = 0;if(flag_KS==INCREASE && count_2s==4){count_2s=0;Rx_Buf++;if(Rx_Buf==16)Rx_Buf = 0;SPEAKER = 0 ;LED1 = 0 ;Delay_1ms(200);SPEAKER = 1 ;LED1 = 1 ;Delay_1ms(200);Display();}}flag_KS = NORMAL;ES = 1;TR0 = 0;}}if(KEY2==0){Delay_1ms(10);if(KEY2==0){LED2 = 0;SPEAKER = 0;Delay_1ms(125);SPEAKER = 1;Delay_1ms(250);LED2 = 1;flag_Serial = SEND;if(Rx_Buf==0)Rx_Buf = 15;elseRx_Buf--;Display();while(KEY2==0){TR0 = 1;ES = 0;if(flag_KS==DECREASE && count_2s==4){count_2s=0;if(Rx_Buf==0)Rx_Buf = 15;elseRx_Buf--;SPEAKER = 0 ;LED2 = 0 ;Delay_1ms(200);SPEAKER = 1 ;LED2 = 1 ;Delay_1ms(200);Display();}}flag_KS = NORMAL;ES = 1;TR0 = 0;}}}。

基于89c52单片机的智能计算器程序

基于89c52单片机的智能计算器程序
Main.c
#include<reg52.h>
#include"lcd.h"
typedef unsigned char uint8;
typedef unsigned int uint16;
sbit led=P3^7;
sbit beep=P2^0;
uint8 key,num;
uint8 fuhao;//定义具体的那个符号,是加减还是乘除。
else
{
//led=1;
b=b*10+dat1[num];
}
}
else
{
flag=1;
fuhao=3;//带表乘号*
}
lcdwrd(0x30+dat1[num]);
}
P1=0xf7;//令第四行为0,判断哪一列按下
if(P1!=0xf7)
{
delay(1000);
if(P1!=0xf7)
{
key=P1&0xf0;
{
lcdwrd(0x30+c%10);//显示结果的最后一位在0x4f的位置
c=c/10;//取前面的结果数据
}
lcdwrd(0x3d); //显示等于号=
a=0;
b=0;
flag=0;
fuhao=0;//全部清除为0
}
if(fuhao==2) //减
{
lcdwrc(0x4f+0x80);
lcdwrc(0x04);//设置光标左移,屏幕不移动
void delay(uint16 i)
{
while(i--);
}
void lcdwrc(uint8 c)
{
LcdWriteCom(c);

数字时钟_89C52_单片机C语言程序

数字时钟_89C52_单片机C语言程序
/*列扫描控制 LED1位 2位 3位 4位 5位 6位 7位 8位*/
uchar MON[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
uchar A;
uchar BIN=0; /* 【BIN】作为倒计时开始的标志 */
TH0 = (65536 - 10000) / 256; /*给定计时器高位赋予 初值=15536/256*/
TL0 = (65536 - 10000) % 256; /*给定计时器低位赋予 初值=15536%256 */
ET0 = 1; /*打开定时器外部终断0允许 ET1是中断器1的开关*/
P2 = C[4];
Delay(1);
P0 = Code[Msec%10]; /*第五位的数字显示【分】的【个】位 */
P2 = C[5];
Delay(1);
Delay(1);
P0 = 0x40; /*第六位符号【-】的显示 */
P2 = C[6];
Delay(1);
P2 = C[2];
Delay(1);
if(x/50==0)
P0 = 0x40; /*第三位符号【-】的显示 */
else
P0 = 0x00;
P2 = C[3];
Delay(1);
P0 = Code[min/10]; /*第四位的数字的显示【分】的【十】位 */
uchar month=7;
uchar month2;
uchar day=19;
uchar set1 = 1; /* set1=1 是调节 时分秒 set1=2时时调节 年月日 set=3时事调节闹钟 */

电子设计-基于STC89C52RC单片机的简易计算器设计.docx

电子设计-基于STC89C52RC单片机的简易计算器设计.docx

电子设计实验名称:基于STC89C52RC单片机的简易计算器设计姓名:学号:指导老师:一、可行性研究■-二、方案述.....2.1、功能介■■■..3 (4)、设可彳亍性分析:1.2.1经济可行性由于只是实验性质的编程,所以在设计和开发都不需要过多的经费,但是系 统投入运行以后,硕件维护和损耗所造成的耗费是必须的,但是数目也不会很大。

基本功能 .......... 扩展功能 ..........2.2、总体设计方案…… 总体设计思路•- 方案论证与比较系统组成 ........... 三、详细设计 .............1. 各个模块设计…… 输入模块: 运算模块: 显示模块: 阀件电设计 2.键盘扫描•….单片机控制…LCD 1602 显硬件连接121213 14 153.元件的介绍 ........ STC89C52单片机组成 复位和复位电路…•…LCD 1602 显示5 ■5 •6器•……4.PCB 设计以及结果显示五、总结 ...... ....... 附录主要程序代码 .............19 222425所以经过初步分析,经济上基本上是可行的1.2.2技术可行性在技术方面,因为都学习了C语言,硕件课程设计等课程,对于开发语言C语言也有一定的掌控能力,应该能够完成相应的任务。

1.2.3运行可行性该成果简单易操作,非常容易使用。

1.2.4法律可行性由于我们需要完成的功能相对简单,没有太多涉及到很专业方面的内容,更没有计划将系统利用到商业用途,所以不存在侵权或者版权纠纷方面的问题。

125结论该系统的软硬件都比较容易理解和实现,所以,具有实现一计算器的可行性。

二、设计方案简述2.1功能概述系统基本功能:(1)由于设计的计算器要进行四则运算,为了得到较好的显示效果,经综合分析后,最后采用LCD显示数据和结果。

(2)采用键盘输入方式,键盘包括数字键(0〜9)、符号键(+、-、X、清除键(onV )和等号键(=),故只需要16个按键即口J,设计中采用集成的计算 键盘。

STC89C52+PT2313 C语言程序源代码

STC89C52+PT2313 C语言程序源代码
for(i=0;i<2;i++)
{
for(j=0;j<8;j++)
{
write_com(temp+j);
delay_ms(2);
sbit rw=P2^1;
sbit en=P2^2;
bit flag;
uint time;
static uchar long_press_count=0,vol=0,bass=7,treble=7;
static char left=0,right=0;
static uchar input_flag=0;
/* 0x88= 10001000 ,由tone[]与0x88求和来计算bass&treble增益
0x00 0000 -14dB
0x01 0001 -12dB
0x02 0010 -10dB
0x03 0011 -8dB
0x04 0100 -6dB
{
uint x,y;
for(x=i;i>0;i--)
for(y=123;y>0;y--);
}
//开始信号
void start()
{
sda=1;
delay();
scl=1;
void write_7313(uchar dat)
{
start();
write_i2c(SC7313_ADD);
while(!respons());
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char

c单片机C语言编写的PWM程序

c单片机C语言编写的PWM程序

89c51单片机C语言编写的PWM程序PWM, 单片机, C语言, 程序, 编写分享到:新浪微博 QQ空间开心网人人网说明:本程序使用STC89C52RC单片机,22.1184MHz晶振,要使用本程序需要自己修改,我是用来控制直流电机的,外接了L298驱动电路,有问题或意见请回复,谢谢^_^#include "reg52.H"#include "MyType.h"//=============L298端口定义===============sbit ENA = P3^6;?//左轮驱动使能sbit IN1 = P0^3;?//左轮黑线(-)sbit IN2 = P0^4;?//左轮红线(+)sbit IN3 = P0^5;?//右轮红线(-)sbit IN4 = P0^6;?//右轮黑线(+)sbit ENB = P3^7;?//右轮驱动使能//=============PWM================#define PWM_COUST 100?//PWM细分等份uchar MOTO_speed1;??//左边电机转速uchar MOTO_speed2; ??//右边电机转速uchar PWM_abs1;???//左边电机取绝对值后占空比uchar PWM_abs2;???//左边电机取绝对值后占空比?uchar PWM_var1=20;??//左边电机直走速度(不同的电机,此参数不同)uchar PWM_var2=20;??//右边电机直走速度uchar PWMAnd = 0;??//PWM自增变量/****************************************************************** 名称:motor(char speed1,char speed2);功能:同时调节电机的转速参数:speed1:电机1的PWM值;speed2:电机2的PWM值?? speed>0.正转;speed<0.反转(-100~100)调用:extern int abs(int val); 取绝对值返回:/******************************************************************/ void motor(char speed1,char speed2){??//==============左边电机=============?if (speed1>0)??{??IN1 =0;IN2 =1;//正转??}???else if (speed1<0)??{??IN1 =1;IN2 =0;//反转??}?//==============右边电机=============?if (speed2>0)??{??IN3 =1;IN4 =0;//正转??}?else if (speed2<0)??{??IN3 =0;IN4 =1;//反转??}}/******************************************************************名称:motor_PWM();功能:PWM占空比输出参数:无调用:无返回:无/******************************************************************/void motor_PWM (){?uchar PWM_abs1;?uchar PWM_abs2;?PWM_abs1=MOTO_speed1;?PWM_abs2=MOTO_speed2;?if (PWM_abs1>PWMAnd) ENA=1;??? //左边电机占空比输出??else ENA=0;?if (PWM_abs2>PWMAnd) ENB=1;??? //右边电机占空比输出??else ENB=0;?if (PWMAnd>=PWM_COUST) PWMAnd=0;? //PWM计数清零??else PWMAnd+=1;}???/******************************************************************名称:void TIME_Init ();功能:定时器初始化指令:调用:无返回:无/******************************************************************/void TIME_Init ()?{//=========定时器T2初始化 PWM==================?T2CON = 0x00;? ?T2MOD = 0x00;? ?RCAP2H = 0xff;?//定时0.1ms? ?RCAP2L = 0x47;? ?TH2 = 0xff;? ?TL2 = 0x47;?ET2 = 1;??//定时器2中断开?TR2 = 1;??//PWM定时器关,PWM周期为10ms?}/******************************************************************名称:void PWM_Time2 () interrupt 5功能:T2中断,PWM控制参数:调用:motor_PWM();//PWM占空比输出返回:/******************************************************************/?void PWM_Time2 () interrupt 5{? ?TR2 = 0;?TF2 = 0;?ET2 = 0;?//定时器0中断禁止?motor_PWM();//PWM占空比输出?ET2 = 1;?//定时中断0开启?TR2 = 1;}main(){TIME_Init ()?;motor(50,50);//左右电机的转速都是50}。

AT89C52单片机简易计算器

AT89C52单片机简易计算器
lnumnow=lnumnow*10+2;
flag=2;
}
if(P3_4==0)//0
{
if(flag==1)
{
lnumbefore=lnumnow;lnumnow=0;digit=0;
}
if(flag==4)
{
lnumnow=0;
}
digit++;
lnumnow=lnumnow*10;
flag=2;
flag=2;
}
if(P3_4==0&&flag!=1)//=
{
switch(signal)
{
case '+':
lnumnow=lnumnow+lnumbefore;
lnumbefore=lnumnow;
break;
case '-':
lnumnow=lnumbefore-lnumnow;
lnumbefore=lnumnow;
break;
}
signal=0;
if(P3_7==0)//除
{
signal='/';
flag=1;
digit=0;
}
if(P3_6==0)//乘
{
flag=1;
signal='*';
digit=0;
}
if(P3_5==0)//减
{
flag=1;
signal='-';
digit=0;
}
if(P3_4==0)//加
lnumnow=lnumnow*10+4;
flag=2;
}
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

STC89c52单片机计算器C语言程序STC89C52单片机计算器C语言程序下面是STC89C52单片机计算器的C语言程序,适用于P2位选P0段选时钟12MHZ。

程序代码如下:includedefine uchar unsigned chardefine uint unsigned intuchar Led[17] = {0x3f。

0x06.0x5b。

0x4f。

0x66.0x6d。

0x7d。

0x07.0x7f。

0x6f。

0x77.0x7c。

0x39.0x5e。

0x79.0x71.0x00};long float Number[]={0,0,0,0};uchar A[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};long int D[] = {0,0,0,0,0,0,0,0};uchar code C[] = {0x0.0xFE。

0xFD。

0xFB。

0xF7.0xEF。

0xDF。

0xBF。

0x7F};uchar k=16;uchar b;long float Out_put;uchar e=0;uchar g=0;uchar L=0;uchar g1=0;uchar g2=0;uchar g3=0;uchar g4=0;char j=-1;uchar m=0;uchar n=0;uchar x=0;程序中包含了头文件和宏定义,以及数码管段选、数码管显示位控制寄存器、数码管显示内容寄存器、数码管位选、按键控制变量等各种变量。

其中,Led数组存储了数码管的段选值,Number数组存储了数字,A数组存储了数码管的位选值,D数组存储了数码管的显示内容,C数组存储了数码管的位选值,k、b、Out_put、e、g、L、g1、g2、g3、g4、j、m、n、x 等变量用于按键控制和运算。

代码中没有明显的格式错误,可以直接使用。

下面是已经修改过的文章:uchar xo = 0./*控制开始计数小数点的变量*/long int result;void Delay(uint o) {uint i。

j;for(i = 0.i < o。

i++) {for(j = 0.j < 121.j++) {void show(long float Out_put) { uchar r;uchar k;long int q。

p;uchar s = 0;uchar i;long int temp;temp = Out_put;if((Out_put - temp)。

= 0) { result = Out_put * ;r = 4;else {result = Out_put;r = 0;p = result;if(m == 1) {if(result < 0) { result = -result;p = result;q = result;for(i = 1.i <= 8.i++) { q = q / 10;if(q == 0) {k = i;i = 9;P0 = 0x40;P2 = C[8 - k]; Delay(1);负号的显示P0 = 0x80;P2 = C[r];Delay(1);P0 = 0x00;result = p;P0 = Led[result % 10];P2 = C[8];result = result / 10;Delay(1);if((result % 10 == 0) && (result % 100 == 0) && (result % 1000 == 0) && (result % == 0) && (result % == 0) && (result % xxxxxxx == 0)) {P0 = 0x00;else {P0 = Led[result % 10];P2 = C[7];result = result / 10;Delay(1);if((result % 10 == 0) && (result % 100 == 0) && (result % 1000 == 0) && (result % == 0) && (result % == 0)) { P0 = 0x00;文章已经没有明显的格式错误和段落问题。

稍作修改,将变量名和注释变成英文,可以提高代码的可读性。

void display_result() {显示结果if (result == 0) {P0 = 0x00;else {P0 = Led[result % 10];P2 = C[6];result = result / 10;Delay(1);if ((result % 10 == 0) && (result % 100 == 0) && (result % 1000 == 0) && (result % == 0)) {P0 = 0x00;else {P0 = Led[result % 10];P2 = C[5];result = result / 10;Delay(1);if ((result % 10 == 0) && (result % 100 == 0) && (result % 1000 == 0)) {P0 = 0x00;else {P0 = Led[result % 10];P2 = C[4];result = result / 10;Delay(1);if ((result % 10 == 0) && (result % 100 == 0)) {P0 = 0x00;else {P0 = Led[result % 10];P2 = C[3];result = result / 10;Delay(1);if (result % 10 == 0) {P0 = 0x00;else {P0 = Led[result % 10]; P2 = C[2];result = result / 10; Delay(1);if (result == 0) {P0 = 0x00;else {P0 = Led[result % 10]; P2 = C[1];result = result / 10; Delay(1);void input_decimal() { 输入小数加小数点uchar i;if (k。

= 0 && k <= 9) { switch (e) {case 8:D[7] = D[6];A[7] = A[6];case 7:D[6] = D[5];A[6] = A[5];case 6:D[5] = D[4];A[5] = A[4];case 5:D[4] = D[3];A[4] = A[3];case 4:D[3] = D[2];A[3] = A[2];case 3:D[2] = D[1];A[2] = A[1];case 2:D[1] = D[0];A[1] = A[0];case 1:if (n == 0) {D[0] = k;A[0] = Led[k];if (xo == 1) {x++;if (n == 1) {A[0] = Led[k] | 0x80; xo = 1;n = 0;The following code is used to XXX。

The code includes a switch statement that checks the value of the variable k。

which represents the n to be performed。

If k is een 11 and 15 and b is equal to 1.the switch XXX on the n being performed。

The code also includes a n called Key_scan()。

which scans the keyboard for input。

The n saves the state of the keyboard when a key is pressed and then determines which key was pressed based on the saved state。

If a number key is pressed。

the n calls the In_put() n to input the number.XXX of the code。

some minor changes have been made。

The formatting errors have been corrected。

and some paragraphs that XXX.The code includes a switch XXX the value of the variable k。

which represents the n to be performed。

If k is een 11 and 15 and b is equal to 1.the switch XXX.The code also includes a n called Key_scan()。

which scans the keyboard for input。

The n saves the state of the keyboardwhen a key is pressed and then determines which key was pressed based on the saved state。

If a number key is pressed。

the n calls the In_put() n to input the number.Overall。

the code is XXX and to input numbers from the keyboard。

The code could be improved by adding more comments to explain the purpose of each n and variable。

nally。

the code could be XXX.以下是格式错误已经删除后的文章:在程序设计中,数字和字符的转换是一个很常见的任务。

在C语言中,可以通过ASCII码表将字符转换为对应的数字。

相关文档
最新文档