int main(void)
{
	DDRC |= WP | HOLD;	// Set WP, HOLD output
	PORTC |= WP|HOLD;	// Set WP, HOLD high
	
	SPI_MasterInit();	// Init SPI Master
	status_register_1 = Read_Status_Register();		// Read STATUS REGISTER
	
	/****** Programm 4 Databytes with Byte-Program Sequence ******/
	Enable_Write_Procedure();				// Enable a write process (Enable EWSR,WRSR and WREN)
	Byte_Program(0x00, 0x00, 0x00, 0xAA);	// Programm 1 databyte (AA) @ address 0x000000
	Enable_Write_Procedure();				// Enable a write process (Enable EWSR,WRSR and WREN)
	Byte_Program(0x00, 0x00, 0x01, 0xBB);	// Programm 1 databyte (BB) @ address 0x000001
	Enable_Write_Procedure();				// Enable a write process (Enable EWSR,WRSR and WREN)
	Byte_Program(0x00, 0x00, 0x02, 0xCC);	// Programm 1 databyte (CC) @ address 0x000002
	Enable_Write_Procedure();				// Enable a write process (Enable EWSR,WRSR and WREN)
	Byte_Program(0x00, 0x00, 0x03, 0xDD);	// Programm 1 databyte (DD) @ address 0x000003
	Write_Disable();						// Write disable WRDI
	
	/****** Read 4 Databytes with Read Sequence ******/
	PORTB &= ~CE; // CE = low (start communication)
	SPI_MasterTransmit(0x03);	// Send command 0x03 Read
	SPI_MasterTransmit(0x00);	// Send 1. Addressbyte (MSB first)
	SPI_MasterTransmit(0x00);	// Send 2. Addressbyte
	SPI_MasterTransmit(0x00);	// Send 3. Addressbyte
	SPI_MasterTransmit(0x00);	// Send Dummybyte
	data1 = SPI_SlaveReceive();	// Receive the value of data
	SPI_MasterTransmit(0x00);	// Send Dummybyte
	data2 = SPI_SlaveReceive(); // Receive the value of data
	SPI_MasterTransmit(0x00);	// Send Dummybyte
	data3 = SPI_SlaveReceive(); // Receive the value of data
	SPI_MasterTransmit(0x00);	// Send Dummybyte
	data4 = SPI_SlaveReceive(); // Receive the value of data
	PORTB |= CE;				// CE = high (end of communication)
	
	/****** Erase full memory array with Chip-Erase Sequence ******/
	Enable_Write_Procedure();	// Enable a write process (Enable EWSR,WRSR and WREN)
	Chip_Erase();				// Chip erase - Erase full memory array
	Write_Disable();			// Write disable WRDI
	status_register_2 = Read_Status_Register(); // Read STATUS REGISTER
	
	/****** Write 4 Databytes with Auto Address Increment AAI ******/
	Enable_Write_Procedure();						// Enable a write process (Enable EWSR,WRSR and WREN)
	status_register_3 = Read_Status_Register();		// Read STATUS REGISTER
	PORTB &= ~CE;				// CE = low (start communication)
	SPI_MasterTransmit(0xAD);	// Send command 0xAD Auto Address Increment (AAI)
	SPI_MasterTransmit(0x00);	// Send 1. Addressbyte (MSB first)
	SPI_MasterTransmit(0x00);	// Send 2. Addressbyte
	SPI_MasterTransmit(0x00);	// Send 3. Addressbyte
	SPI_MasterTransmit(0x01);	// Send 1. databyte
	SPI_MasterTransmit(0x02);	// Send 2. Databyte
	PORTB |= CE;				// CE = high (end of communication)
	_delay_us(10);				// Wait min. TBP (10us)
	PORTB &= ~CE;				// CE = low (start communication)
	SPI_MasterTransmit(0xAD);	// Send command 0xAD Auto Address Increment (AAI)
	SPI_MasterTransmit(0x03);	// Send 3. databyte
	SPI_MasterTransmit(0x04);	// Send 4. Databyte
	PORTB |= CE;				// CE = high (end of communication)
	_delay_us(10);				// Wait min. TBP (10us)
	Write_Disable();			// Write disable WRDI
	PORTB &= ~CE;				// CE = low (start communication)
	status_register_4 = Read_Status_Register(); // Read STATUS REGISTER
	
	/****** Read 4 Databytes with Read Sequence ******/
	PORTB &= ~CE;				// CE = low (start communication)
	SPI_MasterTransmit(0x03);	// Send command 0x03 Read
	SPI_MasterTransmit(0x00);	// Send 1. Addressbyte (MSB first)
	SPI_MasterTransmit(0x00);	// Send 2. Addressbyte
	SPI_MasterTransmit(0x00);	// Send 3. Addressbyte
	SPI_MasterTransmit(0x00);	// Send Dummybyte
	data1 = SPI_SlaveReceive(); // Receive the value of data
	SPI_MasterTransmit(0x00);	// Send Dummybyte
	data2 = SPI_SlaveReceive(); // Receive the value of data
	SPI_MasterTransmit(0x00);	// Send Dummybyte
	data3 = SPI_SlaveReceive(); // Receive the value of data
	SPI_MasterTransmit(0x00);	// Send Dummybyte
	data4 = SPI_SlaveReceive(); // Receive the value of data
	PORTB |= CE;				// CE = high (end of communication)
	
	while(1)
	{
		asm("NOP");
	}
}