有谁会编DS1307+pic16f877 ,电子时钟

2019-03-25 19:43发布

有谁会编ds1307 +pic16f877?电子时钟的显示。     [ 本帖最后由 j_z 于 2011-2-20 16:29 编辑 ] 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
5条回答
daicheng
1楼-- · 2019-03-26 00:56
楼主可以自己写,有问题大家可以帮你,1307的操作只要你把pic16f877的I2C调试好,然后看看数据手册
应该没有问题
j_z
2楼-- · 2019-03-26 01:25
我i2c口的代码,但是不知道怎样 连到DS1307上. #include /* Function: I2CInit Return: Arguments: Description: Initialize I2C in master mode, Sets the required baudrate */ void I2CInit(void){ TRISC3 = 1; /* SDA and SCL as input pin */ TRISC4 = 1; /* these pins can be configured either i/p or o/p */ SSPSTAT |= 0x80; /* Slew rate disabled */ SSPCON = 0x28; /* SSPEN = 1, I2C Master mode, clock = FOSC/(4 * (SSPADD + 1)) */ SSPADD = 0x28; /* 100Khz @ 4Mhz Fosc */ } /* Function: I2CStart Return: Arguments: Description: Send a start condition on I2C Bus */ void I2CStart(){ SEN = 1; /* Start condition enabled */ while(SEN); /* automatically cleared by hardware */ /* wait for start condition to finish */ } /* Function: I2CStop Return: Arguments: Description: Send a stop condition on I2C Bus */ void I2CStop(){ PEN = 1; /* Stop condition enabled */ while(PEN); /* Wait for stop condition to finish */ /* PEN automatically cleared by hardware */ } /* Function: I2CRestart Return: Arguments: Description: Sends a repeated start condition on I2C Bus */ void I2CRestart(){ RSEN = 1; /* Repeated start enabled */ while(RSEN); /* wait for condition to finish */ } /* Function: I2CAck Return: Arguments: Description: Generates acknowledge for a transfer */ void I2CAck(){ ACKDT = 0; /* Acknowledge data bit, 0 = ACK */ ACKEN = 1; /* Ack data enabled */ while(ACKEN); /* wait for ack data to send on bus */ } /* Function: I2CNck Return: Arguments: Description: Generates Not-acknowledge for a transfer */ void I2CNak(){ ACKDT = 1; /* Acknowledge data bit, 1 = NAK */ ACKEN = 1; /* Ack data enabled */ while(ACKEN); /* wait for ack data to send on bus */ } /* Function: I2CWait Return: Arguments: Description: wait for transfer to finish */ void I2CWait(){ while ( ( SSPCON2 & 0x1F ) || ( SSPSTAT & 0x04 ) ); /* wait for any pending transfer */ } /* Function: I2CSend Return: Arguments: dat - 8-bit data to be sent on bus data can be either address/data byte Description: Send 8-bit data on I2C bus */ void I2CSend(unsigned char dat){ SSPBUF = dat; /* Move data to SSPBUF */ while(BF); /* wait till complete data is sent from buffer */ I2CWait(); /* wait for any pending transfer */ } /* Function: I2CRead Return: 8-bit data read from I2C bus Arguments: Description: read 8-bit data from I2C bus */ unsigned char I2CRead(void){ unsigned char temp; /* Reception works if transfer is initiated in read mode */ RCEN = 1; /* Enable data reception */ while(!BF); /* wait for buffer full */ temp = SSPBUF; /* Read serial buffer and store in temp register */ I2CWait(); /* wait to check any pending transfer */ return temp; /* Return the read data from bus */ } //============MAIN CODE===========// void main(){ /* Buffer where we will read/write our data */ unsigned char *I2CData; unsigned char RTCData[]={0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x09, 0x00}; I2CData=&RTCData; unsigned char i; /* Initialize I2C Port */ I2CInit(); /* Send Start condition */ I2CStart(); /* Send DS1307 slave address with write operation */ I2CSend(0xD0); /* Send subaddress 0x00, we are writing to this location */ I2CSend(0x00); /* Loop to write 8 bytes */ for(i=0;i<8;i++,I2CData++) { /* send I2C data one by one */ I2CSend(I2CData); } /* Send a stop condition - as transfer finishes */ I2CStop(); /* We will now read data from DS1307 */ /* Reading for a memory based device always starts with a dummy write */ /* Send a start condition */ I2CStart(); /* Send slave address with write */ I2CSend(0xD0); /* Send address for dummy write operation */ /* this address is actually where we are going to read from */ I2CSend(0x00); /* Send a repeated start, after a dummy write to start reading */ I2CRestart(); /* send slave address with read bit set */ I2CSend(0xD1); /* Loop to read 8 bytes from I2C slave */ for(i=8;i>0;i--) { /* read a byte */ I2CData = I2CRead(); /* ACK if its not the last byte to read */ /* if its the last byte then send a NAK */ if(i-1) I2CAck(); else I2CNak(); } /* Send stop */ I2CStop(); /* end of program */ while(1); } [ 本帖最后由 j_z 于 2011-2-20 16:34 编辑 ]
wanghongyang
3楼-- · 2019-03-26 01:27
LZ毕业设计题目?你是想找别人帮你做?
j_z
4楼-- · 2019-03-26 02:53
 精彩回答 2  元偷偷看……
jishuaihu
5楼-- · 2019-03-26 06:21
这种东西可以使用拿来主义,I2C代码都是开源的,多的是,但LZ不能什么也拿吧,直接要现成的啊

一周热门 更多>