Add ATTiny24 single-LED experiment firmware
This commit is contained in:
commit
77f8009b39
6 changed files with 209 additions and 0 deletions
8
tn24/src/config.h
Normal file
8
tn24/src/config.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef CONFIG_H_
|
||||
#define CONFIG_H_
|
||||
|
||||
#define F_CPU 128000UL
|
||||
|
||||
#define MAX_DELAY 600
|
||||
|
||||
#endif
|
94
tn24/src/main.c
Normal file
94
tn24/src/main.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
#include "main.h"
|
||||
|
||||
uint16_t RCounter;
|
||||
uint16_t GCounter;
|
||||
uint16_t BCounter;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
DDRA = 0;
|
||||
DDRB = 0;
|
||||
PORTA = 0;
|
||||
PORTB = 0;
|
||||
|
||||
D_LEDR |= (1 << P_LEDR);
|
||||
D_LEDG |= (1 << P_LEDG);
|
||||
D_LEDB |= (1 << P_LEDB);
|
||||
O_LEDR |= (1 << P_LEDR);
|
||||
|
||||
_delay_ms(50);
|
||||
|
||||
O_LEDR &= ~(1 << P_LEDR);
|
||||
|
||||
WDTCSR = (1 << WDIE) | (1 << WDP1);
|
||||
|
||||
RCounter = 10;
|
||||
GCounter = 35;
|
||||
BCounter = 20;
|
||||
|
||||
sei();
|
||||
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||
sleep_mode();
|
||||
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
ISR(WATCHDOG_vect)
|
||||
{
|
||||
if(O_LEDR & (1 << P_LEDR))
|
||||
{
|
||||
O_LEDR &= ~(1 << P_LEDR);
|
||||
RCounter = rand() % MAX_DELAY;
|
||||
}
|
||||
else
|
||||
{
|
||||
RCounter--;
|
||||
if(RCounter == 0)
|
||||
{
|
||||
O_LEDR |= (1 << P_LEDR);
|
||||
}
|
||||
}
|
||||
|
||||
if(O_LEDG & (1 << P_LEDG))
|
||||
{
|
||||
O_LEDG &= ~(1 << P_LEDG);
|
||||
GCounter = rand() % MAX_DELAY;
|
||||
}
|
||||
else
|
||||
{
|
||||
GCounter--;
|
||||
if(GCounter == 0)
|
||||
{
|
||||
O_LEDG |= (1 << P_LEDG);
|
||||
}
|
||||
}
|
||||
|
||||
if(O_LEDB & (1 << P_LEDB))
|
||||
{
|
||||
O_LEDB &= ~(1 << P_LEDB);
|
||||
BCounter = rand() % MAX_DELAY;
|
||||
}
|
||||
else
|
||||
{
|
||||
BCounter--;
|
||||
if(BCounter == 0)
|
||||
{
|
||||
O_LEDB |= (1 << P_LEDB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t y = 132457;
|
||||
|
||||
uint16_t rand()
|
||||
{
|
||||
y ^= y << 13;
|
||||
y ^= y >> 7;
|
||||
y ^= y << 5;
|
||||
return y;
|
||||
}
|
20
tn24/src/main.h
Normal file
20
tn24/src/main.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef MAIN_H_
|
||||
#define MAIN_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <stdint.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "pinning.h"
|
||||
|
||||
int main(void);
|
||||
|
||||
uint16_t rand();
|
||||
|
||||
#endif
|
16
tn24/src/pinning.h
Normal file
16
tn24/src/pinning.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef PINNING_H_
|
||||
#define PINNING_H_
|
||||
|
||||
#define D_LEDR DDRA
|
||||
#define O_LEDR PORTA
|
||||
#define P_LEDR PA2
|
||||
|
||||
#define D_LEDG DDRA
|
||||
#define O_LEDG PORTA
|
||||
#define P_LEDG PA3
|
||||
|
||||
#define D_LEDB DDRA
|
||||
#define O_LEDB PORTA
|
||||
#define P_LEDB PA1
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue