欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
基于stm32開發的DS1302萬年歷程序設計
[打印本頁]
作者:
Tzf-Ly
時間:
2019-3-20 09:52
標題:
基于stm32開發的DS1302萬年歷程序設計
這是一個上次寫的基于STM32開發的萬年歷設計
32.png
(83.33 KB, 下載次數: 60)
下載附件
2019-3-20 09:51 上傳
單片機源程序如下:
/* 下載完程序后要把BOOT1拔掉在重新上電即可看到效果
此程序最關鍵的是要做好io輸入輸出端口的配置,不能
使用GPIO_Mode_Out_OD模式,此不是雙向IO口 */
#include "public.h"
#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)
#define rs (GPIO_Pin_1)
#define rw (GPIO_Pin_2)
#define e (GPIO_Pin_0)
#define io (GPIO_Pin_12)
#define ce (GPIO_Pin_13)
#define sck (GPIO_Pin_14)
u8 num[]="0123456789";
u8 time[7]={0x18, 0x19, 0x13, 0x01, 0x10, 0x06, 0x16};//秒分時日月周年
u8 w[7]={0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c}; //寫地址
u8 r[7]={0x81, 0x83, 0x85, 0x87, 0x89, 0x8b, 0x8d}; //讀地址
u8 miao,fen,shi,zhou,ri,yue,nian;
void GPIOINIT() //端口初始化
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=DATA|rs|rw|e;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);//把調試設置普通IO口
GPIO_InitStructure.GPIO_Pin=ce|sck;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
/*
GPIO_InitStructure.GPIO_Pin=io;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD; //經過測試并不是雙向IO口
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
*/
}
void IOOUTINIT() //io輸出配置
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=io;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
void IOININT() //io輸入配置
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=io;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
void RCCINIT() //系統初始化
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
//如果不加這條語句程序顯示就會出錯,即沒有打開端口復用功能的時鐘配置
}
u8 readbusy() //忙信號檢測
{
u8 f;
GPIO_ResetBits(GPIOB,rs);
GPIO_SetBits(GPIOB,rw);
GPIO_SetBits(GPIOB,e);
f=((GPIO_ReadInputData(GPIOB)&0X8000));
delayms(10);
GPIO_ResetBits(GPIOB,e);
return f;
}
void lcdwrc(u8 c)
{
while(readbusy());
GPIO_ResetBits(GPIOB,rs);
GPIO_ResetBits(GPIOB,rw);
GPIO_ResetBits(GPIOB,e);
delayms(1);
GPIOB->BSRR = c<<8 & 0xf000; //將數據送到P0口
GPIOB->BRR = ((~c)<<8) & 0xf000;
delayms(1);
GPIO_SetBits(GPIOB,e);
delayms(1);
GPIO_ResetBits(GPIOB,e);
delayms(1);
}
void lcdwrc4bit(long c)
{
while(readbusy());
GPIO_ResetBits(GPIOB,rs);
GPIO_ResetBits(GPIOB,rw);
GPIO_ResetBits(GPIOB,e);
delayms(1);
GPIOB->BSRR = c<<8 & 0xf000; //將數據送到P0口
GPIOB->BRR = ((~c)<<8) & 0xf000;
delayms(1);
GPIO_SetBits(GPIOB,e);
delayms(1);
GPIO_ResetBits(GPIOB,e);
delayms(1);
GPIOB->BSRR = c<<12 & 0xf000; //將數據送到P0口
GPIOB->BRR = ((~c)<<12) & 0xf000;
delayms(1);
GPIO_SetBits(GPIOB,e);
delayms(1);
GPIO_ResetBits(GPIOB,e);
delayms(1);
}
void lcdwrd(long dat)
{
while(readbusy());
GPIO_SetBits(GPIOB,rs);
GPIO_ResetBits(GPIOB,rw);
GPIO_ResetBits(GPIOB,e);
delayms(1);
GPIOB->BSRR = dat<<8 & 0xf000; //將數據送到P0口
GPIOB->BRR = ((~dat)<<8) & 0xf000;
delayms(1);
GPIO_SetBits(GPIOB,e);
delayms(1);
GPIO_ResetBits(GPIOB,e);
delayms(1);
GPIOB->BSRR = dat<<12 & 0xf000; //將數據送到P0口
GPIOB->BRR = ((~dat)<<12) & 0xf000;
delayms(1);
GPIO_SetBits(GPIOB,e);
delayms(1);
GPIO_ResetBits(GPIOB,e);
delayms(1);
GPIO_ResetBits(GPIOB,rs);
}
void lcdinit()
{
delayms(15);
lcdwrc4bit(0x32);
delayms(5);
lcdwrc4bit(0x28);
delayms(5);
lcdwrc4bit(0x08);
delayms(5);
lcdwrc4bit(0x01);
delayms(5);
lcdwrc4bit(0x06);
delayms(5);
lcdwrc4bit(0x0c);
delayms(5);
}
void ds1302writebyte(u8 dat) //單字節寫
{
u8 i,value;
GPIO_ResetBits(GPIOA,sck);
delayus(20);
IOOUTINIT();
for(i=0;i<8;i++)
{
value=dat&0x01;
if(value)
GPIO_WriteBit(GPIOA,io,Bit_SET);
else
GPIO_WriteBit(GPIOA,io,Bit_RESET);
dat>>=1;
GPIO_SetBits(GPIOA,sck);
delayus(20);
GPIO_ResetBits(GPIOA,sck);
delayus(20);
}
}
void ds1302writebytes(u8 add,u8 dat) //多字節寫
{
GPIO_ResetBits(GPIOA,ce);
delayus(20);
GPIO_SetBits(GPIOA,ce);
delayus(20);
ds1302writebyte(add);
ds1302writebyte(dat);
GPIO_ResetBits(GPIOA,ce);
delayus(20);
}
u8 ds1302readbyte() //單字節讀
{
u8 i,value;
GPIO_ResetBits(GPIOA,sck);
delayus(20);
IOININT();
for(i=0;i<8;i++)
{
value>>=1;
if(GPIO_ReadInputDataBit(GPIOA,io)==1)
{
value|=0x80;
}
GPIO_SetBits(GPIOA,sck);
delayus(20);
GPIO_ResetBits(GPIOA,sck);
delayus(20);
}
return value;
}
u8 ds1302readbytes(u8 add) //多字節讀
{
u8 temp;
GPIO_ResetBits(GPIOA,ce);
delayus(20);
GPIO_SetBits(GPIOA,ce);
delayus(20);
ds1302writebyte(add);
temp=ds1302readbyte();
GPIO_ResetBits(GPIOA,ce);
delayus(20);
GPIO_ResetBits(GPIOA,io);
delayus(20);
GPIO_SetBits(GPIOA,io); //釋放IO
delayus(20);
return temp;
}
void settime()
{
u8 i;
ds1302writebytes(0x8e,0x00);
for(i=0;i<7;i++)
{
ds1302writebytes(w[i],time[i]);
}
ds1302writebytes(0x8e,0x80);
}
void readtime()
{
miao=ds1302readbytes(r[0]);
fen=ds1302readbytes(r[1]);
shi=ds1302readbytes(r[2]);
zhou=ds1302readbytes(r[5]);
ri=ds1302readbytes(r[3]);
yue=ds1302readbytes(r[4]);
nian=ds1302readbytes(r[6]);
}
void display()
{
lcdwrc4bit(0x00+0x80);
lcdwrd(num[shi/16]);
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
DS1302萬年歷設計.7z
(178.13 KB, 下載次數: 229)
2019-3-20 18:47 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
admin
時間:
2019-3-20 18:47
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
作者:
lxflxy
時間:
2020-6-27 22:54
請問有仿真圖嗎
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1