Home

Selasa, 06 April 2010 di 03.20 |  
/*****************************************************
Project : I2C Example program
Version : 1.0
Date : 2/21/2005
Author : Wildani Mufadhol
Company : Pens-ITS

Chip type : ATMega16
Program type : Application
Clock frequency : 4.0000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 128
*****************************************************/

#include

#include
#include
#include


#asm
.equ __i2c_port=0x18 ;PORTB //setting bit i2c
.equ __sda_bit=7
.equ __scl_bit=6
#endasm




#define EEPROM_ADDR 0xA0 //alamat eeprom (lihat datasheet)

//jumlah alamat tergantung ic (lihat datasheet)

unsigned char read_EEPROM(unsigned char alamat}
unsigned char data;
i2c_start();
i2c_write(EEPROM_ADDR);
i2c_write(alamat);
i2c_start();
i2c_write(EEPROM_ADDR | 1);
data = i2c_read(0);
i2c_stop();
return data;
}

void write_EEPROM(unsigned char alamat, unsigned char nilai){
i2c_start();
i2c_write(EEPROM_ADDR);
i2c_write(alamat);
i2c_write(nilai);
i2c_stop();
delay_ms(10);
}

void main(void){

PORTA=0x00;
DDRA=0xff;
unsigned char i;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x4D;

i2c_init();

write_EEPROM(0x00,0x00);
i=read_EEPROM(0x00);

while (1){

PORTA=i;

}
}

Diposkan oleh AF_Dhol Group

0 komentar:

Selasa, 06 April 2010

Mengisi EEPROM Serial pada CVAVR

/*****************************************************
Project : I2C Example program
Version : 1.0
Date : 2/21/2005
Author : Wildani Mufadhol
Company : Pens-ITS

Chip type : ATMega16
Program type : Application
Clock frequency : 4.0000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 128
*****************************************************/

#include

#include
#include
#include


#asm
.equ __i2c_port=0x18 ;PORTB //setting bit i2c
.equ __sda_bit=7
.equ __scl_bit=6
#endasm




#define EEPROM_ADDR 0xA0 //alamat eeprom (lihat datasheet)

//jumlah alamat tergantung ic (lihat datasheet)

unsigned char read_EEPROM(unsigned char alamat}
unsigned char data;
i2c_start();
i2c_write(EEPROM_ADDR);
i2c_write(alamat);
i2c_start();
i2c_write(EEPROM_ADDR | 1);
data = i2c_read(0);
i2c_stop();
return data;
}

void write_EEPROM(unsigned char alamat, unsigned char nilai){
i2c_start();
i2c_write(EEPROM_ADDR);
i2c_write(alamat);
i2c_write(nilai);
i2c_stop();
delay_ms(10);
}

void main(void){

PORTA=0x00;
DDRA=0xff;
unsigned char i;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x4D;

i2c_init();

write_EEPROM(0x00,0x00);
i=read_EEPROM(0x00);

while (1){

PORTA=i;

}
}

Tidak ada komentar:

Poskan Komentar

Visit the Site
MARVEL and SPIDER-MAN: TM & 2007 Marvel Characters, Inc. Motion Picture © 2007 Columbia Pictures Industries, Inc. All Rights Reserved. 2007 Sony Pictures Digital Inc. All rights reserved. blogger templates.
Distributed by Deluxe Templates