Листинг для SPI
- Код: Выделить всё • Развернуть
void SPI_MasterInit(void)
{
DDRB = (1<<DDB5)|(1<<DDB7)
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
}
void SPI_MasterTransmit(char cData)
{
SPDR = cData;
while(!(SPSR & (1<<SPIF)))
;
}
void SPI_SlaveInit(void)
{
DDRB = (1<<DDB6);
/* Enable SPI */
SPCR = (1<<SPE);
}
char SPI_SlaveReceive(void)
{
while(!(SPSR & (1<<SPIF)))
;
return SPDR;
}
void main()
{
SPI_SlaveInit();
while (1)
{
char vh = SPI_SlaveReceive();
eeprom_write(0x00, vh);
}
}
Листинг для UART
- Код: Выделить всё • Развернуть
void USART_Init( unsigned int baud )
{
UBRRH0 = (unsigned char)(baud>>8);
UBRRL0 = (unsigned char)baud;
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
/* Set frame format: 8data, 2stop bit */
UCSR0C = (1<<USBS0)|(3<<UCSZ00);
}
void USART_Transmit( unsigned char data )
{
while ( !( UCSR0A & (1<<UDRE0)) )
;
UDR0 = data;
}
unsigned char USART_Receive( void )
{
while ( !(UCSR0A & (1<<RXC0)) )
;
return UDR0;
}
void main()
{
USART_Init(9600);
while (1)
{
char vh = USART_Receive();
eeprom_write(0x00, vh);
}
}