source: avrstuff/V-USB_Dev/firmwares/christmas/main.c@ 4946f6f

main
Last change on this file since 4946f6f was 4946f6f, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago

Move christmasblinker to firmware folder.

git-svn-id: svn://pulkomandy.tk/avrstuff@47 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#include <avr/io.h>
2#include <avr/interrupt.h>
3#include <avr/wdt.h>
4#include <avr/pgmspace.h>
5#include <util/delay.h>
6
7#include <string.h>
8#include <stdbool.h>
9
10#include "usbdrv/usbdrv.h"
11
12#define DDRIN DDRB
13#define PORTIN PORTB
14#define PININ PINB
15
16#define DDROUT DDRC
17#define PORTOUT PORTC
18
19int state;
20int step;
21
22int main() {
23// wdt_enable(WDTO_2S);
24
25 // USB
26 sei();
27
28 DDROUT = 255; // Keyboard matrix out
29 PORTOUT = 255; // Enable pull up
30 // We put all pins as input then output a 0 in only one at a time.
31 // All the other pins are high-Z to avoid short circuits when many
32 // buttons are pressed.
33 DDRIN = 0; // Keyboard matrix in
34 PORTIN = 255; // Enable pull up
35
36 state = 0;
37 step = 0;
38
39 for(;;) {
40 switch(state)
41 {
42 case 0:
43 for(int i = 5; --i>=0;) {
44 PORTOUT = ~(1<<i);
45 _delay_ms(100);
46 PORTOUT = 255;
47 _delay_ms(300);
48 }
49 _delay_ms(500);
50 break;
51 case 1:
52#define PWM 10000
53 for(int j = PWM; j > 0; j -= 100)
54 {
55 PORTOUT = 255;
56 _delay_us(j);
57 PORTOUT = 0;
58 _delay_us(PWM - j);
59 }
60 for(int j = PWM; j > 0; j -= 100)
61 {
62 PORTOUT = 0;
63 _delay_us(j);
64 PORTOUT = 255;
65 _delay_us(PWM - j);
66 }
67
68 _delay_ms(500);
69 break;
70
71 case 2:
72 for(int i = 16; --i>= 0;)
73 {
74 PORTOUT = i;
75 _delay_ms(200);
76 }
77 break;
78
79 case 3:
80 for(int j = PWM; j > 0; j -= 100)
81 {
82 PORTOUT = ~3;
83 _delay_us(j);
84 PORTOUT = 3;
85 _delay_us(PWM - j);
86 }
87 for(int j = PWM; j > 0; j -= 100)
88 {
89 PORTOUT = 3;
90 _delay_us(j);
91 PORTOUT = ~3;
92 _delay_us(PWM - j);
93 }
94
95 _delay_ms(500);
96 break;
97
98 default: state = 0;
99 }
100
101 if (++step > 5) {
102 step = 0;
103 ++state;
104 }
105 }
106}
107
108
Note: See TracBrowser for help on using the repository browser.