本帖最后由 546758514 于 2012-12-28 12:46 编辑
- 编译时出现图片上的错误,求助各位大侠是什么原因?出错的是77-79、98-104、108-110行,估计是数组的错误,但我找不到有什么错误,程序如下:
- #include "ds1302.h"
- #include <reg52.h>
- #include<intrins.h>
- unsigned char time_buf1[8]={20,10,6,5,12,55,00,6};//空年月日时分秒周
- unsigned char time_buf[8];
- sbit SCLK=P1^7;
- sbit CE=P1^5;
- sbit DIO=P1^6;
- /*------------------------------------------------
- *名称:void Write_ds1302(uchar add,uchar dat)
- *功能:向DS1302指定地址写入一字节数据
- *说明:无返回值
- ------------------------------------------------*/
- void Write_ds1302(unsigned char add,unsigned char dat)
- {
- unsigned char i,temp;
- CE=0;
- SCLK=0;
- CE=1;
- for(i=8;i>0;i--)
- {
- SCLK=0;
- temp=add;
- DIO=(bit)(temp&0x01);
- add>>=1;
- SCLK=1;
- }
- for(i=8;i>0;i--)
- {
- SCLK=0;
- temp=dat;
- DIO=(bit)(temp&0x01);
- dat>>=1;
- SCLK=1;
- }
- CE=0;
- }
- /*------------------------------------------------
- *名称:void Write_ds1302(uchar add,uchar dat)
- *功能:从DS1302指定地址读出一字节数据
- *说明:有返回值
- ------------------------------------------------*/
- unsigned char Read_ds1302(unsigned char add)
- {
- unsigned char i,temp,dat;
- CE=0;
- SCLK=0;
- CE=1;
- for(i=8;i>0;i--)
- {
- SCLK=0;
- temp=add;
- DIO=(bit)(temp&0x01);
- add>>=1;
- SCLK=1;
- }
- for(i=8;i>0;i--)
- {
- SCLK=1;
- dat>>=1;
- if(DIO==1)
- dat|=0x80;
- SCLK=0;
- }
- CE=0;
- return dat;
- }
- /*------------------------------------------------
- 向DS1302写入时钟数据
- ------------------------------------------------*/
- void Ds1302_Write_Time(void)
- {
- unsigned char i,tmp;
- for(i=0;i<8;i++)
- { //BCD处理
- tmp=time_buf1[i]/10;
- time_buf[i]=time_buf1[i]%10;
- time_buf[i]=time_buf[i]+tmp*16
- }
- Write_ds1302(0x8e,0x00);//写保护关
- Write_ds1302(0x80,0x80);//暂停
- Write_ds1302(0x8c,time_buf[1]);
- Write_ds1302(0x88,time_buf[2]);
- Write_ds1302(0x86,time_buf[3]);
- Write_ds1302(0x84,time_buf[4]);
- Write_ds1302(0x82,time_buf[5]);
- Write_ds1302(0x80,time_buf[6]);
- Write_ds1302(0x8a,time_buf[7]);
- Write_ds1302(0x8e,0x80);//写保护开
- }
- /*------------------------------------------------
- 从DS1302读出时钟数据
- ------------------------------------------------*/
- void Ds1302_Read_Time(void)
- {
- unsigned char i,tmp;
- time_buf[1]=Read_ds1302(0x8c); //年
- time_buf[2]=Read_ds1302(0x88); //月
- time_buf[3]=Read_ds1302(0x86); //日
- time_buf[4]=Read_ds1302(0x84); //时
- time_buf[5]=Read_ds1302(0x82); //分
- time_buf[6]=(Read_ds1302(0x81))&0x7F;//秒
- time_buf[7]=Read_ds1302(0x8a); //周
- for(i=0;i<8;i++)
- { //BCD处理
- tmp=time_buf1[i]/10;
- time_buf[i]=time_buf1[i]%10;
- time_buf[i]=time_buf[i]+tmp*16;
- }
- }
复制代码
-
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>