這是我用正點原子開發板戰艦3做的一個計算器
51hei圖片20200717010620.jpg (239.09 KB, 下載次數: 85)
下載附件
2020-7-17 01:06 上傳
主要代碼如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "24cxx.h"
- #include "w25qxx.h"
- #include "touch.h"
-
- int aa = 0;
- //清空屏幕并在右上角顯示"RST"
- void Load_Drow_Dialog(void)
- {
- LCD_Clear(WHITE); //清屏
- POINT_COLOR=BLUE; //設置字體為藍色
- LCD_ShowString(lcddev.width-24,0,200,16,16,"RST");//顯示清屏區域
- POINT_COLOR=RED; //設置畫筆藍色
- }
- ////////////////////////////////////////////////////////////////////////////////
- //電容觸摸屏專有部分
- //畫水平線
- //x0,y0:坐標
- //len:線長度
- //color:顏色
- void gui_draw_hline(u16 x0,u16 y0,u16 len,u16 color)
- {
- if(len==0)return;
- LCD_Fill(x0,y0,x0+len-1,y0,color);
- }
- //畫實心圓
- //x0,y0:坐標
- //r:半徑
- //color:顏色
- void gui_fill_circle(u16 x0,u16 y0,u16 r,u16 color)
- {
- u32 i;
- u32 imax = ((u32)r*707)/1000+1;
- u32 sqmax = (u32)r*(u32)r+(u32)r/2;
- u32 x=r;
- gui_draw_hline(x0-r,y0,2*r,color);
- for (i=1;i<=imax;i++)
- {
- if ((i*i+x*x)>sqmax)// draw lines from outside
- {
- if (x>imax)
- {
- gui_draw_hline (x0-i+1,y0+x,2*(i-1),color);
- gui_draw_hline (x0-i+1,y0-x,2*(i-1),color);
- }
- x--;
- }
- // draw lines from inside (center)
- gui_draw_hline(x0-x,y0+i,2*x,color);
- gui_draw_hline(x0-x,y0-i,2*x,color);
- }
- }
- //兩個數之差的絕對值
- //x1,x2:需取差值的兩個數
- //返回值:|x1-x2|
- u16 my_abs(u16 x1,u16 x2)
- {
- if(x1>x2)return x1-x2;
- else return x2-x1;
- }
- //畫一條粗線
- //(x1,y1),(x2,y2):線條的起始坐標
- //size:線條的粗細程度
- //color:線條的顏色
- void lcd_draw_bline(u16 x1, u16 y1, u16 x2, u16 y2,u8 size,u16 color)
- {
- u16 t;
- int xerr=0,yerr=0,delta_x,delta_y,distance;
- int incx,incy,uRow,uCol;
- if(x1<size|| x2<size||y1<size|| y2<size)return;
- delta_x=x2-x1; //計算坐標增量
- delta_y=y2-y1;
- uRow=x1;
- uCol=y1;
- if(delta_x>0)incx=1; //設置單步方向
- else if(delta_x==0)incx=0;//垂直線
- else {incx=-1;delta_x=-delta_x;}
- if(delta_y>0)incy=1;
- else if(delta_y==0)incy=0;//水平線
- else{incy=-1;delta_y=-delta_y;}
- if( delta_x>delta_y)distance=delta_x; //選取基本增量坐標軸
- else distance=delta_y;
- for(t=0;t<=distance+1;t++ )//畫線輸出
- {
- gui_fill_circle(uRow,uCol,size,color);//畫點
- xerr+=delta_x ;
- yerr+=delta_y ;
- if(xerr>distance)
- {
- xerr-=distance;
- uRow+=incx;
- }
- if(yerr>distance)
- {
- yerr-=distance;
- uCol+=incy;
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////////////
- //5個觸控點的顏色
- const u16 POINT_COLOR_TBL[CT_MAX_TOUCH]={RED,GREEN,BLUE,BROWN,GRED};
- //電阻觸摸屏測試函數
- void rtp_test(void)
- {
- u8 key;
- u8 i=0;
- while(1)
- {
- key=KEY_Scan(0);
- tp_dev.scan(0);
- if(tp_dev.sta&TP_PRES_DOWN) //觸摸屏被按下
- {
- if(tp_dev.x[0]<lcddev.width&&tp_dev.y[0]<lcddev.height)
- {
- if(tp_dev.x[0]>(lcddev.width-24)&&tp_dev.y[0]<16)Load_Drow_Dialog();//清除
- else TP_Draw_Big_Point(tp_dev.x[0],tp_dev.y[0],RED); //畫圖
- }
- }else delay_ms(10); //沒有按鍵按下的時候
- if(key==KEY0_PRES) //KEY0按下,則執行校準程序
- {
- LCD_Clear(WHITE);//清屏
- TP_Adjust(); //屏幕校準
- Load_Drow_Dialog();
- }
- i++;
- if(i%20==0)LED0=!LED0;
- }
- }
- //電容觸摸屏測試函數
- void ctp_test(void)
- {
- u8 t=0;
- u8 i=0;
- u16 lastpos[5][2]; //記錄最后一次的數據
- while(1)
- {
- tp_dev.scan(0);
- for(t=0;t<CT_MAX_TOUCH;t++)
- {
- if((tp_dev.sta)&(1<<t))
- {
- if(tp_dev.x[t]<lcddev.width&&tp_dev.y[t]<lcddev.height)
- {
- if(lastpos[t][0]==0XFFFF)
- {
- lastpos[t][0] = tp_dev.x[t];
- lastpos[t][1] = tp_dev.y[t];
- }
- lcd_draw_bline(lastpos[t][0],lastpos[t][1],tp_dev.x[t],tp_dev.y[t],2,POINT_COLOR_TBL[t]);//畫線
- lastpos[t][0]=tp_dev.x[t];
- lastpos[t][1]=tp_dev.y[t];
- if(tp_dev.x[t]>(lcddev.width-24)&&tp_dev.y[t]<16)
- {
- Load_Drow_Dialog();//清除
- }
- }
- }else lastpos[t][0]=0XFFFF;
- }
-
- delay_ms(5);i++;
- if(i%20==0)LED0=!LED0;
- }
- }
- void jiemian1(void)
- {
- POINT_COLOR=GRAY;
- LCD_DrawRectangle(0,320,240,160);
- LCD_DrawRectangle(0,320,240,200);
- LCD_DrawRectangle(0,320,240,240);
- LCD_DrawRectangle(0,320,240,280);
- LCD_DrawRectangle(0,160,240,120);
-
- LCD_DrawRectangle(60,320,120,160);
- LCD_DrawRectangle(0,280,60, 160);
- LCD_DrawRectangle(0,280,120,160);
- LCD_DrawRectangle(0,320,180,160);
- LCD_DrawRectangle(60,160,180,120);
- LCD_DrawRectangle(60,160,120,120);
-
-
-
- POINT_COLOR=BLACK;
- LCD_ShowString(25,170,200,18,24,"7");
- LCD_ShowString(85,170,200,18,24,"8");
- LCD_ShowString(145,170,200,18,24,"9");
-
- LCD_ShowString(25,210,200,18,24,"4");
- LCD_ShowString(85,210,200,18,24,"5");
- LCD_ShowString(145,210,200,18,24,"6");
- LCD_ShowString(25,250,200,18,24,"1");
- LCD_ShowString(85,250,200,18,24,"2");
- LCD_ShowString(145,250,200,18,24,"3");
- LCD_ShowString(85,290,200,18,24,"0");
-
- LCD_ShowString(205,170,200,18,24,"x");
-
- LCD_ShowString(130,290,200,18,24,"+/-");
- LCD_ShowString(205,201,200,18,24,"_");
- LCD_ShowString(205,250,200,18,24,"+");
- POINT_COLOR=BRRED;
- LCD_ShowString(205,290,200,18,24,"=");
- POINT_COLOR=RED;
- LCD_ShowString(25,130,200,18,24,"C");
- POINT_COLOR=BRRED;
- LCD_ShowString(10,294,200,18,16,"[]/[]");
-
- POINT_COLOR=BLACK;
- LCD_ShowString(145,125,200,18,24,".");
- LCD_ShowString(205,130,200,18,24,"/");
- LCD_ShowString(66,135,200,18,16,"Delete");
- }
- void jiemian2(void)
- {
- POINT_COLOR=GRAY;
- LCD_DrawRectangle(0,320,48,75);
- LCD_DrawRectangle(48,320,96,75);
- LCD_DrawRectangle(96,320,144,75);
- LCD_DrawRectangle(144,320,192,75);
- LCD_DrawRectangle(192,320,240,75);
-
- LCD_DrawRectangle(0,110,240,145);
- LCD_DrawRectangle(0,145,240,180);
- LCD_DrawRectangle(0,180,240,215);
- LCD_DrawRectangle(0,215,240,250);
- LCD_DrawRectangle(0,250,240,285);
- LCD_DrawRectangle(0,285,240,320);
-
- POINT_COLOR=BLACK;
- LCD_ShowString(210,291,200,18,24,"=");
- LCD_ShowString(210,256,200,18,24,"+");
- LCD_ShowString(210,221,200,18,24,"-");
- LCD_ShowString(210,183,200,18,24,"x");
- LCD_ShowString(210,155,200,18,24,"/");
- POINT_COLOR=GRAY;
- LCD_ShowString(214,117,200,18,24,")");
- LCD_ShowString(203,85,200,18,16,"tan");
-
- POINT_COLOR=BLACK;
- LCD_ShowString(152,291,200,18,24,"+/-");
- LCD_ShowString(162,256,200,18,24,"3");
- LCD_ShowString(162,221,200,18,24,"6");
- LCD_ShowString(162,185,200,18,24,"9");
- LCD_ShowString(164,146,200,18,24,".");
- POINT_COLOR=GRAY;
- LCD_ShowString(158,117,200,18,24,"(");
- LCD_ShowString(158,85,200,18,16,"cos");
-
- POINT_COLOR=BLACK;
- LCD_ShowString(114,291,200,18,24,"0");
- LCD_ShowString(114,256,200,18,24,"2");
- LCD_ShowString(114,221,200,18,24,"5");
- LCD_ShowString(114,185,200,18,24,"8");
- LCD_ShowString(112,155,200,18,16,"Del");
- POINT_COLOR=GRAY;
- LCD_ShowString(111,120,200,18,16,"ln");
- LCD_ShowString(110,85,200,18,16,"sin");
-
- POINT_COLOR=BLACK;
- LCD_ShowString(66,291,200,18,24,"e");
- LCD_ShowString(66,256,200,18,24,"1");
- LCD_ShowString(66,221,200,18,24,"4");
- LCD_ShowString(66,185,200,18,24,"7");
- POINT_COLOR=BRRED;
- LCD_ShowString(66,150,200,18,24,"C");
- POINT_COLOR=GRAY;
- LCD_ShowString(66,120,200,18,16,"lg");
- LCD_ShowString(64,85,200,18,16,"deg");
-
- POINT_COLOR=BRRED;
- LCD_ShowString(5,295,200,18,16,"[]/[]");
- POINT_COLOR=GRAY;
- LCD_ShowString(18,256,200,18,24,"@");
- LCD_ShowString(13,225,200,18,16,"1/X");
- LCD_ShowString(18,185,200,18,24,"x!");
- LCD_ShowString(18,150,200,18,24,"x");
- LCD_ShowString(30,146,200,18,16,"y");
- LCD_ShowString(18,120,200,18,24,"x");
- LCD_ShowString(27,117,200,18,12,"1/2");
- LCD_ShowString(18,85,200,18,16,"2nd");
- POINT_COLOR=BLACK;
- }
- int main(void)
- {
- int qq=0;
- int i=0;
- int j=0;
- int key=0;
- int num=0;
- int num1=0;
- int num2=0;
- int flag=0;
- int F=0;
- int and=0;
- int time=0;
- int minus=0;
- int division=0;
- int quyu = 0;
- int jiecheng=0;
- int cifang=0;
- int num3=0;
- int e = 0;
- u8 *fuhao;
- delay_init(); //延時函數初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設置中斷優先級分組為組2:2位搶占優先級,2位響應優先級
- uart_init(115200); //串口初始化為115200
-
- LED_Init(); //LED端口初始化
- LCD_Init();
- KEY_Init();
- tp_dev.init();
-
- while(1)
- {
- if(aa == 1)
- {
- jiemian2();
- if(key==22)
- {
- LCD_ShowxNum(80,50,num1,12,24,1);
- F = 0;
- qq=0;
- }
- else
- {
- if(num1==0 && num2==0)
- {
- LCD_ShowxNum(80,50,num1,12,24,1);
- }
- else
- {
- if(qq==1)
- {
- LCD_ShowString(40,50,200,18,24,"+");
- }
- if(qq==2)
- {
- LCD_ShowString(40,50,200,18,24,"*");
- }
- if(qq==3)
- {
- LCD_ShowString(40,30,200,18,24,"_");
- }
- if(qq==4)
- {
- LCD_ShowString(40,50,200,18,24,".");
- LCD_ShowString(38,40,200,18,24,"_");
- LCD_ShowString(40,38,200,18,24,".");
- }
- if(qq==6)
- {
- LCD_ShowString(40,50,200,18,24,"^");
- }
- if(F==1)
- {
- //LCD_ShowString(40,80,200,18,24,"_");
- if(flag)
- {
- LCD_ShowxNum(80,30,num2,12,24,1);
- LCD_ShowxNum(80,50,num1,12,24,1);
- if(num2/10<1)
- {
- if(num2==0)LCD_ShowString(195,40,200,18,24,"_");
- else
- {
- LCD_ShowString(195,20,200,18,24,"_");
- }
- }
- else if(num2/10<10)
- {
- LCD_ShowString(183,20,200,18,24,"_");
- }
- else if(num2/10<100)
- {
- LCD_ShowString(172,20,200,18,24,"_");
- }
- else if(num2/10<1000)
- {
- LCD_ShowString(161,20,200,18,24,"_");
- }
- else if(num2/10<10000)
- {
- LCD_ShowString(150,20,200,18,24,"_");
- }
- else if(num2/10<100000)
- {
- LCD_ShowString(139,20,200,18,24,"_");
- }
- else if(num2/10<1000000)
- {
- LCD_ShowString(128,20,200,18,24,"_");
- }
- else if(num2/10<10000000)
- {
- LCD_ShowString(117,20,200,18,24,"_");
- }
- else LCD_ShowString(103,20,200,18,24,"_");
- }
- else
- {
- LCD_ShowxNum(80,50,num1,12,24,1);
- if(num1==0)
- {
- ;
- }
- else if(num1/10<1)
- {
- LCD_ShowString(195,40,200,18,24,"_");
- }
- else if(num1/10<10)
- {
- LCD_ShowString(183,40,200,18,24,"_");
- }
- else if(num1/10<100)
- {
- LCD_ShowString(172,40,200,18,24,"_");
- }
- else if(num1/10<1000)
- {
- LCD_ShowString(161,40,200,18,24,"_");
- }
- else if(num1/10<10000)
- {
- LCD_ShowString(150,40,200,18,24,"_");
- }
- else if(num1/10<100000)
- {
- LCD_ShowString(139,40,200,18,24,"_");
- }
- else if(num1/10<1000000)
- {
- LCD_ShowString(128,40,200,18,24,"_");
- }
- else if(num1/10<10000000)
- {
- LCD_ShowString(117,40,200,18,24,"_");
- }
- else LCD_ShowString(103,40,200,18,24,"_");
-
- }
- }
- else
- {
- if(flag)
- {
- LCD_ShowxNum(80,30,num2,12,24,1);
- LCD_ShowxNum(80,50,num1,12,24,1);
- }
- else
- LCD_ShowxNum(80,50,num1,12,24,1);
- }
- }
- }
- tp_dev.scan(0);
- if(tp_dev.sta&TP_PRES_DOWN) //觸摸屏被按下
- {
- if(tp_dev.x[0]<lcddev.width&&tp_dev.y[0]<lcddev.height)
- {
- for(i=0;i<7;i++)
- {
- for(j=0;j<5;j++)
- {
- if(tp_dev.x[0]>(j*48) && tp_dev.x[0]<(j*48+48) && tp_dev.y[0]>(320-(35*i+35)) && tp_dev.y[0]<(320-35*i))
- {
- key=j+i*5+1;
- if(key == 1)
- {aa=0;LCD_Clear(WHITE);delay_ms(100);}
- delay_ms(100);
- LCD_Fill(0,20,240,74,WHITE);
- GPIO_SetBits(GPIOB,GPIO_Pin_8);
- delay_ms(100);
- GPIO_ResetBits(GPIOB,GPIO_Pin_8);
-
- }
- }
- }
- }
- }else delay_ms(50);
- if(key == 2) num=e;
- else if(key == 3) num =0;
- else if(key == 4) fuhao ="+/-";
- else if(key == 5) fuhao ="=";
- else if(key == 6) ;
- else if(key == 7) num=1;
- else if(key == 8) num=2;
- else if(key == 9) num=3;
- else if(key == 10) fuhao="+";
- else if(key == 11) fuhao="1/X";
- else if(key == 12) num=4;
- else if(key == 13) num=5;
- else if(key == 14) num=6;
- else if(key == 15) fuhao="-";
- else if(key == 16) fuhao="X!";
- else if(key == 17) num=7;
- else if(key == 18) num=8;
- else if(key == 19) num=9;
- else if(key == 20) fuhao="*";
- else if(key == 21) fuhao="X^y";
- else if(key == 22) fuhao="C";
- else if(key == 23) fuhao="Del";
- else if(key == 24) fuhao=".";
- else if(key == 25) fuhao="/";
- switch (key)
- {
- case 22:num1=0;num2=0;F=0;break;
- case 23:num1=num1/10;break;
- case 10: num2=num1;num1=0;flag=1;and=1;qq=1;break;
- case 20:num2=num1;num1=0;flag=1;time=1;qq=2;break;
- case 15:num2=num1;num1=0;flag=1;minus=1;qq=3;break;
- case 25:num2=num1;num1=0;flag=1;division=1;qq=4;break;
- case 4:quyu=1;break;
- case 16:num2=1;num1=num1;jiecheng=1;qq=5;break;
- case 21:num2=num1;num3=1;num1=0;flag=1;cifang=1;qq=6;break;
- case 5:
- if(flag)
- {
- qq=0;
- if(and)
- {
- if(F==1)
- {
- if(num1>num2)
- {
- num1-=num2;
- F=0;
- }
- else if(num1 == num2)
- {
- num1=0;
- F=0;
- }
- else
- {
- num1=num2-num1;
- F=1;
- }
- }
- else
- {
- F=0;
- num1+=num2;
- }
- flag=0;
- and = 0;
-
- }
- else if(time)
- {
- num1=num1*num2;flag=0;
- time = 0;
-
- }
- else if(division)
- {
- if(num1>num2)
- {
- num1=0;
- }
- else if(num1==num2)
- {
- num1=1;
- }
- else
- {
- num1=num2/num1;
- }
- flag=0;
- division = 0;
- }
- else if(minus)
- {
- if(F==1)
- {
- num1=num1+num2;
- }
-
- else
- {
- if(num2>num1)
- {
- num1=num2-num1;
- F = 0;
- }
- else if(num2==num1)
- {
- num1=0;
- F = 0;
- }
- else
- {
- if(num2<num1)
- {
- num1=num1-num2;
- F = 1;
- }
- }
- }
- flag=0;
- minus = 0;
-
- }
- else if(cifang)
- {
- if(F==1)
- {
- if(num1==0)
- {
- num3=1;
- F=0;
- }
- else if(num1%2==0)
- {
- for(i=num1;i>0;i--)
- {
- num3=num3*num2;
- }
- F=0;
- }
- else
- {
- for(i=num1;i>0;i--)
- {
- num3=num3*num2;
- }
- }
- num1=num3;
- num3=0;
- num2=0;
- cifang=0;
- flag=0;
- }
- else
- {
-
- if(num1==0)
- {
- num3=1;
- }
- else
- {
- for(i=num1;i>0;i--)
- {
- num3=num3*num2;
- }
- }
- num1=num3;
- num3=0;
- num2=0;
- cifang=0;
- flag=0;
- }
-
- }
-
-
- }
- break;
- }
- if(jiecheng)
- {
- if(num1<24)
- {
- for(i=num1;i>0;i--)
- {
- num2=num2*num1;
- num1--;
- }
- num1=num2;
- num2=0;
- }
- jiecheng=0;
- }
- if(quyu)
- {
- F=!F;
- quyu=0;
- }
- if(num1>999999999)
- num1=0;
- key = 0;
- if(num1<100000000)
- {
- if(num == 0)
- {
- num1 = num1*10;
- num = -1;
- }
- if(num>0 && num<10)
- {
- num1 = num1*10+num;
- num = -1;
- }
- }
- }
- else
- {
- jiemian1();
- if(key==17)
- {
- LCD_ShowxNum(80,90,num1,12,24,1);
- F = 0;
- qq=0;
- }
- else
- {
- if(num1==0 && num2==0)
- {
- LCD_ShowxNum(80,90,num1,12,24,1);
- }
- else
- {
- if(qq==1)
- {
- LCD_ShowString(40,90,200,18,24,"+");
- }
- if(qq==2)
- {
- LCD_ShowString(40,90,200,18,24,"*");
- }
- if(qq==3)
- {
- LCD_ShowString(40,80,200,18,24,"_");
- }
- if(qq==4)
- {
- LCD_ShowString(40,90,200,18,24,".");
- LCD_ShowString(38,80,200,18,24,"_");
- LCD_ShowString(40,78,200,18,24,".");
- }
- if(F==1)
- {
- //LCD_ShowString(40,80,200,18,24,"_");
- if(flag)
- {
- LCD_ShowxNum(80,70,num2,12,24,1);
- LCD_ShowxNum(80,90,num1,12,24,1);
- if(num2/10<1)
- {
- if(num2==0)LCD_ShowString(195,80,200,18,24,"_");
- else
- {
- LCD_ShowString(195,60,200,18,24,"_");
- }
- }
- else if(num2/10<10)
- {
- LCD_ShowString(183,60,200,18,24,"_");
- }
- else if(num2/10<100)
- {
- LCD_ShowString(172,60,200,18,24,"_");
- }
- else if(num2/10<1000)
- {
- LCD_ShowString(161,60,200,18,24,"_");
- }
- else if(num2/10<10000)
- {
- LCD_ShowString(150,60,200,18,24,"_");
- }
- else if(num2/10<100000)
- {
- LCD_ShowString(139,60,200,18,24,"_");
- }
- else if(num2/10<1000000)
- {
- LCD_ShowString(128,60,200,18,24,"_");
- }
- else if(num2/10<10000000)
- {
- LCD_ShowString(117,60,200,18,24,"_");
- }
- else LCD_ShowString(103,60,200,18,24,"_");
- }
- else
- {
- LCD_ShowxNum(80,90,num1,12,24,1);
- if(num1==0)
- {
- ;
- }
- else if(num1/10<1)
- {
- LCD_ShowString(195,80,200,18,24,"_");
- }
- else if(num1/10<10)
- {
- LCD_ShowString(183,80,200,18,24,"_");
- }
- else if(num1/10<100)
- {
- LCD_ShowString(172,80,200,18,24,"_");
- }
- else if(num1/10<1000)
- {
- LCD_ShowString(161,80,200,18,24,"_");
- }
- else if(num1/10<10000)
- {
- LCD_ShowString(150,80,200,18,24,"_");
- }
- else if(num1/10<100000)
- {
- LCD_ShowString(139,80,200,18,24,"_");
- }
- else if(num1/10<1000000)
- {
- LCD_ShowString(128,80,200,18,24,"_");
- }
- else if(num1/10<10000000)
- {
- LCD_ShowString(117,80,200,18,24,"_");
- }
- else LCD_ShowString(103,80,200,18,24,"_");
-
- }
- }
- else
- {
- if(flag)
- {
- LCD_ShowxNum(80,70,num2,12,24,1);
- LCD_ShowxNum(80,90,num1,12,24,1);
- }
- else
- LCD_ShowxNum(80,90,num1,12,24,1);
- }
- }
- }
- tp_dev.scan(0);
- if(tp_dev.sta&TP_PRES_DOWN) //觸摸屏被按下
- {
- if(tp_dev.x[0]<lcddev.width&&tp_dev.y[0]<lcddev.height)
- {
- for(i=0;i<5;i++)
- {
- for(j=0;j<4;j++)
- {
- if(tp_dev.x[0]>(j*60) && tp_dev.x[0]<(j*60+60) && tp_dev.y[0]>(320-(40*i+40)) && tp_dev.y[0]<(320-40*i))
- {
- key=j+i*4+1;
- if(key == 1)
- {aa=1;LCD_Clear(WHITE);delay_ms(100);}
- delay_ms(100);
- LCD_Fill(0,60,240,119,WHITE);
- GPIO_SetBits(GPIOB,GPIO_Pin_8);
- delay_ms(100);
- GPIO_ResetBits(GPIOB,GPIO_Pin_8);
- }
- }
- }
- }
- }else delay_ms(50);
- if(key == 2) num=0;
- else if(key == 3) fuhao ="+/-";
- else if(key == 4) fuhao ="=";
- else if(key == 5) num=1;
- else if(key == 6) num=2;
- else if(key == 7) num=3;
- else if(key == 8) fuhao="+";
- else if(key == 9) num=4;
- else if(key == 10) num=5;
- else if(key == 11) num=6;
- else if(key == 12) fuhao="-";
- else if(key == 13) num=7;
- else if(key == 14) num=8;
- else if(key == 15) num=9;
- else if(key == 16) fuhao="*";
- else if(key == 17) fuhao="C";
- else if(key == 18) fuhao="Delete";
- else if(key == 19) fuhao=".";
- else if(key == 20) fuhao="/";
- switch (key)
- {
- case 17:num1=0;num2=0;F=0;qq=0;break;
- case 18:num1=num1/10;break;
- case 8: num2=num1;num1=0;flag=1;and=1;qq=1;break;
- case 16:num2=num1;num1=0;flag=1;time=1;qq=2;break;
- case 12:num2=num1;num1=0;flag=1;minus=1;qq=3;break;
- case 20:num2=num1;num1=0;flag=1;division=1;qq=4;break;
- case 3:quyu=1;break;
- case 4:
- if(flag)
- {
- qq=0;
- if(and)
- {
- if(F==1)
- {
- if(num1>num2)
- {
- num1-=num2;
- F=0;
- }
- else if(num1 == num2)
- {
- num1=0;
- F=0;
- }
- else
- {
- num1=num2-num1;
- F=1;
- }
- }
- else
- {
- F=0;
- num1+=num2;
- }
- flag=0;
- and = 0;
-
- }
- else if(time)
- {
- num1=num1*num2;flag=0;
- time = 0;
-
- }
- else if(division)
- {
- if(num1>num2)
- {
- num1=0;
- }
- else if(num1==num2)
- {
- num1=1;
- }
- else
- {
- num1=num2/num1;
- }
- flag=0;
- division = 0;
-
- }
- else if(minus)
- {
- if(F==1)
- {
- num1=num1+num2;
- }
-
- else
- {
- if(num2>num1)
- {
- num1=num2-num1;
- F = 0;
- }
- else if(num2==num1)
- {
- num1=0;
- F = 0;
- }
- else
- {
- if(num2<num1)
- {
- num1=num1-num2;
- F = 1;
- }
- }
- }
- flag=0;
- minus = 0;
-
- }
-
- }
- break;
- }
- if(quyu)
- {
- F=!F;
- quyu=0;
- }
- key = 0;
- if(num1<100000000)
- {
- if(num == 0)
- {
- num1 = num1*10;
- num = -1;
- }
- if(num>0 && num<10)
- {
- num1 = num1*10+num;
- num = -1;
- }
- }
- }
- }
- }
復制代碼 注釋部分字體顯示有點錯誤,不過沒什么關系
復制到主界面即可用
51hei下載地址:
jishuanji.7z
(253.88 KB, 下載次數: 220)
2021-6-17 23:58 上傳
點擊文件名下載附件
計算器代碼 下載積分: 黑幣 -5
|