Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include<avr/interrupt.h>
- #define LED 1
- #define LOW PORTB &= ~( 1 << LED )
- #define HIGH PORTB |= ( 1 << LED )
- uint16_t data[] = { 0x002, 0x14b, 0x100, 0x100, 0x04a, /*2nd part*/0x102, 0x04B, 0x000, 0x000, 0x14A};
- uint8_t DataIndex = 0;
- #define MAX_DATA_IDX (sizeof(data) / sizeof( uint16_t))
- uint8_t BitIndex = 0;
- uint16_t delay_bits = 100;
- ISR( TIMER1_COMPA_vect )
- {
- if( delay_bits )
- {
- if( delay_bits-- == 1 )
- {
- //start bit - low
- LOW;
- }
- else
- {
- HIGH;
- }
- return;
- }
- if( data[ DataIndex ] & ( 0x01 << BitIndex++ ) )
- {
- HIGH;
- }
- else
- {
- LOW;
- }
- if( BitIndex == 9 )
- {
- BitIndex = 0;
- delay_bits = 3;//delay between bytes
- if( ++DataIndex == MAX_DATA_IDX )
- {
- delay_bits = 100;
- DataIndex = 0;
- cli();//only single shot of bytes
- }
- }
- }
- static inline void initTimer1( void )
- {
- TCCR1 |= ( 1 << CTC1 ); // clear timer on compare match
- TCCR1 |= ( 1 << CS12 );// | ( 1 << CS11 );// | ( 1 << CS12 ) | ( 1 << CS11 ); //clock prescaler 8192
- OCR1C = 106; // compare match value
- TIMSK |= ( 1 << OCIE1A ); // enable compare match interrupt
- }
- int main()
- {
- DDRB |= ( 1 << LED );
- HIGH;
- initTimer1();
- sei(); // enable interrupts
- while( 1 )
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement