سلام بر همگی
در برنامه زیر قصد دارم تا نحوه ی اتصال حافظه
EEPROM
را واسه شما توضیح بدم برنامه ی اون در کدویژن اینطوریه
#include <mega16.h>
#include <i2c.h>
#include <delay.h>
#asm
.equ__i2c_port=0x12 ;PORTD
.equ__sda_bit=4
.equ__scl_bit=3
#endasm
#define write_address_bus 160
#define read_address_bus 161
Void write_eeprom(unsigned char data,unsigned int address);
Unsigned char read _eeprom(unsigned int address);
Void main(void)
{
Unsigned char read_data,write_data;
Int I;
I2c_init();
Write_data=55;
For(i=0;i<100;i++)
Write_eeprom(write_data,i);
Read_data=read_eeprom(i);
}
While(1);
}
Void write_eeprom(unsigned char data,unsigned int address)
{
I2c_start();
I2c_write(write_address_bus);
I2c_write((address&0xff00)>>8);
I2c_write(address&0x00ff);
I2c_write(data);
I2c_stop();
Delay_ms(10);
}
Unsigned char read_eeprom(unsigned int address)
{
Unsigned char data_read;
I2c_start();
I2c_write(write_address_bus);
I2c_write((address & 0xff00)>>8);
I2c_write(address & 0x00ff);
I2c_start();
I2c_write(read_address_bus);
Data_read=i2c_read(0);
I2c_stop();
Return data_read;}
در برنامه زیر قصد دارم تا نحوه ی اتصال حافظه
EEPROM
را واسه شما توضیح بدم برنامه ی اون در کدویژن اینطوریه
#include <mega16.h>
#include <i2c.h>
#include <delay.h>
#asm
.equ__i2c_port=0x12 ;PORTD
.equ__sda_bit=4
.equ__scl_bit=3
#endasm
#define write_address_bus 160
#define read_address_bus 161
Void write_eeprom(unsigned char data,unsigned int address);
Unsigned char read _eeprom(unsigned int address);
Void main(void)
{
Unsigned char read_data,write_data;
Int I;
I2c_init();
Write_data=55;
For(i=0;i<100;i++)
Write_eeprom(write_data,i);
Read_data=read_eeprom(i);
}
While(1);
}
Void write_eeprom(unsigned char data,unsigned int address)
{
I2c_start();
I2c_write(write_address_bus);
I2c_write((address&0xff00)>>8);
I2c_write(address&0x00ff);
I2c_write(data);
I2c_stop();
Delay_ms(10);
}
Unsigned char read_eeprom(unsigned int address)
{
Unsigned char data_read;
I2c_start();
I2c_write(write_address_bus);
I2c_write((address & 0xff00)>>8);
I2c_write(address & 0x00ff);
I2c_start();
I2c_write(read_address_bus);
Data_read=i2c_read(0);
I2c_stop();
Return data_read;}