Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/25/06 04:31
Read: times


 
#114963 - I2C program and controller
Responding to: ???'s previous message
Hi,
Sorry for the delay in responding your question Erik sir. The microcontroller used in my project is C8051F120. Then, I’m unable to understand your question.’ derivative or deviate?’

void main(void)
{
SFRPAGE=LEGACY_PAGE;
WDTCN = 0xde; // disable watchdog timer
WDTCN = 0xad;

SYSCLK_Init(); // turn on the external oscillator

SFRPAGE = CONFIG_PAGE;
XBR0 = 0x01; // Route SMBus to GPIO pins through crossbar
XBR2 = 0x40; // Enable crossbar and weak pull-ups
P7MDOUT = 0x1f; // enable (P7^0,^1,^2,^3,^4)as push pull-LCD control lines
// P0MDOUT = 0x03;

// SFRPAGE = SMB0_PAGE;
// SMB0CN = 0x40; // Enable SMBus with acknowledge low (AA = 1)
// SMB0CR = -245; // SMBus clock rate = 100 kHz
// SMB0ADR = ADDRTC; // Set own slave address.

EA = 1; // Global interrupt enable
// EIE1 |= 0x02; // SMBus interrupt enable

sqw = 1; // set up for read, weak pull-up

while (1)
{
initialize();
disp_clk_regs(0x00); //To display seconds
writebyte(0x20,0x50);
readbyte(0x20);
}
}


void I2C_start()
{
sda = 1;
scl = 1; // Initiate start condition
sda = 0;
}

void I2C_stop()
{
sda = 0;
sda = 0;
sda = 0;
sda = 0; // Initiate stop condition
scl = 1;
scl = 1;
sda = 1;
}

void I2C_write(unsigned char d)
{
unsigned char i;

scl = 0;
for (i = 1; i <= 8; i++)
{
sda = (d >> 7);
scl = 1;
d = d << 1; // increase scl high time
scl = 0;
}
sda = 1; // Release the sda line
scl = 0;
scl = 1;
if(sda)
//Display 'ACK bit missing' in the lcd
scl = 0;
}

unsigned char I2C_read(unsigned char b)
{
unsigned char d, i;

sda = 1; // Let go of sda line
scl = 0;
for (i = 1; i <= 8; i++) // read the msb first
{
scl = 1;
d = d << 1;
d = d | (unsigned char)sda;
scl = 0;
}
sda = b; // Hold sda low for acknowledge

scl = 0;
scl = 1;
if(b == NACK)
sda = 1; // sda = 1 if next cycle is reset
scl = 0;

sda = 1; // Release the sda line
return d;
}

void readbyte(char Add)
{
I2C_start();
I2C_write(ADDRTC);
I2C_write(Add); // 'Add' = Address containing the data to be read
I2C_start();
I2C_write(ADDRTC | 1);
a=I2C_read(NACK);
//display the value in the 'a' variable
I2C_read(NACK);
I2C_stop();
}

void writebyte(char Add,char Data) /* -- write one byte of data to the specified address -- */
{
I2C_start();
I2C_write(ADDRTC);
I2C_write(Add); //'Add'= Address in which the data is to be written
I2C_write(Data); //'Data'=Data to be written in the specified address
I2C_stop();
}

Then, I want to know whether the SMBus peripheral is to be enabled for this RTC interfacing. Also, tell the changes to be done in the program.



List of 23 messages in thread
TopicAuthorDate
How to enable the oscillator in RTC?            01/01/70 00:00      
   I2C Code            01/01/70 00:00      
   SMBus include SCL and SDA lines            01/01/70 00:00      
      derivative or deviate?            01/01/70 00:00      
      I2C RTC            01/01/70 00:00      
         be careful            01/01/70 00:00      
   I2C program and controller            01/01/70 00:00      
      since you are using a derivative (F120)            01/01/70 00:00      
         I used the Code Architect....Erik Sir,            01/01/70 00:00      
            Lost in confusion.            01/01/70 00:00      
               the confooosion is ...            01/01/70 00:00      
   To display time            01/01/70 00:00      
      is reading that tough, evidently it must            01/01/70 00:00      
   I2C RTC Interfacing with 8051            01/01/70 00:00      
      horsefeathers            01/01/70 00:00      
   My position in this I2C RTC....            01/01/70 00:00      
      yes, after 15 minutes            01/01/70 00:00      
      Three issues            01/01/70 00:00      
   yes,after 15 minutes...            01/01/70 00:00      
      More specifically....            01/01/70 00:00      
      use the debugger            01/01/70 00:00      
   Thank you ...            01/01/70 00:00      
      Persistance wins again            01/01/70 00:00      

Back to Subject List