久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 7987|回復: 8
打印 上一主題 下一主題
收起左側

自制stm32小游戲,類似打地鼠

  [復制鏈接]
跳轉到指定樓層
樓主
ID:225148 發表于 2017-8-6 11:07 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
寫了不到一天時間,就自己瞎玩一玩,大家看看,哈哈哈

所有資料51hei提供下載:
實驗40 踩百塊哈哈哈.rar (1.21 MB, 下載次數: 137)


stm32單片機源程序如下:
  1. #include "sys.h"
  2. #include "delay.h"
  3. #include "usart.h"
  4. #include "led.h"
  5. #include "lcd.h"
  6. #include "key.h"  
  7. #include "sram.h"   
  8. #include "malloc.h"
  9. #include "usmart.h"  
  10. #include "sdio_sdcard.h"   
  11. #include "malloc.h"
  12. #include "w25qxx.h"   
  13. #include "ff.h"  
  14. #include "timer.h"
  15. #include "exfuns.h"   
  16. #include "fontupd.h"
  17. #include "text.h"       
  18. #include "rng.h"
  19. #include "touch.h"
  20. #include "rtc.h"

  21. //ALIENTEK 探索者STM32F407開發板 實驗40
  22. //漢字顯示 實驗 -庫函數版本

  23. //清空屏幕并在右上角顯示"RST"    t

  24. u32 qwer;

  25. u32 random=300;
  26. u32 dom=300;

  27. u32 miao;



  28. void TIM3_IRQHandler(void)
  29. {
  30.         if(TIM_GetITStatus(TIM3,TIM_IT_Update)==SET) //溢出中斷
  31. {  
  32.         miao++;
  33.         LCD_ShowNum(30+3*16,170,miao,5,16); //shijian

  34. }
  35.         TIM_ClearITPendingBit(TIM3,TIM_IT_Update);  //清除中斷標志位
  36. }


  37. void Load_Drow_Dialog(void)
  38. {
  39. //        LCD_Clear(WHITE);//清屏   
  40.         POINT_COLOR=BLUE;//設置字體為藍色
  41.         LCD_ShowString(lcddev.width-24,0,200,16,16,"RST");//顯示清屏區域
  42.           POINT_COLOR=RED;//設置畫筆藍色
  43. }
  44. ////////////////////////////////////////////////////////////////////////////////
  45. //電容觸摸屏專有部分
  46. //畫水平線
  47. //x0,y0:坐標
  48. //len:線長度
  49. //color:顏色
  50. void gui_draw_hline(u16 x0,u16 y0,u16 len,u16 color)
  51. {
  52.         if(len==0)return;
  53.         LCD_Fill(x0,y0,x0+len-1,y0,color);       
  54. }
  55. //畫實心圓
  56. //x0,y0:坐標
  57. //r:半徑
  58. //color:顏色
  59. void gui_fill_circle(u16 x0,u16 y0,u16 r,u16 color)
  60. {                                                                                          
  61.         u32 i;
  62.         u32 imax = ((u32)r*707)/1000+1;
  63.         u32 sqmax = (u32)r*(u32)r+(u32)r/2;
  64.         u32 x=r;
  65.         gui_draw_hline(x0-r,y0,2*r,color);
  66.         for (i=1;i<=imax;i++)
  67.         {
  68.                 if ((i*i+x*x)>sqmax)// draw lines from outside  
  69.                 {
  70.                         if (x>imax)
  71.                         {
  72.                                 gui_draw_hline (x0-i+1,y0+x,2*(i-1),color);
  73.                                 gui_draw_hline (x0-i+1,y0-x,2*(i-1),color);
  74.                         }
  75.                         x--;
  76.                 }
  77.                 // draw lines from inside (center)  
  78.                 gui_draw_hline(x0-x,y0+i,2*x,color);
  79.                 gui_draw_hline(x0-x,y0-i,2*x,color);
  80.         }
  81. }  
  82. //兩個數之差的絕對值
  83. //x1,x2:需取差值的兩個數
  84. //返回值:|x1-x2|
  85. u16 my_abs(u16 x1,u16 x2)
  86. {                         
  87.         if(x1>x2)return x1-x2;
  88.         else return x2-x1;
  89. }  
  90. //畫一條粗線
  91. //(x1,y1),(x2,y2):線條的起始坐標
  92. //size:線條的粗細程度
  93. //color:線條的顏色
  94. void lcd_draw_bline(u16 x1, u16 y1, u16 x2, u16 y2,u8 size,u16 color)
  95. {
  96.         u16 t;
  97.         int xerr=0,yerr=0,delta_x,delta_y,distance;
  98.         int incx,incy,uRow,uCol;
  99.         if(x1<size|| x2<size||y1<size|| y2<size)return;
  100.         delta_x=x2-x1; //計算坐標增量
  101.         delta_y=y2-y1;
  102.         uRow=x1;
  103.         uCol=y1;
  104.         if(delta_x>0)incx=1; //設置單步方向
  105.         else if(delta_x==0)incx=0;//垂直線
  106.         else {incx=-1;delta_x=-delta_x;}
  107.         if(delta_y>0)incy=1;
  108.         else if(delta_y==0)incy=0;//水平線
  109.         else{incy=-1;delta_y=-delta_y;}
  110.         if( delta_x>delta_y)distance=delta_x; //選取基本增量坐標軸
  111.         else distance=delta_y;
  112.         for(t=0;t<=distance+1;t++ )//畫線輸出
  113.         {  
  114.                 gui_fill_circle(uRow,uCol,size,color);//畫點
  115.                 xerr+=delta_x ;
  116.                 yerr+=delta_y ;
  117.                 if(xerr>distance)
  118.                 {
  119.                         xerr-=distance;
  120.                         uRow+=incx;
  121.                 }
  122.                 if(yerr>distance)
  123.                 {
  124.                         yerr-=distance;
  125.                         uCol+=incy;
  126.                 }
  127.         }  
  128. }   
  129. ////////////////////////////////////////////////////////////////////////////////
  130. //5個觸控點的顏色(電容觸摸屏用)                                                                                                 
  131. const u16 POINT_COLOR_TBL[OTT_MAX_TOUCH]={RED,GREEN,BLUE,BROWN,GRED};  
  132. ////電阻觸摸屏測試函數
  133. void rtp_test(void)
  134. {
  135.         u8 key;
  136.         u8 i=0;          
  137.         while(1)
  138.         {
  139.                  key=KEY_Scan(0);
  140.                 tp_dev.scan(0);                  
  141.                 if(tp_dev.sta&TP_PRES_DOWN)                        //觸摸屏被按下
  142.                 {       
  143.                          if(tp_dev.x[0]<lcddev.width&&tp_dev.y[0]<lcddev.height)
  144.                         {       
  145.                                 if(tp_dev.x[0]>(lcddev.width-24)&&tp_dev.y[0]<16)Load_Drow_Dialog();//清除
  146.                                 else TP_Draw_Big_Point(tp_dev.x[0],tp_dev.y[0],RED);                //畫圖                                    
  147.                         }
  148.                 }else delay_ms(10);        //沒有按鍵按下的時候             
  149.                 if(key==KEY0_PRES)        //KEY0按下,則執行校準程序
  150.                 {
  151.                         LCD_Clear(WHITE);        //清屏
  152.                     TP_Adjust();                  //屏幕校準
  153.                         TP_Save_Adjdata();         
  154.                         Load_Drow_Dialog();
  155.                 }
  156.                 i++;
  157.         //        if(i%20==0)LED0=!LED0;
  158.         }
  159. }
  160. //電容觸摸屏測試函數




  161. void ctp_test(void)
  162. {
  163.        
  164.         u8 t=0;
  165.         u8 i=0;                      
  166.         u16 lastpos[5][2];                //最后一次的數據
  167.        
  168.         while(1)
  169.         {
  170.                
  171.                 tp_dev.scan(0);
  172.                 for(t=0;t<OTT_MAX_TOUCH;t++)
  173.                 {
  174.                         if((tp_dev.sta)&(1<<t))
  175.                         {
  176.                                 if(tp_dev.x[t]<lcddev.width&&tp_dev.y[t]<lcddev.height)
  177.                                 {
  178.                                         if(lastpos[t][0]==0XFFFF)
  179.                                         {
  180.                                                 lastpos[t][0] = tp_dev.x[t];
  181.                                                 lastpos[t][1] = tp_dev.y[t];
  182.                                         }
  183.                                         lcd_draw_bline(lastpos[t][0],lastpos[t][1],tp_dev.x[t],tp_dev.y[t],2,POINT_COLOR_TBL[t]);//畫線
  184.                                         lastpos[t][0]=tp_dev.x[t];
  185.                                         lastpos[t][1]=tp_dev.y[t];
  186.                                                
  187.                                         if(tp_dev.x[t]>random&&tp_dev.x[t]<random+30&&tp_dev.y[t]>dom&&tp_dev.y[t]<dom+30)       //水平方向,可以來進行類似的按鍵檢測
  188.                                         {

  189.                                                 random=RNG_Get_RandomRange(35,365);//獲取[0,9]區間的隨機數   x
  190.             dom=RNG_Get_RandomRange(235,665);//獲取[0,9]區間的隨機數      y
  191.                                                 delay_ms(10);
  192.                                                 Load_Drow_Dialog();//清除
  193.                                                 delay_ms(10);
  194.                                                 LCD_Fill(33,233,400,700,WHITE);
  195.                                                 LED1=!LED1;
  196.                                                 LCD_Fill(random,dom,random+30,dom+30,BLUE);
  197.                                                 qwer=qwer+17;
  198.                                                 LCD_ShowNum(30+5*16,150,qwer,5,16); //顯示隨機數
  199.                                                 if(qwer>1000)
  200.                                                 {
  201.                         Show_Str(30,210,200,16,"您是MVP:",16,0);
  202.                                                       Show_Str(30,210,200,16,"您是MVP:",16,0);

  203.                                                 }
  204.                                        
  205.                                         }
  206.                                 }
  207.                         }else lastpos[t][0]=0XFFFF;
  208.                 }
  209.                
  210.                 delay_ms(5);i++;
  211.                 //if(i%20==0)LED0=!LED0;
  212.         }       
  213. }
  214.        

  215. void retc()
  216. {
  217. RTC_TimeTypeDef RTC_TimeStruct;
  218.         RTC_DateTypeDef RTC_DateStruct;
  219. u8 x;
  220.                 u8 tbuf[40];
  221. x++;
  222.                 if((x%10)==0)        //每100ms更新一次顯示數據         RTC_TimeStruct.RTC_Hours
  223.                 {

  224.                         RTC_GetTime(RTC_Format_BIN,&RTC_TimeStruct);
  225.                        
  226.                         sprintf((char*)tbuf,"Time:%02d:%02d:%02d",RTC_TimeStruct.RTC_Hours,RTC_TimeStruct.RTC_Minutes,RTC_TimeStruct.RTC_Seconds);
  227.                         LCD_ShowString(30,140,210,16,16,tbuf);       
  228.                        
  229.                         RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
  230.                        
  231.                         sprintf((char*)tbuf,"Date:20%02d-%02d-%02d",RTC_DateStruct.RTC_Year,RTC_DateStruct.RTC_Month,RTC_DateStruct.RTC_Date);
  232.                         LCD_ShowString(30,160,210,16,16,tbuf);       
  233.                         sprintf((char*)tbuf,"Week:%d",RTC_DateStruct.RTC_WeekDay);
  234.                         LCD_ShowString(30,180,210,16,16,tbuf);
  235.                                
  236.                 }
  237. }       




  238. void jiemian()
  239. {
  240. LCD_Fill(33,33,333,400,GREEN);
  241. LCD_Fill(533,33,750,400,BLUE);

  242. }




  243. int main(void)
  244. {  
  245.      RTC_TimeTypeDef RTC_TimeStruct;
  246.         RTC_DateTypeDef RTC_DateStruct;
  247. u8 x;
  248.                 u8 tbuf[40];
  249.         u32 fontcnt;                  
  250.         u8 i,j;
  251.         u8 t;
  252.         u8 fontx[2];//gbk碼
  253. u32 miao=0;

  254.         u8 key;//t;
  255.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設置系統中斷優先級分組2
  256.         delay_init(168);  //初始化延時函數
  257.         uart_init(9600);                //初始化串口波特率為115200
  258.         LED_Init();                                        //初始化LED  
  259.         LCD_Init();                                        //LCD初始化  
  260.         KEY_Init();                                        //按鍵初始化  
  261.         RNG_Init();
  262.         //My_RTC_Init();                                 //初始化RTC
  263.         tp_dev.init();                                //觸摸屏初始化
  264.         TIM3_Int_Init(10000-1,8400-1);        //定時器時鐘84M,分頻系數8400,所以84M/8400=10Khz的計數頻率,計數5000次為500ms   
  265.         W25QXX_Init();                                //初始化W25Q128
  266.         usmart_dev.init(84);                //初始化USMART
  267.         my_mem_init(SRAMIN);                //初始化內部內存池
  268.         my_mem_init(SRAMCCM);                //初始化CCM內存池
  269.         exfuns_init();                                //為fatfs相關變量申請內存  
  270.           f_mount(fs[0],"0:",1);                 //掛載SD卡
  271.         f_mount(fs[1],"1:",1);                 //掛載FLASH.
  272.        
  273.        
  274.         //RTC_Set_WakeUp(RTC_WakeUpClock_CK_SPRE_16bits,0);                //配置WAKE UP中斷,1秒鐘中斷一次
  275.        
  276.        
  277.         while(font_init())                         //檢查字庫
  278.         {
  279. UPD:   
  280.                 LCD_Clear(WHITE);                           //清屏
  281.                 POINT_COLOR=RED;                        //設置字體為紅色                                
  282.                 LCD_ShowString(30,50,200,16,16,"Explorer STM32F4");
  283. //                while(SD_Init())                        //檢測SD卡
  284. //                {
  285. //                        LCD_ShowString(30,70,200,16,16,"SD Card Failed!");
  286. //                        delay_ms(200);
  287. //                        LCD_Fill(30,70,200+30,70+16,WHITE);
  288. //                        delay_ms(200);                    
  289. //                }                                                                                                                     
  290.                 LCD_ShowString(30,70,200,16,16,"SD Card OK");
  291.                 LCD_ShowString(30,90,200,16,16,"Font Updating...");
  292.                 key=update_font(20,110,16,"0:");//更新字庫
  293.                 while(key)//更新失敗               
  294.                 {                                           
  295.                         LCD_ShowString(30,110,200,16,16,"Font Update Failed!");
  296.                         delay_ms(200);
  297.                         LCD_Fill(20,110,200+20,110+16,WHITE);
  298.                         delay_ms(200);                       
  299.                 }                   
  300.                 LCD_ShowString(30,110,200,16,16,"Font Update Success!   ");
  301.                 delay_ms(1500);       
  302.                 LCD_Clear(WHITE);//清屏               
  303.         }  
  304.         POINT_COLOR=RED;     

  305. jiemian();


  306.         if(tp_dev.touchtype!=0XFF)LCD_ShowString(30,130,200,16,16,"Press KEY0 to Adjust");//電阻屏才顯示
  307.         delay_ms(1500);
  308.         Load_Drow_Dialog();                
  309.         LCD_Fill(random,dom,random+30,dom+30,BLUE);

  310.         if(tp_dev.touchtype&0X80)ctp_test();//電容屏測試
  311.         else rtp_test();                                         //電阻屏測試
  312.         while(1)
  313.         {
  314.                 fontcnt=0;
  315.                 //retc();
  316.                
  317.                
  318.                 Show_Str(30,210,200,16,"您是MVP:",16,0);
  319.                
  320.                
  321.                 x++;
  322.                 if((x%10)==0)        //每100ms更新一次顯示數據         RTC_TimeStruct.RTC_Hours
  323.                 {

  324.                         RTC_GetTime(RTC_Format_BIN,&RTC_TimeStruct);
  325.                        
  326.                         sprintf((char*)tbuf,":%02d:%02d:%02d",RTC_TimeStruct.RTC_Hours,RTC_TimeStruct.RTC_Minutes,RTC_TimeStruct.RTC_Seconds);
  327.                         LCD_ShowString(530,140,210,24,24,tbuf);       
  328.                        
  329.                         RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
  330.                        
  331.                         sprintf((char*)tbuf,"日期:20%02d-%02d-%02d",RTC_DateStruct.RTC_Year,RTC_DateStruct.RTC_Month,RTC_DateStruct.RTC_Date);
  332.                         LCD_ShowString(530,180,210,24,24,tbuf);       
  333.                        
  334.                         sprintf((char*)tbuf,"Week:%d",RTC_DateStruct.RTC_WeekDay);
  335.                         LCD_ShowString(530,220,210,24,24,tbuf);
  336.                                
  337.                 }
  338.                
  339.                
  340.                
  341.                
  342.                
  343.                
  344.                
  345.                
  346.                
  347.                
  348.                
  349.                 for(i=0x81;i<0xff;i++)
  350.                 {               
  351.                         fontx[0]=i;
  352. //                        LCD_ShowNum(118,150,i,3,16);                //顯示內碼高字節  
  353.                        
  354.                         for(j=0x40;j<0xfe;j++)
  355.                         {
  356.                                 if(j==0x7f)continue;
  357.                                 fontcnt++;
  358. //                                LCD_ShowNum(118,170,j,3,16);        //顯示內碼低字節         
  359. //                                LCD_ShowNum(118,190,fontcnt,5,16);//漢字計數顯示         
  360.                                  fontx[1]=j;
  361. //                                Show_Font(30+132,220,fontx,24,0);          
  362. //                                Show_Font(30+144,244,fontx,16,0);                                            
  363. //                                Show_Font(30+108,260,fontx,12,0);                                            
  364. //                                t=200;
  365.                                
  366.                                
  367. //                               
  368. //                               
  369. //                               
  370. //                                while(t--)//延時,同時掃描按鍵
  371. //                                {
  372. //                                        delay_ms(1);
  373. //                                        key=KEY_Scan(0);
  374. //                                        if(key==KEY0_PRES)goto UPD;
  375. //                                }
  376. //                //                LED0=!LED0;
  377.                         }   
  378.                 }       
  379.         }
  380. }
復制代碼



評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:225148 發表于 2017-8-6 15:54 | 只看該作者
沒人喵
回復

使用道具 舉報

板凳
ID:421423 發表于 2018-11-5 23:22 來自手機 | 只看該作者
頂一個
回復

使用道具 舉報

地板
ID:420026 發表于 2018-11-6 09:01 | 只看該作者
好東西,必須頂起來
回復

使用道具 舉報

5#
ID:368791 發表于 2018-11-6 22:32 來自手機 | 只看該作者
好東西,頂上去
回復

使用道具 舉報

6#
ID:444708 發表于 2018-12-12 11:22 | 只看該作者
......好東西,但是突然發現還有1-20行的庫我沒有....
完全沒辦法跑
回復

使用道具 舉報

7#
ID:467442 發表于 2020-6-7 23:56 | 只看該作者
來試試
回復

使用道具 舉報

8#
ID:91165 發表于 2020-6-8 09:51 | 只看該作者
這個真好,準備買個407
回復

使用道具 舉報

9#
ID:793851 發表于 2020-7-8 20:55 | 只看該作者
有仿真圖嗎
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美高清视频一区 | 草草草网站 | 亚洲一区影院 | 久久精品视频99 | 国产精品美女久久久久aⅴ国产馆 | 午夜一级黄色片 | 久久久久久久国产精品视频 | 久久久网| 大伊人久久 | 免费av在线| 欧美色综合网 | 国产一区二区三区免费观看在线 | 久久久成人免费视频 | 欧美日韩中文字幕在线 | 久久亚洲一区二区三区四区 | 日日夜夜天天干 | 亚洲精品国产精品国自产在线 | 欧美精品一区二区三区四区 在线 | 日韩电影中文字幕 | 天天综合久久 | 久久久美女 | 在线91| 久久这里只有精品首页 | 免费麻豆视频 | 麻豆一区 | 中文字幕综合在线 | 国精品一区二区 | 先锋av资源在线 | 亚洲一区二区三区免费视频 | 黑人精品欧美一区二区蜜桃 | 亚洲成av人片在线观看 | 91精品国产乱码久久久久久久久 | 中文字幕一区二区三区在线视频 | 在线一区二区三区 | 人人看人人草 | 99久久99热这里只有精品 | 国产精品99久久久久久动医院 | 欧美精品福利 | 欧美黑人狂野猛交老妇 | 国产免费一区二区 | 国产一区二区在线免费观看 |