EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
用stm32f03c8t6 单片机做的一个简易计算器,用4×4矩阵键盘输入,LCD1602显示。下面是对我计算器的介绍,附件中还可以下载源程序代码码。我的简易计算器是搭建在面包板上面的,下面这是实物图和仿真图。. `8 s1 j, C( p$ {% Z4 a
6 E4 @; p5 Y, W ?. _7 [1 {3 g0 S% Y+ S, Y# o
- a, t9 _/ Z- }; W 该计算器可以实现连续加减运算图:
3 s5 P0 k; L' V; S7 a8 v% z% Q' K
6 q# n& O6 |4 R5 f' R+ T' E9 o- |7 x3 O& p
4 L) a% h4 J) T
较大数字或者较小数字可以用科学计数法显示 ![]()
2 i# D. K+ H8 F4 @# u / |4 d" A4 @/ Z' h# B! z
当用除法运算时,能够保留三位小数字 * Y! D" Q1 ?# G( P8 s7 f' \
2 W/ F _. W: K! t
7 D8 O& H3 L1 M0 B
另外,在运算时还可以通过串口观察数据变化 S1 R; z) _/ a
下面是部分源码: #include "stm32f10x.h" #include "delay.h" #include "keyscan.h" #include "LCD1602.h" #include "usart.h" #include "math.h" u8 num,flag; double r,o; long long a,b,x,y,z,sum,k; int e,f,g,h,i,t,len,w,l; int s,m,w,j,q,d,n,c=0;
- ~6 d" p/ W+ T2 Tint main() { LCD_init(); uart_init(9600);
' P: \$ H/ J* V/ i: q while(1) { num=keyscan(); a=num; if(a>=0&&a<=9&&s!=2&&flag!=0) { if(a!=0||n!=0) { LCD_write_data((u8)a+0x30); if(n==0) { b=a; } else { b=sum*10; sum=a; } sum=sum+b; /////////////////////////////// if(q==0&&j==0) { x=sum; printf("x=%lld ",x); d=1; m=0; } 7 A( {8 a2 ~# c$ J2 I
if(q==1&&j==1) { x=-sum; printf("x=%lld ",x); d=1; m=0; } ) |9 N* |/ ?* U; k+ z, i' t9 }
///////////////////////////////// ' [: U/ U- Q2 O+ b e3 _! D0 l# G. B
if(q==1&&(j==2||j==0)) { y=sum; printf("y=%lld ",y); d=2; } , l# _% b, s/ L% B' g
' D- k& G6 D2 S) \9 I2 h///////////////////////////////// n++; w++; delay_ms(100); } } if(a==10&n!=0&&m!=1&&flag!=0)//+号 { if(c>=1) { q=1; j=0; x=z; 4 M! y# ^. E+ _9 f
} //LCD_write_data('+'); LCD_write_data(0x2b); printf(" + "); j=0; n=0; q=1; flag=1; b=0; sum=0; c++; w++;
, A y& y8 J% j( l7 I delay_ms(100); } if(a==11&&m!=1&&flag!=0) { //LCD_write_data('-'); LCD_write_data(0x2d);//'-'号 printf(" - "); if(c>=1) { q=1; j=0; x=z;
. Q0 } a1 a! k# R/ w6 q) m }
( I. D' V# h2 V6 v if(d==0) { j=1; } if(d==1) { j=2; } $ A P7 y1 B/ u" L, U
n=0; q=1; flag=2; b=0; sum=0; m=-m; w++; c++; delay_ms(100); }
; b- c0 d- M, D0 i if(a==12&n!=0&&m!=1&&flag!=0) { LCD_write_data('*');//×号 //LCD_write_data(0x2a);//×号 if(c>=1) { q=1; j=0; x=z; & F( O) U4 Z$ C; m
} printf(" * "); j=0; n=0; q=1; flag=3; b=0; sum=0; m=-m; w++; c++; delay_ms(100); } if(a==13&n!=0&&m!=1&&flag!=0) { // LCD_write_data('');//除号 LCD_write_data(0xfd);//÷号 if(c>=1) { q=1; j=0; x=z; 8 _4 ^2 M$ g# x/ \
} printf("/");
4 [: Z& H0 w* Z2 u( E0 n |