06-26-2015, 01:01 PM
(06-25-2015, 06:40 AM)Segolia Wrote:(06-25-2015, 06:24 AM)SCN-3_NULL Wrote: I'm not sure about the configurable clock but I do finf TMR1,TMR2 and a few TRM in the special registers, are those what I'm looking for?
and yes the device has ports, I'm planning on assembling them like this, but with 5LEDs and 4MHz clock
And a code example would be really useful, dont see these in my slides, will put those in the comments just for reminder.
I can't give you a code example easily. I'd have to read through the datasheet for your device to even work out pinouts and registers properly. Not to mention I'm a bit rusty and I've never worked with PIC (I learned assembly with an ARM architecture).
It should be pretty straightforward, you know how to write interrupt handlers right? psuedocode would look something like
Quote:Main:
-configure clock registers (for desired delay)
-configure GPIO pins/ports/whatever for LED
-Store LED bitmask (0x01) in memory or register
-Store Direction flag/bit (0x0) in memory or register
-enable port/pins
-enable clock
Clock interrupt handler:
-read LED bitmask into register
-Clear all current LED pins
-Perform some logic to write to appropriate pin (eg. write value of LED bitmask AND 2_00000001 to LED 1, bitmask AND 2_00000010 to LED 2 etc.)
-read direction flag/bit
-Circular shift (aka rotate no carry) either left or right based on value of direction bit (eg. left if 0, right if 1)
-store new LED bitmask in memory
Button interrupt handler:
-read direction flag/bit
-XOR 0x1 to toggle
-store updated direction flag/bit
And remember if you're using registers to store those values to push them onto the stack before running your interrupt handler.
Is it required to use PIC for this? I tried using an attiny recently instead of a pic for a project and was quite impressed. There's a lot less setup going on, and the attiny has a lot more registers to work with making it easier to code assembly for compared to the single 'W' register of the pic architecture.
I've never actually run PIC code, though I have written it a few times, while I have both assembly and C++ for attiny working in actual devices.
Feel free to PM me if anything is broken