JAL Program Design Help

Discussion in 'Programmer's Corner' started by ajhoward, Dec 30, 2011.

  1. ajhoward

    Thread Starter Member

    Nov 16, 2011
    46
    0
    Hi there

    I need some help designing a JAL program for this door alarm project. I don't know how to implement interrupts or use sleep mode. I need the PIC to go into sleep mode once the door is closed and wake up when the door is opened. I have attached what I have so far.

    Happy New Year! :)
     
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Here is an intro to jal and interrupts, looks pretty easy. The assembly listing is what is produce by the small program.

    sleep is the command to go to low power mode, but you need to set up the PIC for interrupt on change (in datasheet for your PIC, also described in the doc below)

    Interrupts in jal, part 1

    I'm not sure of the reason you have so many switches.

    Why not just have the door switch pull up where you have R3 to wake from interrupt, wait 10 seconds, then light LEDs on the other ports?

    P.S. Your LED's are pointing the wrong way.
     
  3. ajhoward

    Thread Starter Member

    Nov 16, 2011
    46
    0
    OK, I'll give it a read. S1 and S2 are reed switches, one is aligned to the fridge and one to the freezer. S3 is just there so that I can get direct feedback on what the reed switches are doing without waiting for the timer, so that I can align the switches easier. I realized about the LEDS after I posted the pic, is because I have been changing the circuit around a bit because I am tossing up on whether to switch the earth or power.
     
  4. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    That can be set in software, often it is a pull up switch to wake.
     
  5. ajhoward

    Thread Starter Member

    Nov 16, 2011
    46
    0
    So the switch closing is enough to cause a interrupt, it is not needed in the program?
     
  6. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    When the switch closes, if you have the config registers set up correctly, it will "wake up" from sleep mode and run at full/standard speed. Then, once the tasks it needs to complete are done (waiting 10 seconds, then annoying people), your code will ensure the uC's "wake on change" interrupt on the chosen pin is ready, and go back to sleep.
     
Loading...