Generate a PWM signal for the display
Generate a variable duty cycle PWM signal for the dimmable display backlight at a frequency of 1.25kHz. For demo und testing purposes PD5 is currently fading between 0 and 100%.
This commit is contained in:
commit
0065fb630f
3 changed files with 75 additions and 0 deletions
31
firmware/src/main.c
Normal file
31
firmware/src/main.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#define F_CPU 8000000UL
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int main(void) {
|
||||
// FastPWM: 1.25kHz
|
||||
TCCR0A = (1 << WGM01) | (1 << WGM00) | (1 << COM0B1);
|
||||
TCCR0B = (1 << CS01) | (1 << WGM02); // prescaler = 8;
|
||||
OCR0A = 100;
|
||||
OCR0B = 10;
|
||||
DDRD |= (1 << PD5);
|
||||
|
||||
bool reverse = 0;
|
||||
|
||||
while (1) {
|
||||
_delay_ms(1);
|
||||
|
||||
if (OCR0B > 100)
|
||||
reverse = !reverse;
|
||||
|
||||
if (reverse)
|
||||
OCR0B++;
|
||||
else
|
||||
if (OCR0B > 0)
|
||||
OCR0B--;
|
||||
else
|
||||
reverse = !reverse;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue