i 'm trying to run ds1307 with software i2c .after so much effort i could do it.but there is a thing which is unsolved for me ,and it's that i don't understand why should i use restart instruction to get the result(instead of using start)? and by the way , it 's good to know that in MPLAB_C18_Libraries.pdf example for sw_i2c it started with SWStartI2C(); (not SWRestartI2C();).
so why?should we always use SWRestartI2C(); at first? or it is only for ds1307?
ps:the code bellow ,make a 1 Hz wave on out pin.
- Code: Select all
#include <P18f4550.h>
#include <stdio.h>
#include <stdlib.h>
#include <delays.h>
#include "sw_i2c.h"
//*****************************************
#pragma config WDT=OFF
#pragma config FOSC=HS// our crystal is 4 MHZ
#pragma config CPUDIV=OSC1_PLL2
#pragma config LVP=OFF
//*****************************************
unsigned char var=0;
//***************************************
void main(void)
{
ADCON1=0X0F; //All analog port are digitaled
SWRestartI2C();
//SWStartI2C(); //with this code it didn't work!!
var=SWPutcI2C(0xD0);// control byte
SWAckI2C();
var=SWPutcI2C(0x07); // word address
SWAckI2C();
var=SWPutcI2C(0x10); // data
SWAckI2C();
SWStopI2C();
}