Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * CAN.c
- *
- * Created: 06/12/2011 11:19:04
- * Author: saintamand03
- */
- #include <avr/io.h>
- void USART_Init( unsigned int baudrate );
- unsigned char USART_Receive( void );
- void USART_Transmit( unsigned char data );
- int CAN_CONVERSION();
- void CAN_INIT();
- int main(void)
- {
- while(1)
- {
- //TODO:: Please write your application code
- }
- }
- void CAN_INIT()
- {
- ADMUX=((1<<REFS1)|(1<<REFS0)|(1<<ADLAR));
- ADCSRA=((1<<ADEN)|(1<<ADPS2)|(1<<ADPS1));
- }
- int CAN_CONVERSION()
- {
- ADCSRA=(1<<ADSC);
- while (ADSC=1)
- ;
- return(ADCH);
- }
- /* Initialize UART */
- void USART_Init( unsigned int baudrate )
- {
- /* Set the baud rate */
- UBRR0H = (unsigned char) (baudrate>>8);
- UBRR0L = (unsigned char) baudrate;
- /* RAZ du registre de controle A */
- UCSR0A = 0x00 ;
- /* Enable UART receiver and transmitter */
- UCSR0B = ( ( 1 << RXEN0 ) | ( 1 << TXEN0 ) );
- /* Set frame format: 8 data 2stop */
- UCSR0C = (1<<USBS0)|(1<<UCSZ01)|(1<<UCSZ00);
- }
- /* Read and write functions */
- unsigned char USART_Receive( void )
- {
- /* Wait for incomming data */
- while ( !(UCSR0A & (1<<RXC0)) )
- ;
- /* Return the data */
- return UDR0;
- }
- void USART_Transmit( unsigned char data )
- {
- /* Wait for empty transmit buffer */
- while ( !(UCSR0A & (1<<UDRE0)) )
- ;
- /* Start transmittion */
- UDR0 = data;
- }
Add Comment
Please, Sign In to add comment