亚洲网站在线免费观看,欧美性运动视频免费观看网站,国产精品爽爽久久,熟女少妇丰满一区二区

問答

DS1302的問題 時(shí)間加到79年再加就變成00年,00年再減就變成19年。求解啊!!哪位大俠幫幫忙啊!!急!!

提問者:chailang11372013-08-22 00:00

最佳答案

你的程序沒問題吧?先排除軟件上的問題,1302的時(shí)間格式是BCD碼的,你的是否正確,還有1302國產(chǎn)的片子水貨比較多,之前連續(xù)用了幾塊都有問題,時(shí)間走得太慢比正常的慢一倍,換了塊片子就好了。 這是我驗(yàn)證通過的程序 sbit SCLK = P3^3; sbit IO = P3^5; sbit RST = P3^4; sbit ACC_0 = ACC^0; sbit ACC_7 = ACC^7; //秒 分 時(shí) 日 月 星期 年 unsigned char idata init_time[] = {0x00, 0x00, 0x20, 0x01, 0x01, 0x05, 0x10}; unsigned char idata now_time[7]; unsigned char time_reload_flag = 0; //是否進(jìn)行時(shí)間設(shè)置標(biāo)志位 unsigned char idata YearNum[2]; unsigned char idata MonthNum[2]; unsigned char idata DayNum[2]; unsigned char idata WeekNum[1]; unsigned char idata HourNum[2]; unsigned char idata MinuteNum[2]; unsigned char idata SecondNum[2]; //函數(shù)功能: DS1302時(shí)間處理函數(shù),將鍵盤輸入的時(shí)間轉(zhuǎn)換成DS1302的格式 //入口參數(shù): 無 //出口參數(shù): 無 void Time_Process(void) { init_time[6] = YearNum[1] * 16 + YearNum[0]; // DS1302的時(shí)間格式為16進(jìn)制 init_time[5] = WeekNum[0]; init_time[4] = MonthNum[1] * 16 + MonthNum[0]; init_time[3] = DayNum[1] * 16 + DayNum[0]; init_time[2] = HourNum[1] * 16 + HourNum[0]; init_time[1] = MinuteNum[1] * 16 + MinuteNum[0]; init_time[0] = SecondNum[1] * 16 + SecondNum[0]; } //延時(shí)X微秒(STC12C5A60S2@12M) //不同的工作環(huán)境,需要調(diào)整此函數(shù) //此延時(shí)函數(shù)是使用1T的指令周期進(jìn)行計(jì)算,與傳統(tǒng)的12T的MCU不同 void Delay_ds1302() { _nop_(); _nop_(); } //函數(shù)功能: 從DS1302讀1字節(jié)數(shù)據(jù) //入口參數(shù):無 //出口參數(shù): 返回讀的數(shù)據(jù) unsigned char DS1302_ReadByte() { unsigned char i; unsigned char dat = 0; for (i=0; i<8; i++) //8位計(jì)數(shù)器 { SCLK = 0; //時(shí)鐘線拉低 Delay_ds1302(); //延時(shí)等待 dat >>= 1; //數(shù)據(jù)右移一位 if (IO) dat |= 0x80; //讀取數(shù)據(jù) SCLK = 1; //時(shí)鐘線拉高 Delay_ds1302(); //延時(shí)等待 } return dat; } //函數(shù)功能: 向DS1302寫1字節(jié)數(shù)據(jù) //入口參數(shù):寫的數(shù)據(jù) //出口參數(shù): 無 void DS1302_WriteByte(unsigned char dat) { unsigned char i; for (i=0; i<8; i++) //8位計(jì)數(shù)器 { SCLK = 0; //時(shí)鐘線拉低 Delay_ds1302(); //延時(shí)等待 dat >>= 1; //移出數(shù)據(jù) IO = CY; //送出到端口 SCLK = 1; //時(shí)鐘線拉高 Delay_ds1302(); //延時(shí)等待 } } //函數(shù)功能: 讀DS1302某地址的的數(shù)據(jù) //入口參數(shù):地址 //出口參數(shù): 數(shù)據(jù) unsigned char DS1302_ReadData(unsigned char addr) { unsigned char dat; RST = 0; Delay_ds1302(); SCLK = 0; Delay_ds1302(); RST = 1; Delay_ds1302(); DS1302_WriteByte(addr); //寫地址 dat = DS1302_ReadByte(); //讀數(shù)據(jù) SCLK = 1; RST = 0; return dat; } //函數(shù)功能: 往DS1302的某個(gè)地址寫入數(shù)據(jù) //入口參數(shù):地址 //出口參數(shù): 無 void DS1302_WriteData(unsigned char addr, unsigned char dat) { RST = 0; Delay_ds1302(); SCLK = 0; Delay_ds1302(); RST = 1; Delay_ds1302(); DS1302_WriteByte(addr); //寫地址 DS1302_WriteByte(dat); //寫數(shù)據(jù) SCLK = 1; RST = 0; } //函數(shù)功能: 寫入初始時(shí)間 //入口參數(shù):時(shí)間數(shù)組地址 //出口參數(shù): 無 void DS1302_SetTime(unsigned char *p) { unsigned char addr = 0x80; unsigned char n = 7; DS1302_WriteData(WRITE_PROTECT, 0x00); //允許寫操作 while (n--) { DS1302_WriteData(addr, *p++); addr += 2; } DS1302_WriteData(WRITE_PROTECT, 0x80); //寫保護(hù) } //函數(shù)功能: 讀時(shí)間 //入口參數(shù):時(shí)間數(shù)組地址 //出口參數(shù): 無 void DS1302_GetTime(unsigned char *p) { unsigned char addr = 0x81; unsigned char n = 7; while (n--) { *p++ = DS1302_ReadData(addr); addr += 2; } } //函數(shù)功能: 初始化DS1302 //入口參數(shù):時(shí)間數(shù)組地址 //出口參數(shù): 無 void DS1302_Initial() { RST = 0; SCLK = 0; DS1302_WriteData(WRITE_PROTECT, 0x00); //允許寫操作 // DS1302_WriteData(0x80, 0x00); //時(shí)鐘啟動(dòng) DS1302_WriteData(WRITE_CHARGING, 0xa6); //使能涓流充電,一個(gè)二極管+4K電阻充電 DS1302_WriteData(WRITE_PROTECT, 0x80); //寫保護(hù) } //函數(shù)功能: DS1302顯示函數(shù) //入口參數(shù): xposi,yposi //出口參數(shù): 無 void Disp_Time(unsigned char xposi, unsigned int yposi) { unsigned char shi, fen , miao, year, month, date, week; DS1302_GetTime(now_time); year = now_time[6]; // 獲取 年 Disp_12(xposi, yposi, NUMBIG[2]); Disp_12(xposi + 2, yposi, NUMBIG[0]); Disp_12(xposi + 4, yposi, NUMBIG[(year & 0xf0) >> 4]); //讀出來的year的高4位是存放年的十位的值,所以取高4位,然后右移4位,即是年的十位應(yīng)該顯示的數(shù)值? Disp_12(xposi + 6, yposi, NUMBIG[(year & 0x0f)]); //讀出來的year的低4位是存放年的個(gè)位的值 , Disp_24(xposi + 8, yposi, TIME[0]); month = now_time[4]; // 獲取 月 Disp_12(xposi + 12, yposi, NUMBIG[(month & 0xf0) >> 4]); Disp_12(xposi + 14, yposi, NUMBIG[(month & 0x0f)]); Disp_24(xposi + 16, yposi, TIME[1]); date = now_time[3]; // 獲取 日 Disp_12(xposi + 20, yposi, NUMBIG[(date & 0xf0) >> 4]); Disp_12(xposi + 22, yposi, NUMBIG[(date & 0x0f)]); Disp_24(xposi + 24, yposi, TIME[2]); week = now_time[5]; // 獲取 星期 Disp_24(xposi + 28, yposi, TIME[3]); Disp_24(xposi + 31, yposi, TIME[4]); Disp_24(xposi + 34, yposi, DAY[(week & 0x0f) - 1]); shi = now_time[2]; // 獲取 小時(shí) Disp_12(xposi + 39, yposi + 0, NUMBIG[(shi & 0xf0) >> 4]); Disp_12(xposi + 41, yposi + 0, NUMBIG[shi & 0x0f]); Disp_12(xposi + 43, yposi + 0, DOTT); fen = now_time[1]; // 獲取 分 Disp_12(xposi + 45, yposi + 0, NUMBIG[(fen & 0xf0) >> 4]); Disp_12(xposi + 47, yposi + 0, NUMBIG[fen & 0x0f]); Disp_12(xposi + 49, yposi + 0, DOTT); miao = now_time[0]; // 獲取 秒 Disp_12(xposi + 51, yposi + 0, NUMBIG[(miao & 0xf0) >> 4]); Disp_12(xposi + 53, yposi + 0, NUMBIG[miao & 0x0f]); }

回答者:jusck4848132016-08-22 00:00

DS 5相關(guān)問題

相關(guān)閱讀

DS 5頻道

報(bào)價(jià):21.99-34.59
級(jí)別:中型車
排量:1.6T 1.8T 
變速箱:-

車友關(guān)注

最新標(biāo)簽

按字母分類:
ABCDEFGHIJKLMNOPQRSTWXYZ0-9