~gabe/flashlight-firmware/anduril2

« back to all changes in this revision

Viewing changes to DrJones/MiniDrv/README

  • Committer: Selene Scriven
  • Date: 2015-09-14 19:23:29 UTC
  • mto: (153.1.18 tiny25)
  • mto: This revision was merged to the branch mainline in revision 156.
  • Revision ID: ubuntu@toykeeper.net-20150914192329-0ean5s8qpnnkdbub
updated to BLF-VLD 0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
MiniDrv - simple firmware (source code)
 
2
DrJones
 
3
Fri, 01/31/2014 - 18:21
 
4
 
 
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).
 
8
 
 
9
  //MiniDrv -- minimalistic driver firmware (no blinkies)  --  DrJones 2014
 
10
  #define F_CPU 4800000                    //use fuses  low:0x75  high:0xff
 
11
  #include <avr/io.h>
 
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
 
15
  int main() {
 
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
 
29
  }
 
30
 
 
31
Change modes and number of modes in the modes[]={...} line, just add, delete or
 
32
change values.
 
33
 
 
34
Choose between (classic) memory and no-memory by uncommenting one of those
 
35
lines near the end.
 
36
 
 
37
License: Free for registered BLF users.
 
38
 
 
39
Use low fuse 0x75 and high fuse 0xFF.