i am confused in interrupt !

Mike.

Member
hello guys !
i am using picaxe- 18M2 micro-controller..
i am confused in interrupt ..
i am using B.0 , B.1 , B.2 AS INPUT AND B.3 AS OUTPUT.
AT OUTPUT B.3, LED IS CONNECTED TO GLOW.

ALL INPUT (B.0 , B.1 , B.2) WILL BE HIGH.

IF ANYONE ONE OF B.0 , B.1 , B.2 INPUT GOES LOW THEN
THE INTERRUPT SHOULD OCCUR AND TURN THE LED ON ( OUTPUT B.3 HIGH ).

what will be the required code !

thanks
 

nick12ab

Senior Member
Can you do the rest of your code with no medium or long pauses or music commands? Can you do your code so that it's just a section of IF statements running in a loop? If so, then you can add an IF statement to check the B pins:

Code:
do
....
..... Other code here
....
.....
  if b.0 = 1 and b.1 = 1 and b.2 = 1 then
    high b.3
  else
    low b.3
  end if
loop
 

Mike.

Member
Can you do the rest of your code with no medium or long pauses or music commands? Can you do your code so that it's just a section of IF statements running in a loop? If so, then you can add an IF statement to check the B pins:

Code:
do
....
..... Other code here
....
.....
  if b.0 = 1 and b.1 = 1 and b.2 = 1 then
    high b.3
  else
    low b.3
  end if
loop
it is an if statement !
i want interrupt ! the rest of my code will be running.. but as the input pins goes low then interrupt should occur and take the output pin high..
 

nick12ab

Senior Member
it is an if statement !
i want interrupt ! the rest of my code will be running.. but as the input pins goes low then interrupt should occur and take the output pin high..
Are you complaining that I've only supplied you with an IF statement that you find useless?

It isn't useless. If your current code runs in a loop which is completed in a few milliseconds then the IF statement I provided is a good enough replacement for the interrupt. You can't use the setint command because it only supports pinsC.

Examples of projects where the code can just run in a loop:
  • LED clock (multiplexing or otherwise)
  • Security alarm
  • Datalogger
  • Thermostat / temperature controller
  • Cycle computer
  • Electronic games
  • Battery charge controller
  • Adjustable digital power supply
  • ANd many more...
 

kollinsb

Member
Is the 18M2 the problem here because it doesn't support an interrupt on a specific pin? If so, do you have another type chip like a 14m2 or 20m2? Page 215 in Manual 2 is where interrupts are explained. I don't have an 18m2 to test on but the programming editor gives nice little hints when you check the syntax after writing some code. Like with the 14m2 it tells me that interrupts can only be run on ports C.0 through C.2, that simple.
 

inglewoodpete

Senior Member
Mike. You asked for code to turn an output high when any of 3 inputs goes low.

The following code will do what you want, except:
1. Inputs must be on port C
2. Output must be turned off in some other piece of code, possibly in your main loop.
Code:
#PICAXE 18M2

Init:     SetInt OR %00000000, %00000111 'Interrupt occurs on inputs C.0, C.1, C.2 (%00000111)
                                      ' when they go low  (%00000000)
          '
MainLoop: Do
             '{put your own main loop code here}
          Loop
          '
Interrupt:High B.3                    'Turn LED on
          SetInt OR %00000000, %00000111 'Reset interrupts
          Return
 
Top