Operácie

AVR ExamplePWMgenerator.c: Rozdiel medzi revíziami

Z SensorWiki

Riadok 19: Riadok 19:
 
int main(void) {
 
int main(void) {
  
   /* *********************** Init device MiniMEXLE ******************************** */
+
   /* *********************** Init device ******************************** */
  
     DDRB = 0b00000000;      // PORTB: PWM - PB1, PB2 (LED)  is output, PB6, 7 IN!!!
+
     DDRB = 0b00000000;      //  
   PORTB = 0b00000000;      // LED Active low, LED off, No pull-ups
+
   PORTB = 0b00000000;      //  
  
     DDRC = 0b00000000;      // PORTC LED on PC5  is output, SW1-4 are inputs
+
     DDRC = 0b00000000;      //  
   PORTC = 0b0000000;      // LED Active high, LED off, pull-ups ON
+
   PORTC = 0b00000000;      //  
  
 
   /* *********************** Init T1 as a PWM generator *************************** */
 
   /* *********************** Init T1 as a PWM generator *************************** */
Riadok 36: Riadok 36:
 
                
 
                
  
for (;;) {
+
for (;;);
      if( bit_is_clear(PINC, SW1)) {  // Switch 1
+
          
              OCR1A += 32;                    // Increment OCR
 
              OCR1B += 32;
 
              loop_until_bit_is_set(PINC, SW1);
 
                }
 
       
 
      if(bit_is_clear(PINC, SW2)){  // Switch 2
 
              OCR1A -= 32;                  // Decrement OCR
 
        OCR1B -= 32;
 
              loop_until_bit_is_set(PINC, SW2);
 
                }
 
 
 
              if(bit_is_clear(PINC, SW3)){  // Switch 3
 
              PORTC |= (1<<RedLED);         // Red LED ON
 
              loop_until_bit_is_set(PINC, SW3);
 
                }
 
 
 
              if(bit_is_clear(PINC, SW4)) {  // Switch 4
 
              PORTC &= ~(1<<RedLED);        // Red LED OFF
 
      loop_until_bit_is_set(PINC, SW4);
 
                }
 
          }
 
  
 
}
 
}

Verzia zo dňa a času 07:37, 3. november 2011

/* ******************************************************** */
/* Example 10.1. Timer counter 1 as a PWM generator         */
/* Modulates LED connected on PB5, SW1 and SW2 changes duty */
/* SW3 and 4 control the red LED                            */
/* Warning: The values are NOT CORRECT, they should be re-  */
/*          placed by students themselves!!!                */
/* ******************************************************** */

#include <avr\io.h>

#define SW1 0
#define SW2 1
#define SW3 2
#define SW4 3

#define RedLED 5

int main(void) {

  /* *********************** Init device ******************************** */

    DDRB = 0b00000000;       // 
   PORTB = 0b00000000;       // 

    DDRC = 0b00000000;       // 
   PORTC = 0b00000000;       // 

  /* *********************** Init T1 as a PWM generator *************************** */

  TCCR1A = 0b00000000;       // Mode: PWM, Phase Correct, 9-bit
  TCCR1B = 0b00000000;       // Prescaler 1:1024
   OCR1A = 000;              // Initialization values          
   OCR1B = 000;              // for 1:1 duty cycle
   TCNT1 = 0;           
              

for (;;);
         

}

Návrat na cvičenie...