I had these needs, and they can be easily managed using bit masks. For some lighting effects, I had some pins on a port used as inputs and others as outputs. I need to add the NewState value on bits 0-5 of LATC, bits 6 and 7 are input: Update the focus pins: ' Focuses 1-6 (bits 0-5) on LATB.0-5, preserving bits 6-7 (strobe) LATB = (LATB And %11000000) Or (NewState And %00111111) This way, you directly write all the bits you need in a single pass and don't disturb the input bits.
I'm sending you a library I wrote to use a PCF8574 in my home automation project. I use it to program outputs and use them both as inputs (the pin goes high and generates an interrupt when it's pulled low externally) and as outputs. It's possible to configure outputs as unmodifiable; this was useful for my home automation project. I also added the ability to read a rotary encoder. The routines are commented, and a small sample code is included.
In Mikrobasic the volatile word is also used during the variable declaration. A variable whose value can change asynchronously, out of the direct control of the flow of the main program. The compiler will not make optimizations on it, precisely because it must consider that the value could be altered by: Interruption routine (ISR) Direct accesses from hardware peripherals Asynchronous operations from other threads or processes (if present)
Cute, fun. Even though I'm an old (actually very old) school programmer. So old school that I once programmed in Fortran on a Digital PDP11-84. I like playing with these things, I'll play with it a bit...
I had written the original program in MikroBasic and I tried it on the pic16F1847 with a clock of 32mhz and on a pic18F47K40 with a clock of 64MHz. In both cases the response was quite fast and the effect was pleasant. I did not have the opportunity to try this version in GCBasic because I gave the circuit I had assembled to a friend for his birthday. It all depends on the speed that the GCBasic compiler uses to do the floating point calculations. If you try it, use a PIC with a high enough clock...
Actually no, it was for testing and it stayed there like that. It needs to be lowered but I don't have the program with me now, I had set it with the oscilloscope during debugging.
Constants: I need to define constants that have a value of type single (and also double). I know that the Const instruction is used only for strings. How can I make use single or double constants? Example: ' --- CONSTANTS --- Const LN2 As Single = 0.69314718056 Const INV_LN2 As Single = 1.44269504089 Const EPSILON As Single = 0.000001
Constants: I need to define constants that have a value of type single (and also double). I know that the Const instruction is used only for strings. How can I make mer use single or double constants? Example: ' --- CONSTANTS --- Const LN2 As Single = 0.69314718056 Const INV_LN2 As Single = 1.44269504089 Const EPSILON As Single = 0.000001