Dtynin
DIIDevHeads IoT Integration Server
•Created by Dtynin on 9/12/2024 in #firmware-and-baremetal
Compile-Time Check for Node Limit in Custom Communication Function for PIC16F84A
Hey everyone, I’m working in Microchip Studio to create a custom communication function for a few PIC16F84A microcontrollers. I know there are built-in options like SPI, but I’m going the DIY route to learn more about the nitty-gritty of how this all works. Here’s what I’ve come up with so far:
Now, my setup only supports up to 4 nodes, so I want to make sure the
node
parameter doesn’t go above 4. Right now, I just have a simple runtime check:
But I’m thinking it’d be better to enforce this at compile time instead of waiting for runtime. This could make the code safer, maybe even run a bit faster. I haven’t tried anything specific yet, but I’m curious if there are any cool tricks or language features I could use for this, like static assertions or compile-time constants.
Anyone out there tried something similar or have any tips?1 replies