diff options
author | brett <brett@bretts-windows-laptop> | 2024-04-23 20:51:02 -0500 |
---|---|---|
committer | brett <brett@bretts-windows-laptop> | 2024-04-23 20:51:02 -0500 |
commit | 2bd45f076ea7eb429bfee54fe1de240ff4b284e6 (patch) | |
tree | f37034113ad3aec380062d0998e1cf94b65424f5 /final_project/clock.c |
should be finished, backing up
Diffstat (limited to 'final_project/clock.c')
-rw-r--r-- | final_project/clock.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/final_project/clock.c b/final_project/clock.c new file mode 100644 index 0000000..7c216fc --- /dev/null +++ b/final_project/clock.c @@ -0,0 +1,31 @@ +/*
+ * clock.c
+ *
+ * Created: 4/3/2024 10:29:19 AM
+ * Author: bsw9xd
+ */
+#include "clock.h"
+
+void timer_init_ctc() {
+ TCCR1A = 0x00; //WGM10 = 0, WGM11 = 0 (CTC mode when combined with WGM12 in TCCR1B)
+ TCCR1B = (1 << WGM12);
+ TCNT1 = 0; // initialize timer at 0
+ //TIMSK1 |= (1<<OCIE1A); // enable int at timer1
+
+}
+
+void start_timer() {
+ TCNT1 = 0;
+ OCR1A = 0x3d09; // 1 second
+ if(TIFR1 & (1 << OCF1A)) TIFR1 |= (1 << OCF1A);
+ TCCR1B |= (1<<CS12) | (1 << CS10); //start timer with 1024 prescalar
+}
+
+void stop_timer() {
+ if(TIFR1 & (1 << OCF1A)) TIFR1 |= (1 << OCF1A);
+ TIMSK1 = (1 << WGM12);
+}
+
+bool timer_done() {
+ return (TIFR1 & (1 << OCF1A));
+}
\ No newline at end of file |