#include ‹mega8.h›
#include ‹delay.h›
// 1 Wire Bus functions
#asm
.equ __w1_port=0x15 ;PORTC
.equ __w1_bit=2
#endasm
#include ‹1wire.h›
// DS2430 EEPROM functions
#include ‹ds2430.h›
#include ‹stdio.h›
// Declare your global variables here
#define MAX_DEVICES 8
unsigned char rom_code[MAX_DEVICES][9];
char text[]="Hello world!";
char buffer[32];
#define START_ADDR 2
void main(void)
{
// Declare your local variables here
unsigned char i,devices;
// Input/Output Ports initialization
// Port B initialization
PORTB=0x00;DDRB=0xFF;
// Port C initialization
PORTC=0x00;DDRC=0x07;
// Port D initialization
PORTD=0x00;DDRD=0xF7;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600 (Double Speed Mode)
UCSRA=0x02;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x0C;
// 1-Wire Bus initialization
w1_init();
// detect how many 1 Wire devices are present on the bus
devices=w1_search(0xF0,&rom_code[0][0]);
printf("%-u 1 Wire devices found\n\r",devices);
for (i=0;i‹devices;i++)
// make sure to select only the DS2430 types 0x14 is the DS2430 family code
if (rom_code[i][0]==DS2430_FAMILY_CODE)
{
printf("\n\r");
// write text in each DS2430 at START_ADDR
if (ds2430_write_block(&rom_code[i][0],text,START_ADDR,sizeof(text)))
{
printf("Data written OK in DS2430 #%-u!\n\r",i+1);
// display the text written in each DS2430
if (ds2430_read_block(&rom_code[i][0],buffer,START_ADDR,sizeof(text)))
printf("Data read OK!\n\rDS2430 #%-u text: %s\n\r",i+1,buffer);
else printf("Error reading data from DS2430 #%-u!\n\r",i+1);
}
else printf("Error writing data to DS2430 #%-u!\n\r",i+1);
};
// stop
while (1) {};
}; |