Microcontroller - Christmas Card

Microcontroller

Programming Code, technical stuff and much more: Welcome to the world of microcontrollers!

microcontroller-teaserOnly few millimeters in each direction: the microcontrollers are very small – but helpful to bring blinking LEDs to the Christmas Card!

Programming? Daniel Ring worked hard and did it on his own! We proudly present: the code in C:

01
//############################################################################################
02
//##Daniel Ring - ATTINY13 - Christmas Card Project 2 - University of Applied Science Munich##
03
//############################################################################################
04
 
05
#define F_CPU 1200000UL // 1,2 Mhz
06
 
07
#include <avr/io.h>
08
#include <avr/interrupt.h>
09
#include <avr/sleep.h>
10
#include <util/delay.h>
11
 
12
void powerDown(void)
13
{
14
 GIFR |= (1<<PCIF); // Loescht eventuelle vorherige Pin Change Interrupts
15
 GIMSK |= (1<<PCIE); // Aktiviert Pin Change Interrupts
16
 MCUCR = (MCUCR | (1<<SM1)) & ~(1<<SM0);
17
 MCUCR |= (1<<SE); // Aktiviert Power-Down
18
 sleep_cpu();
19
 MCUCR &= ~(1<<SE); // Deaktivert Power-Down
20
 GIMSK &= ~(1<<PCIE); // Deaktiviert Pin Change Interrupts
21
}
22
 
23
ISR(PCINT0_vect)
24
{
25
}
26
 
27
int main(void)
28
{
29
 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
 //+++++++++++++++++++++++ I/O Setup +++++++++++++++++++++++++
31
 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
 //SREG &= 0B01111111; // Schaltet globale Interrupts aus
33
 PORTB |= (1<<PB4); 
34
 DDRB |= (1<<PB3)|(1<<PB1)|(1<<PB2)|(1<<PB0);
35
 //-----------------------------------------------------------
36
 //----------------------- I/O Setup -------------------------
37
 //-----------------------------------------------------------
38
 
39
 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40
 //++++++++++++++++++++ Interrupt Setup ++++++++++++++++++++++
41
 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42
 PCMSK |= (1<<PCINT4); // Nur PB0 triggert jetzt PCINT (wenn im Schlafmodus)
43
 //GIMSK |= (1<<PCIE); // Aktiviere Pin Change Interrupts
44
 
45
 SREG |= (1<<SREG_I); // Schaltet alle Interrupts global (nach dem Setup)
46
 //-----------------------------------------------------------
47
 //-------------------- Interrupt Setup ----------------------
48
 //-----------------------------------------------------------
49
 
50
 while (1)
51

I want to see the whole fancy code!

Continue tour >>