1
MiniDrv - simple firmware (source code)
3
Fri, 01/31/2014 - 18:21
5
Someone recently asked me for a simple firmware, easy to understand, so I wrote
6
this firmware, and thought I could share it. I named it MiniDrv (as in
7
minimalistic driver) - it only has 18 lines of code (not counting comments).
9
//MiniDrv -- minimalistic driver firmware (no blinkies) -- DrJones 2014
10
#define F_CPU 4800000 //use fuses low:0x75 high:0xff
12
#include <util/delay.h>
13
//change modes here; just change/add/delete values
14
uint8_t modes[]={8,90,255}; //PWM values, 5..255
16
DDRB=2; //define PB1 as output
17
TCCR0A=0b00100001; TCCR0B=0b00000001; //PWM setup, 9kHz
18
EEARL=4;EECR=1; uint8_t mode=EEDR; //read from EEPROM
19
if (mode>=sizeof(modes)) mode=0; //check if invalid
20
OCR0B=modes[mode]; //set PWM level
21
EEDR=mode+1; //next mode
22
if(EEDR>=sizeof(modes)) EEDR=0;
23
EECR=4;EECR=4+2; while(EECR&2); //write to EEPROM
24
_delay_ms(1000); //delay for memory (or nomemory) to kick in
25
EEDR=mode; //memory: use this mode again \ use one of these lines
26
//EEDR=0; //no memory: restart from 0 / use one of these lines
27
EECR=4;EECR=4+2; while(EECR&2); //write to EEPROM
28
while(1) {} //endless loop
31
Change modes and number of modes in the modes[]={...} line, just add, delete or
34
Choose between (classic) memory and no-memory by uncommenting one of those
37
License: Free for registered BLF users.
39
Use low fuse 0x75 and high fuse 0xFF.