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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4790|回復: 2
收起左側

基于stm32開發的DS1302萬年歷程序設計

[復制鏈接]
ID:493714 發表于 2019-3-20 09:52 | 顯示全部樓層 |閱讀模式
這是一個上次寫的基于STM32開發的萬年歷設計
32.png
單片機源程序如下:
  1. /* 下載完程序后要把BOOT1拔掉在重新上電即可看到效果
  2.         此程序最關鍵的是要做好io輸入輸出端口的配置,不能
  3.         使用GPIO_Mode_Out_OD模式,此不是雙向IO口 */


  4. #include "public.h"
  5. #define DATA (GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15)
  6. #define rs (GPIO_Pin_1)
  7. #define rw (GPIO_Pin_2)
  8. #define e (GPIO_Pin_0)

  9. #define io (GPIO_Pin_12)
  10. #define ce (GPIO_Pin_13)
  11. #define sck (GPIO_Pin_14)

  12. u8 num[]="0123456789";
  13. u8 time[7]={0x18, 0x19, 0x13, 0x01, 0x10, 0x06, 0x16};//秒分時日月周年
  14. u8 w[7]={0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c};  //寫地址
  15. u8 r[7]={0x81, 0x83, 0x85, 0x87, 0x89, 0x8b, 0x8d};  //讀地址
  16. u8 miao,fen,shi,zhou,ri,yue,nian;
  17. void GPIOINIT()          //端口初始化
  18. {
  19.         GPIO_InitTypeDef GPIO_InitStructure;
  20.         GPIO_InitStructure.GPIO_Pin=DATA|rs|rw|e;
  21.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  22.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  23.         GPIO_Init(GPIOB,&GPIO_InitStructure);
  24.        
  25.         GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);//把調試設置普通IO口
  26.        
  27.         GPIO_InitStructure.GPIO_Pin=ce|sck;
  28.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  29.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  30.         GPIO_Init(GPIOA,&GPIO_InitStructure);
  31. /*
  32.         GPIO_InitStructure.GPIO_Pin=io;
  33.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD;        //經過測試并不是雙向IO口
  34.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  35.         GPIO_Init(GPIOA,&GPIO_InitStructure);
  36. */
  37.        
  38. }
  39. void IOOUTINIT()   //io輸出配置
  40. {
  41.         GPIO_InitTypeDef GPIO_InitStructure;
  42.         GPIO_InitStructure.GPIO_Pin=io;
  43.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;       
  44.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  45.         GPIO_Init(GPIOA,&GPIO_InitStructure);       
  46. }
  47. void IOININT()         //io輸入配置
  48. {
  49.         GPIO_InitTypeDef GPIO_InitStructure;
  50.         GPIO_InitStructure.GPIO_Pin=io;
  51.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;       
  52.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  53.         GPIO_Init(GPIOA,&GPIO_InitStructure);       
  54. }
  55. void RCCINIT() //系統初始化
  56. {
  57.         SystemInit();
  58.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  59.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  60.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
  61.         //如果不加這條語句程序顯示就會出錯,即沒有打開端口復用功能的時鐘配置
  62. }
  63. u8 readbusy()        //忙信號檢測
  64. {               
  65.         u8 f;       
  66.         GPIO_ResetBits(GPIOB,rs);               
  67.         GPIO_SetBits(GPIOB,rw);
  68.         GPIO_SetBits(GPIOB,e);       
  69.         f=((GPIO_ReadInputData(GPIOB)&0X8000));
  70.         delayms(10);
  71.         GPIO_ResetBits(GPIOB,e);
  72.         return f;               
  73. }
  74. void lcdwrc(u8 c)
  75. {       
  76.         while(readbusy());
  77.         GPIO_ResetBits(GPIOB,rs);               
  78.         GPIO_ResetBits(GPIOB,rw);
  79.         GPIO_ResetBits(GPIOB,e);
  80.         delayms(1);
  81.         GPIOB->BSRR = c<<8 & 0xf000;  //將數據送到P0口
  82.     GPIOB->BRR = ((~c)<<8) & 0xf000;

  83.         delayms(1);
  84.         GPIO_SetBits(GPIOB,e);
  85.         delayms(1);
  86.         GPIO_ResetBits(GPIOB,e);
  87.         delayms(1);
  88. }

  89. void lcdwrc4bit(long c)
  90. {       
  91.         while(readbusy());
  92.         GPIO_ResetBits(GPIOB,rs);               
  93.         GPIO_ResetBits(GPIOB,rw);
  94.         GPIO_ResetBits(GPIOB,e);
  95.         delayms(1);
  96.         GPIOB->BSRR = c<<8 & 0xf000;  //將數據送到P0口
  97.     GPIOB->BRR = ((~c)<<8) & 0xf000;
  98.         delayms(1);
  99.         GPIO_SetBits(GPIOB,e);
  100.         delayms(1);
  101.         GPIO_ResetBits(GPIOB,e);
  102.         delayms(1);

  103.         GPIOB->BSRR = c<<12 & 0xf000;  //將數據送到P0口
  104.     GPIOB->BRR = ((~c)<<12) & 0xf000;
  105.         delayms(1);
  106.         GPIO_SetBits(GPIOB,e);
  107.         delayms(1);
  108.         GPIO_ResetBits(GPIOB,e);
  109.         delayms(1);
  110. }

  111. void lcdwrd(long dat)
  112. {
  113.         while(readbusy());               
  114.         GPIO_SetBits(GPIOB,rs);               
  115.         GPIO_ResetBits(GPIOB,rw);
  116.         GPIO_ResetBits(GPIOB,e);
  117.         delayms(1);
  118.         GPIOB->BSRR = dat<<8 & 0xf000;  //將數據送到P0口
  119.     GPIOB->BRR = ((~dat)<<8) & 0xf000;
  120.         delayms(1);
  121.         GPIO_SetBits(GPIOB,e);
  122.         delayms(1);
  123.         GPIO_ResetBits(GPIOB,e);
  124.         delayms(1);
  125.         GPIOB->BSRR = dat<<12 & 0xf000;  //將數據送到P0口
  126.     GPIOB->BRR = ((~dat)<<12) & 0xf000;
  127.         delayms(1);
  128.         GPIO_SetBits(GPIOB,e);
  129.         delayms(1);
  130.         GPIO_ResetBits(GPIOB,e);
  131.         delayms(1);
  132.         GPIO_ResetBits(GPIOB,rs);
  133. }
  134. void lcdinit()
  135. {
  136.         delayms(15);
  137.         lcdwrc4bit(0x32);
  138.         delayms(5);       
  139.         lcdwrc4bit(0x28);
  140.         delayms(5);
  141.         lcdwrc4bit(0x08);
  142.         delayms(5);
  143.         lcdwrc4bit(0x01);
  144.         delayms(5);
  145.         lcdwrc4bit(0x06);
  146.         delayms(5);
  147.         lcdwrc4bit(0x0c);
  148.         delayms(5);
  149. }

  150. void ds1302writebyte(u8 dat)   //單字節寫
  151. {
  152.         u8 i,value;
  153.         GPIO_ResetBits(GPIOA,sck);
  154.         delayus(20);
  155.         IOOUTINIT();               
  156.         for(i=0;i<8;i++)
  157.         {
  158.                 value=dat&0x01;       
  159.                 if(value)
  160.                         GPIO_WriteBit(GPIOA,io,Bit_SET);
  161.                 else
  162.                         GPIO_WriteBit(GPIOA,io,Bit_RESET);
  163.                 dat>>=1;
  164.                 GPIO_SetBits(GPIOA,sck);
  165.                 delayus(20);
  166.                 GPIO_ResetBits(GPIOA,sck);
  167.                 delayus(20);       
  168.         }
  169. }
  170. void ds1302writebytes(u8 add,u8 dat) //多字節寫
  171. {
  172.         GPIO_ResetBits(GPIOA,ce);
  173.         delayus(20);
  174.         GPIO_SetBits(GPIOA,ce);
  175.         delayus(20);
  176.         ds1302writebyte(add);
  177.         ds1302writebyte(dat);
  178.         GPIO_ResetBits(GPIOA,ce);
  179.         delayus(20);                       
  180. }
  181. u8 ds1302readbyte()         //單字節讀
  182. {
  183.         u8 i,value;
  184.         GPIO_ResetBits(GPIOA,sck);
  185.         delayus(20);
  186.         IOININT();               
  187.         for(i=0;i<8;i++)
  188.         {
  189.                 value>>=1;
  190.                 if(GPIO_ReadInputDataBit(GPIOA,io)==1)
  191.                 {
  192.                         value|=0x80;
  193.                 }       
  194.                 GPIO_SetBits(GPIOA,sck);
  195.                 delayus(20);
  196.                 GPIO_ResetBits(GPIOA,sck);
  197.                 delayus(20);       
  198.         }
  199.         return value;                                       
  200. }
  201. u8 ds1302readbytes(u8 add)         //多字節讀
  202. {
  203.         u8 temp;
  204.         GPIO_ResetBits(GPIOA,ce);
  205.         delayus(20);
  206.         GPIO_SetBits(GPIOA,ce);
  207.         delayus(20);
  208.         ds1302writebyte(add);
  209.         temp=ds1302readbyte();
  210.         GPIO_ResetBits(GPIOA,ce);
  211.         delayus(20);
  212.         GPIO_ResetBits(GPIOA,io);
  213.         delayus(20);       
  214.         GPIO_SetBits(GPIOA,io);         //釋放IO
  215.         delayus(20);       
  216.         return temp;               
  217. }
  218. void settime()
  219. {
  220.         u8 i;
  221.         ds1302writebytes(0x8e,0x00);
  222.         for(i=0;i<7;i++)
  223.         {
  224.                 ds1302writebytes(w[i],time[i]);       
  225.         }
  226.         ds1302writebytes(0x8e,0x80);
  227. }
  228. void readtime()
  229. {
  230.         miao=ds1302readbytes(r[0]);
  231.         fen=ds1302readbytes(r[1]);
  232.         shi=ds1302readbytes(r[2]);
  233.         zhou=ds1302readbytes(r[5]);
  234.         ri=ds1302readbytes(r[3]);
  235.         yue=ds1302readbytes(r[4]);       
  236.         nian=ds1302readbytes(r[6]);       
  237. }
  238. void display()
  239. {
  240.         lcdwrc4bit(0x00+0x80);       
  241.         lcdwrd(num[shi/16]);
  242. ……………………

  243. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
DS1302萬年歷設計.7z (178.13 KB, 下載次數: 229)
回復

使用道具 舉報

ID:1 發表于 2019-3-20 18:47 | 顯示全部樓層
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
回復

使用道具 舉報

ID:777712 發表于 2020-6-27 22:54 | 顯示全部樓層
請問有仿真圖嗎
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 午夜精品久久久久久不卡欧美一级 | 亚洲精品一区二区三区中文字幕 | 国产欧美一区二区精品忘忧草 | 中文字幕中文字幕 | 电影91久久久 | 精品久久精品 | 嫩草视频在线看 | 黄片毛片免费观看 | 久草久草久草 | 成人午夜网 | 午夜性色a√在线视频观看9 | 91精品国产综合久久久动漫日韩 | 伊人伊人 | 911精品美国片911久久久 | 国产精品亚洲成在人线 | 亚洲情综合五月天 | 一区二区三区视频在线观看 | 国内久久精品 | 天天躁日日躁aaaa视频 | jdav视频在线观看免费 | 91资源在线 | www.欧美| 亚洲久久在线 | 99精品一区二区 | 日韩国产精品一区二区三区 | 久亚州在线播放 | 久草热8精品视频在线观看 午夜伦4480yy私人影院 | 青青草这里只有精品 | 亚洲国产高清高潮精品美女 | 日韩黄色小视频 | 三级成人在线 | 亚洲一区二区三区免费 | 午夜性色a√在线视频观看9 | 精品欧美一区二区三区久久久 | 午夜天堂精品久久久久 | 亚洲精品电影网在线观看 | 欧美一区二区三区 | 国产色片在线 | 亚洲欧美日韩精品久久亚洲区 | 日本午夜在线视频 | av中文字幕在线观看 |