mod01 ex02 works
This commit is contained in:
@@ -72,7 +72,7 @@ int main() {
|
||||
// -> Table 16-4 : use bit WGM12 to set mode ctc
|
||||
// -> 16.11.2 : bit WGM12 is located in register TCCR1B
|
||||
|
||||
TCCR1A |= (1 << COM1A0 ) ; // Enable timer 1 Compare Output channel A in toggle mode
|
||||
TCCR1A |= (1 << COM1A0); // enable timer 1 Compare Output channel A in toggle mode
|
||||
// -> Table 14-3 : alternate functions for PORTB1 is OC1A (Timer/Counter1 Output Compare Match A Output)
|
||||
// -> 14.3.1 : OC1A/PCINT1 – Port B, Bit 1
|
||||
|
||||
|
||||
@@ -48,12 +48,47 @@
|
||||
#define BUTTON1 (D, SW1)
|
||||
#define BUTTON2 (D, SW2)
|
||||
|
||||
// TIME
|
||||
#define PRESCALE_VALUE 1024
|
||||
#if (PRESCALE_VALUE == 1)
|
||||
#define PRESCALE_SET (1 << CS10)
|
||||
#elif (PRESCALE_VALUE == 8)
|
||||
#define PRESCALE_SET (1 << CS11)
|
||||
#elif (PRESCALE_VALUE == 64)
|
||||
#define PRESCALE_SET (1 << CS10) | (1 << CS11)
|
||||
#elif (PRESCALE_VALUE == 256)
|
||||
#define PRESCALE_SET (1 << CS12)
|
||||
#elif (PRESCALE_VALUE == 1024)
|
||||
#define PRESCALE_SET (1 << CS10) | (1 << CS12)
|
||||
#endif
|
||||
#define TIME_MS(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000)
|
||||
#define PERIOD 1000
|
||||
#define DUTY_CYCLE 10
|
||||
|
||||
// END MACROS
|
||||
|
||||
int main()
|
||||
{
|
||||
MODE_OUTPUT(LED1);
|
||||
SET_ELEM(LED1);
|
||||
|
||||
return 0;
|
||||
int main() {
|
||||
MODE_OUTPUT(LED2);
|
||||
|
||||
// Table 16-4 : set timer in Fast PWM (Pulse With Modulation) mode with TOP = ICR1 (Mode 14)
|
||||
SET(TCCR1A, WGM11);
|
||||
SET(TCCR1B, WGM12);
|
||||
SET(TCCR1B, WGM13);
|
||||
|
||||
// Table 16-2 : Non-inverting mode, the LED will be ON for DUTY_CYCLE% of the time (CLEAR OC1A on compare match, SET OC1A at BOTTOM)
|
||||
SET(TCCR1A, COM1A1);
|
||||
|
||||
// set the period (compare TOP value)
|
||||
ICR1 = TIME_MS(PERIOD);
|
||||
|
||||
// set the duty cycle to DUTY_CYCLE% of the time
|
||||
OCR1A = TIME_MS(DUTY_CYCLE);
|
||||
|
||||
// start the timer with the prescaler
|
||||
TCCR1B |= (PRESCALE_SET);
|
||||
|
||||
while(1) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user