00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #define Usart_spi_hard_init() (PORTD |= 0x2C, DDRD |= 0x28, DDRD &= ~0x04)
00014 #define Usart_hard_init_without_ctrl() (PORTD |= 0x0C, DDRD |= 0x08, DDRD &= ~0x04)
00015 #define Usart_hard_init_with_ctrl() (PORTD |= 0xCC, DDRD |= 0x48, DDRD &= ~0x84)
00016
00017
00018 #define Usart_spi_soft_init() (UBRR1 = 0, \
00019 UCSR1C = (1<<7)|(1<<6)|(1<<1)|(1<<0), \
00020 UCSR1B = (1<<3)|(1<<4), \
00021 UBRR1 = 4) // baudrate = 800kbits/s
00022 #define Usart_soft_init_with_ctrl() (UBRR1 = 0, \
00023 UCSR1C = (1<<UCSZ11) | (1<<UCSZ10), \
00024 UCSR1D = (1<<CTSEN) | (1<<RTSEN), \
00025 UCSR1B = (1<<RXEN1) | (1<<TXEN1), \
00026 UBRR1 = 9) // baudrate = 50kbits/s
00027
00028
00029 #define Usart_soft_init_without_ctrl() (UBRR1 = 0, \
00030 UCSR1C = (1<<UCSZ11) | (1<<UCSZ10), \
00031 UCSR1D &= ~((1<<CTSEN) | (1<<RTSEN)), \
00032 UCSR1B = (1<<RXEN1) | (1<<TXEN1), \
00033 UBRR1 = 4) // baudrate = 100kbits/s
00034
00035 #define Usart_write_byte(dt) (UDR1 = dt)
00036 #define Usart_read_byte() (UDR1)
00037 #define Is_usart_byte_sent() (((UCSR1A&(1<<TXC1)) != 0) ? TRUE : FALSE)
00038 #define Usart_clear_flag_send() (UCSR1A |= (1<<TXC1))
00039 #define Is_usart_byte_received() (((UCSR1A&(1<<RXC1)) != 0) ? TRUE : FALSE)
00040 #define Usart_clear_flag_receive() (UCSR1A |= (1<<RXC1))
00041 #define Is_usart_data_reg_empty() (((UCSR1A&(1<<UDRE1)) != 0) ? TRUE : FALSE)
00042
00043
00044
00045
00046 #define Delay_config_ms(ms) (Timer16_set_clock(TIMER16_CLKIO_BY_256), \
00047 Timer16_set_mode_output_a(TIMER16_COMP_MODE_NORMAL), \
00048 Timer16_set_waveform_mode(TIMER16_WGM_CTC_OCR), \
00049 Timer16_set_compare_a((U16)(31)*(U16)(ms)))
00050 #define Delay_config_us(us) (Timer16_set_clock(TIMER16_CLKIO_BY_8), \
00051 Timer16_set_mode_output_a(TIMER16_COMP_MODE_NORMAL), \
00052 Timer16_set_waveform_mode(TIMER16_WGM_CTC_OCR), \
00053 Timer16_set_compare_a((U16)(us)))
00054
00055 #define Delay_reset() (Timer16_set_counter(0x0000), Timer16_clear_compare_a_it())
00056 #define Is_delay_end() (Timer16_get_compare_a_it())
00057 #define Is_not_delay_end() (!(Timer16_get_compare_a_it()))
00058
00059
00060
00061
00062 #define Bp_delay_debounce() { Delay_config_ms(20); Delay_reset(); while (Is_not_delay_end());}
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077