I'm not familiar with C programming on a PIC, but a few thoughts ... - Not sure which PIC you're using, but RA4 is generally an open collector output, so you'll need to switch the low side of the LED, or use an external driver circuit. Or just change to some other pin for now. - Is it operating too fast to see? Check your timer-0 prescalers, etc. - Verify that any other peripherals (A/D converter, comparators, etc) are turned off for the PIC you're using. Cheers, -Neil. Robert Kiely wrote: > > Hi all, > > I've just begun using PIC's and am using the following code to flash > the LED's connected to RA4 and RA5 on and then off by using timer0. As > you can see from the code the LED connected to RA4 is turned on first > and then the program uses timer0 to flash the LED's. When I program > this onto the PIC however it doesn't work even though it simulates > correctly in MPLAB SIM. After some time I decided to swap the code > around by changing all references to porta.4 to porta.5 and vice > verse. This meant that the LED connected to RA5 turned on first. This > worked perfectly first time. I can't understand why this is and was > hoping that somebody might be able to shed some light on this for me > as it's been annoying me for days ! I'm using MPLAB IDE with the > BoostC PIC16 C compiler and a PicKit 1 flash starter kit for > programming with the supplied PicKit1 Classic programming software. > > Rgds, > Rob > > > #include > #pragma DATA 0x2007, _INTRC_OSC_NOCLKOUT & _WDT_OFF // set configuration > byte > > void main(void){ > option_reg = 135; // set timer0 mode and prescaler > trisa = 207; // set porta input/output modes > porta = 0; // turn off porta outputs > tmr0 = 0; // set timer0 value > intcon = 0; // clear all flags and disable all interrupt (just in case) > porta.4 = 1; // turn on led d0 > intcon.5 = 1; // enable timer0 interrupts > intcon.7 = 1; // enable interrupts > while(1); // wait for timer0 overflow > } > > void interrupt(void){ > if (porta.4 == 0){ // if led d1 is on > porta.5 = 0; // turn it off and > porta.4 = 1; // turn on led d0 > } else { > porta.4 = 0; // turn of led d0 > porta.5 = 1; // turn on led d1 > } > intcon.2 = 0; // clear timer0 flag > return; > } > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > > -- View this message in context: http://www.nabble.com/Odd-behaviour-flashing-LED%27s-using-timer0-on-PIC16F684-tp20652770p20652986.html Sent from the PIC - [PIC] mailing list archive at Nabble.com. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist