aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2021-06-05 11:10:23 +0000
committerrodri <rgl@antares-labs.eu>2021-06-05 11:10:23 +0000
commitedf5f145013aa28ffbc7f19f874cd489a92f8449 (patch)
tree05a7dfdae1b63a79bdfbb1fab84af35a51b5b99c /c
downloadavrtoys-edf5f145013aa28ffbc7f19f874cd489a92f8449.tar.gz
avrtoys-edf5f145013aa28ffbc7f19f874cd489a92f8449.tar.bz2
avrtoys-edf5f145013aa28ffbc7f19f874cd489a92f8449.zip
public release.HEADmaster
Diffstat (limited to 'c')
-rw-r--r--c/blink/blink.c23
-rw-r--r--c/timer/timer.c23
-rw-r--r--c/timer/timerctc.c26
3 files changed, 72 insertions, 0 deletions
diff --git a/c/blink/blink.c b/c/blink/blink.c
new file mode 100644
index 0000000..bb4495a
--- /dev/null
+++ b/c/blink/blink.c
@@ -0,0 +1,23 @@
+#include <avr/io.h>
+#define F_CPU 16000000UL
+#include <util/delay.h>
+
+enum{
+ Delay = 300
+};
+
+int
+main()
+{
+ int led;
+
+ led = 1<<PB1;
+ DDRB |= led;
+
+ for(;;){
+ PORTB ^= led;
+ _delay_ms(Delay);
+ }
+ return 0;
+}
+
diff --git a/c/timer/timer.c b/c/timer/timer.c
new file mode 100644
index 0000000..f1231b1
--- /dev/null
+++ b/c/timer/timer.c
@@ -0,0 +1,23 @@
+#include <avr/io.h>
+
+enum{
+ Dcnt = 62499
+};
+
+int
+main()
+{
+ int led;
+
+ led = 1<<PB1;
+ DDRB |= led;
+ TCCR1B |= 1<<CS12;
+
+ for(;;){
+ if(TCNT1 >= Dcnt){
+ PORTB ^= led;
+ TCNT1 = 0;
+ }
+ }
+}
+
diff --git a/c/timer/timerctc.c b/c/timer/timerctc.c
new file mode 100644
index 0000000..7e65b52
--- /dev/null
+++ b/c/timer/timerctc.c
@@ -0,0 +1,26 @@
+#include <avr/io.h>
+
+enum{
+ Dcnt = 62499 /* 1Hz */
+};
+
+int
+main()
+{
+ int led;
+
+ led = 1<<PB1;
+ DDRB |= led;
+ TCCR1B |= 1<<CS12; /* f/256 prescaling */
+ TCCR1B |= 1<<WGM12; /* ctc op mode */
+ OCR1A = Dcnt; /* setup TOP */
+
+ for(;;){
+ /* check if we reached TOP */
+ if(TIFR1 & (1<<OCF1A)){
+ PORTB ^= led;
+ TIFR1 = 1<<OCF1A; /* reset the flag */
+ }
+ }
+}
+