summaryrefslogtreecommitdiffstats
path: root/PIC/blink.c
diff options
context:
space:
mode:
authorVäinö Kauppila <vaino@vke.fi>2026-04-19 00:33:08 +0300
committerVäinö Kauppila <vaino@vke.fi>2026-04-19 00:33:08 +0300
commit8bd8dd6ce07fb8e247f651b3c61c94bb1f00895a (patch)
tree87bd95bd073d68efd0ad31a34f0d8926c32ff6db /PIC/blink.c
downloadvhdl_pic-8bd8dd6ce07fb8e247f651b3c61c94bb1f00895a.tar.gz
vhdl_pic-8bd8dd6ce07fb8e247f651b3c61c94bb1f00895a.zip
starting files and example programs
Diffstat (limited to 'PIC/blink.c')
-rw-r--r--PIC/blink.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/PIC/blink.c b/PIC/blink.c
new file mode 100644
index 0000000..6789b0a
--- /dev/null
+++ b/PIC/blink.c
@@ -0,0 +1,35 @@
+#include <pic16f84a.h>
+
+typedef unsigned char uint8_t;
+
+// Global volatile so sdcc cannot optimise the delay loops away.
+static volatile uint8_t _d0, _d1, _d2;
+
+// Busy-wait ~500 ms at 50 MHz.
+// 200 × 256 × 256 = 13 107 200 inner iterations.
+// Each iteration ≈ 3 uint8_t instructions × 20 ns = 60 ns.
+// Total ≈ 786 ms (tune outer count _d0 < N to taste).
+static void delay(void) {
+ _d0 = 0;
+ do {
+ _d1 = 0;
+ do {
+ _d2 = 0;
+ do { _d2++; } while (_d2 != 0);
+ } while (++_d1 != 30);
+ _d0++;
+ } while (_d0 != 116);
+}
+
+void main(void) {
+ // port_b(0) drives activity_led at E8 on the Tang Primer 25K.
+ // port_a(0) drives led at L6. Both ports are always outputs in this CPU.
+ while (1) {
+ PORTB = 0x01; // activity_led (E8) on
+ PORTA = 0x01; // led (L6) on
+ delay();
+ PORTB = 0x00; // activity_led (E8) off
+ PORTA = 0x00; // led (L6) off
+ delay();
+ }
+}