資源簡介
也是在網上看到的DS3231代碼,使用的0.96OLED【屏幕】,不過代碼僅僅是可以正常使用,調節按鍵,還沒來得及修改,IIC驅動還有OLED驅動都在相應的H文件里面;

代碼片段和文件信息
#include?“reg51.h“
#include?“intrins.h“
#include?“oled.h“
#include?“DC3231.h“?
#define?uchar?unsigned?char
#define?uint?unsigned?int
#define?ulong?unsigned?long
#define??u8?unsigned?char?
#define??u32?unsigned?int?
#define?OLED_CMD??0 //寫命令
#define?OLED_DATA?1 //寫數據
#define?OLED_MODE?0
uchar?key1;
uchar??sec?min?hour?day?date?month?yearDtemp;
//------------------------------------------------------------------------
void?DS3231_Init(void)
{
??uchar?k;
??P6=k=IIC_single_byte_read(0x02);
??k|=0x20;
??P7=k;
??IIC_single_byte_write(k0x02); //轉換12小時制 第六位置H?=?0100?0000
??//P7=IIC_single_byte_read(0x02);
??//P7=~P7;
}
//--------------------------------------------------------------------------
uchar?BCD2HEX(uchar?val)???//BCD轉換為Byte
{
????return????((val>>4)*10)+(val&0x0f);
}
//--------------------------------------------------------------------------
uchar?B_BCD(uchar?val)//Byte碼轉換為BCD碼
{
?????return????(((val%100)/10)<<4)|(val%10);
}?
//--------------------------------------------------------------------------
void?Readtime()
{
????uchar?temp;
??temp=IIC_single_byte_read(0x00);//秒
??sec=(int)BCD2HEX(temp);
??//sec=2;
??temp=IIC_single_byte_read(0x01);//分
??min=BCD2HEX(temp);
??temp=IIC_single_byte_read(0x02);??//時
??//temp&=0x3F;
??hour=BCD2HEX(temp);
??day=IIC_single_byte_read(0x03);//星期
??temp=IIC_single_byte_read(0x04);??//日
??date=BCD2HEX(temp);
??temp=IIC_single_byte_read(0x05);?//月?
??month=BCD2HEX(temp);
??temp=IIC_single_byte_read(0x06);??//年
??year=BCD2HEX(temp);
??Dtemp=IIC_single_byte_read(0x11);//溫度
}
//-------------------------------------------------------------------
void?Showtime()
{
disp16(002); //年的千位
disp16(800); //年的百位
OLED_Set_Pos(341);
OLED_WR_Byte(0x011); //由上至下二進制低至高位
OLED_WR_Byte(0x011); //由上至下二進制低至高位
OLED_WR_Byte(0x011); //由上至下二進制低至高位
OLED_WR_Byte(0x011); //由上至下二進制低至高位
/////////////////////////////////////////////////////////////
OLED_Set_Pos(591);
OLED_WR_Byte(0x011); //由上至下二進制低至高位
OLED_WR_Byte(0x011); //由上至下二進制低至高位
OLED_WR_Byte(0x011); //由上至下二進制低至高位
OLED_WR_Byte(0x011); //由上至下二進制低至高位
OLED_WR_Byte(0x011); //由上至下二進制低至高位
////////////////////////////////////////////////////////////
OLED_Set_Pos(394);
OLED_WR_Byte(0x181);
OLED_WR_Byte(0x3C1);
OLED_WR_Byte(0x3C1);
OLED_WR_Byte(0x181);
OLED_Set_Pos(395);
OLED_WR_Byte(0x601);
OLED_WR_Byte(0xF01);
OLED_WR_Byte(0xF01);
OLED_WR_Byte(0x601);
//////////////////////////////////////////////////////////////
OLED_Set_Pos(854);
OLED_WR_Byte(0x181);
OLED_WR_Byte(0x3C1);
OLED_WR_Byte(0x3C1);
OLED_WR_Byte(0x181);
OLED_Set_Pos(855);
OLED_WR_Byte(0x601);
OLED_WR_Byte(0xF01);
OLED_WR_Byte(0xF01);
OLED_WR_Byte(0x601);
Readtime();
disp32(933sec/10);??//秒的十位
disp32(1113sec%10);??//秒的個位
disp32(463min/10);???//分的十位
disp32(643min%10);???//分的個位
disp32(03hour/10);??? //時的十位
disp32(183hour%10);??//時的個位
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????277??2018-11-16?14:36??DS3231+12864\DC3231.H
?????文件??????61269??2018-11-16?14:36??DS3231+12864\DS3231+12864
?????文件???????2070??2018-11-16?14:36??DS3231+12864\DS3231+12864.build_log.htm
?????文件??????14738??2018-11-16?14:36??DS3231+12864\DS3231+12864.hex
?????文件?????????95??2018-11-16?14:36??DS3231+12864\DS3231+12864.lnp
?????文件??????38791??2018-11-16?14:36??DS3231+12864\DS3231+12864.M51
????.......?????72591??2018-11-16?14:36??DS3231+12864\DS3231+12864.uvgui.Administrator
????.......??????6517??2018-11-16?14:36??DS3231+12864\DS3231+12864.uvopt
????.......?????14159??2018-11-16?14:36??DS3231+12864\DS3231+12864.uvproj
?????文件???????3444??2018-11-16?14:34??DS3231+12864\ds3231IIC.C
?????文件???????5719??2018-11-16?14:36??DS3231+12864\ds3231IIC.LST
?????文件??????11195??2018-11-16?14:36??DS3231+12864\ds3231IIC.OBJ
?????文件???????8204??2018-11-16?14:35??DS3231+12864\main.c
?????文件??????14309??2018-11-16?14:36??DS3231+12864\main.LST
?????文件??????25435??2018-11-16?14:36??DS3231+12864\main.OBJ
?????文件???????9799??2018-11-16?14:28??DS3231+12864\oled.c
?????文件???????1184??2018-11-16?14:28??DS3231+12864\oled.h
?????文件??????14169??2018-11-16?14:36??DS3231+12864\oled.LST
?????文件??????32902??2018-11-16?14:36??DS3231+12864\oled.OBJ
?????文件???????7876??2018-11-16?14:14??DS3231+12864\oledfont.h
?????文件???????6376??2009-05-07?14:37??DS3231+12864\STARTUP.A51
?????文件??????14048??2018-11-16?14:36??DS3231+12864\STARTUP.LST
?????文件????????749??2018-11-16?14:36??DS3231+12864\STARTUP.OBJ
?????目錄??????????0??2018-11-16?14:36??DS3231+12864
-----------?---------??----------?-----??----
???????????????365916????????????????????24
評論
共有 條評論