eMyListsDDg wrote: >=20 > not sure i fully understand your suggestion. could you provide a a few > lines of code for me to view? This was after Wouter wrote: > > > > In most cases this will put you at the mercy of the Read-Modify-Write > > problem. Better define a bit in a porta-shadow register, chacge that > > bit, and copy it to PORTA after each change of any bit. You'll find a number of examples in my tutorials (www.gooligum.com.au/tutorials.html) - I use shadow registers pretty consistently. Here's one example, showing how I've set up a shadow register as a union, making it possible to refer to the whole register ("GPIO =3D sGPIO.port") o= r to individual shadow bits with logical names ("sFLASH =3D 1"). Don't be scared off - the lessons start simpler than this! /************************************************************************ * * * Description: Lesson 3, example 4 * * * * Demonstrates use of Timer0 in counter mode * * * * LED flashes at 1 Hz (50% duty cycle), * * with timing derived from 32.768 kHz input on T0CKI * * * ************************************************************************* * * * Pin assignments: * * GP1 =3D flashing LED * * T0CKI =3D 32.768 kHz signal * * * ************************************************************************/ #include #include /***** CONFIGURATION *****/ // ext reset, no code protect, no watchdog, int RC clock __CONFIG(MCLRE_ON & CP_OFF & WDT_OFF & OSC_IntRC); // Pin assignments #define sFLASH sGPIO.GP1 // flashing LED (shadow) /***** GLOBAL VARIABLES *****/ union { // shadow copy of GPIO uint8_t port; struct { unsigned GP0 : 1; unsigned GP1 : 1; unsigned GP2 : 1; unsigned GP3 : 1; unsigned GP4 : 1; unsigned GP5 : 1; }; } sGPIO; /***** MAIN PROGRAM *****/ void main() { // Initialisation =20 // configure port =20 TRIS =3D 0b111101; // configure GP1 (only) as an output =20 // configure timer =20 OPTION =3D 0b11110110; // configure Timer0: //--1----- counter mode (T0CS =3D 1) //----0--- prescaler assigned to Timer0 (PSA = =3D 0) //-----110 prescale =3D 128 (PS =3D 110) // -> increment at 256 Hz with 32.768 kHz input =20 // Main loop for (;;) { // TMR0<7> cycles at 1 Hz, so continually copy to LED sFLASH =3D 0; // assume TMR<7>=3D0 -> LED off if (TMR0 & 1<<7) // if TMR0<7>=3D1 sFLASH =3D 1; // turn on LED =20 GPIO =3D sGPIO.port; // copy shadow to GPIO =20 } // repeat forever } --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .