Advertisement
Guest User

M680 power on + full volume

a guest
Aug 17th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include<avr/interrupt.h>
  3.  
  4. #define LED 1
  5.  
  6. #define LOW PORTB &= ~( 1 << LED )
  7. #define HIGH PORTB |= ( 1 << LED )
  8.  
  9. uint16_t data[] = { 0x002, 0x14b, 0x100, 0x100, 0x04a, /*2nd part*/0x102, 0x04B, 0x000, 0x000, 0x14A};
  10. uint8_t DataIndex = 0;
  11. #define MAX_DATA_IDX (sizeof(data) / sizeof( uint16_t))
  12.  
  13. uint8_t BitIndex = 0;
  14.  
  15. uint16_t delay_bits = 100;
  16.  
  17. ISR( TIMER1_COMPA_vect )
  18. {
  19.     if( delay_bits )
  20.     {
  21.         if( delay_bits-- == 1 )
  22.         {
  23.             //start bit - low
  24.             LOW;
  25.         }
  26.         else
  27.         {
  28.             HIGH;
  29.         }
  30.         return;
  31.     }
  32.  
  33.     if( data[ DataIndex ] & ( 0x01 << BitIndex++ ) )
  34.     {
  35.         HIGH;
  36.     }
  37.     else
  38.     {
  39.         LOW;
  40.     }
  41.     if( BitIndex == 9 )
  42.     {
  43.         BitIndex = 0;
  44.         delay_bits = 3;//delay between bytes
  45.         if( ++DataIndex == MAX_DATA_IDX )
  46.         {
  47.             delay_bits = 100;
  48.             DataIndex = 0;
  49.             cli();//only single shot of bytes
  50.         }
  51.     }
  52. }
  53.  
  54. static inline void initTimer1( void )
  55. {
  56.     TCCR1 |= ( 1 << CTC1 );  // clear timer on compare match
  57.     TCCR1 |= ( 1 << CS12 );// | ( 1 << CS11 );// | ( 1 << CS12 ) | ( 1 << CS11 ); //clock prescaler 8192
  58.     OCR1C = 106; // compare match value
  59.     TIMSK |= ( 1 << OCIE1A ); // enable compare match interrupt
  60. }
  61.  
  62. int main()
  63. {
  64.     DDRB |= ( 1 << LED );
  65.     HIGH;
  66.     initTimer1();
  67.     sei();               // enable interrupts
  68.     while( 1 )
  69.     {
  70.     }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement