firmware/main.c

changeset 1
d224ff5c155b
parent 0
bdcf2c76d86e
child 2
114e1283d03a
equal deleted inserted replaced
0:bdcf2c76d86e 1:d224ff5c155b
49 49
50 50
51 TCCR1A = (1<<WGM10)|(1<<COM1A1) // Set up the two Control registers of Timer1. 51 TCCR1A = (1<<WGM10)|(1<<COM1A1) // Set up the two Control registers of Timer1.
52 |(1<<COM1B1); // Wave Form Generation is Fast PWM 8 Bit, 52 |(1<<COM1B1); // Wave Form Generation is Fast PWM 8 Bit,
53 TCCR1B = (1<<WGM12) // OC1A and OC1B are cleared on compare match 53 TCCR1B = (1<<WGM12) // OC1A and OC1B are cleared on compare match
54 |(1<<CS10); // and set at BOTTOM. Clock Prescaler is 1024. 54 |(1<<CS11); // and set at BOTTOM. Clock Prescaler is 1024.
55 55
56 56
57 uint8_t i; 57 uint8_t i;
58 for(i = 0; i<5; i++) { 58 for(i = 0; i<5; i++) {
59 led(i); 59 led(i);
72 void pwm_update(void) { 72 void pwm_update(void) {
73 PORTB |= _BV(0); // switch on led driver 73 PORTB |= _BV(0); // switch on led driver
74 74
75 switch (mode) { 75 switch (mode) {
76 case 1: 76 case 1:
77 OCR1A = 63; // Dutycycle of OC1A = 25% 77 OCR1A = 40; // Dutycycle of OC1A = 25%
78 break; 78 break;
79 case 2: 79 case 2:
80 OCR1A = 127; // Dutycycle of OC1A = 50% 80 OCR1A = 110; // Dutycycle of OC1A = 50%
81 break; 81 break;
82 case 3: 82 case 3:
83 OCR1A = 189; // Dutycycle of OC1A = 75% 83 OCR1A = 160; // Dutycycle of OC1A = 75%
84 break; 84 break;
85 case 4: 85 case 4:
86 OCR1A = 255; // Dutycycle of OC1A = 100% 86 OCR1A = 255; // Dutycycle of OC1A = 100%
87 break; 87 break;
88 default: 88 default:
109 key_last = tmp; 109 key_last = tmp;
110 if (tmp) { 110 if (tmp) {
111 if (mode < 4) { 111 if (mode < 4) {
112 mode++; 112 mode++;
113 } else { 113 } else {
114 mode = 1; 114 mode = 0;
115 } 115 }
116 led(mode); 116 led(mode);
117 pwm_update(); 117 pwm_update();
118 _delay_ms(50); 118 _delay_ms(50);
119 _delay_ms(50); 119 _delay_ms(50);

mercurial