Hello Ivan,

The task you are describing is as simple as RA1 = !RB0.

To use interrupts in any controller (so in PICs too), you have several things 
to configure:
- choose whether the interrupt routine will react to a state or to an edge;
- choose that an ISR will react at all, i.e. allow interrupts in general, the 
one you use in particular, once before entering the main loop.

In the interrupt service routine itself, two cases are possible according to 
the type and model of controller:
- the flag that is set by the interrupting event gets reset by hardware upon 
execution of the ISR;
or
- you have to explicitly reset the flag yourself inside the ISR.
Either way, the flag has to be reset.

You'll want to check all that in the specs of your controller, then code your 
program so that:
- interrupts are allowed for both edges on RB0 (startup);
- RA1 = 0 upon a trailing (falling) edge (ISR)
- RA1 = 1 upon a leading (rising) edge (ISR)
- The main loop will do nothing, that's the idea with interrupts.

It's not that terrible, Ivan ;-)

Regards
JP

Le Lundi 28 Janvier 2008 19:06, Ivan Petrushev a écrit :
> Hello,
> I'm new to SDCC and microcontrollers - my first two very simple
> programs burned into PIC16F88 and working! :)
> Now I'm trying something little harder than just lighting LEDs - I
> want to try the interrupt system.
> PIC16F88 has one external interrupt - on pin RB0.
> I'm trying the following very simple program, but something is wrong:
> #define __16f88
> #include"pic/pic16f88.h"
>
> typedef unsigned int word;
> word at 0x2007  __CONFIG = 0x3f70;
>
> void isr_high(void) interrupt 1 {
>         if (RB0 == 1) RA1 = 0;
> }
> void main(void) {
>         TRISA = 0;
>         while(1) {
>                 RA1 = 1;
>         }
> }
>
> I expect when I run this to have pin RA1 '1', untill RB0 is pulled
> '1'. Then RA1 should go '0' untill RB0 is released.
> I'm running that at gpsim and there RA1 is always '1'. When I run the
> program step by step I see it never enters the interrupt code section.
> So, how can I define an interrupt? I've searched a lot through the
> documentation of SDCC and the only piece of value I've found is the
> 'void isr_high interrupt 1' function I'm using.
>
> Is there a more complicated/simplified way to code an interrupt?
>
> Thanks,
> Ivan.
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Sdcc-user mailing list
> Sdcc-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sdcc-user

-- 
Never jump into a loop!

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to