Em 11/6/2012 07:00, Michael Rigby-Jones escreveu: > > -----Original Message----- > > Em 8/6/2012 14:31, William "Chops" Westfield escreveu: >> On Jun 8, 2012, at 4:54 AM, Ben Barwise wrote: >> >>> interrupt isr() >>> { >>> int off1 =3D 0; >>> } >> You'll need to make off1 a global variable, so that references to that n= ame in the isr and references from the main code actually reference the sam= e data. >> >> Then you'll probably need to make it "volatile" so that the compiler wil= l be warned that it has to keep checking the value, instead of (for instanc= e) moving it into a register at the start of main and just referring to tha= t copy over and over again. >> >> BillW > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf = Of Isaac Marino Bavaresco > Sent: 08 June 2012 19:23 > To: Microcontroller discussion list - Public. > Subject: Re: [PIC] Help using interrupts in High Tech C & 12F683 > >> Do not forget to use a critical section (segment of code with interrupts >> disabled) to access off1 from main code, otherwise you may get corrupted= data. >> >> >> Isaac > If access to the variable is atomic (e.g. it's a single bit or an aligned= byte wide value on a PIC) then a critical section should not be needed. > > Mike Exactly, *atomic* operations don't need to be protected. Unfortunately, most operations are not atomic, even on single bits or bytes. For instance: if you need to check the current value and then change it, then it is not an atomic operation anymore. Also, his variable is 'int'. Isaac --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .