Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me fix a code for LED blinking in PIC16F876!

Status
Not open for further replies.

Faizan Jawaid

Full Member level 3
Joined
Jul 17, 2008
Messages
189
Helped
23
Reputation
46
Reaction score
5
Trophy points
1,298
Location
Karachi, Pakistan
Activity points
2,336
My test prog is not working...The LED on b0 is blinking but LED on b1 is not blinking at all....Can anyone find where the mistake is pls? Prog is written in CCS C COMPILER

///////////////////TEST_INT///////////////////////////
#include <16F876.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#int_timer1

void wave_timer()
{
output_toggle(pin_b1);
}

void main()
{
set_tris_b(0xff);
set_timer1(0);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(1)
{
output_toggle(pin_b0);
delay_ms(100);
}
}
 

Re: INT prob with PIC!

add this in fuses,

#FUSES PUT //Power Up Timer

u r using port B as output not as input make it low

set_tris_b(0x00);

now it will work 100%
 

Re: INT prob with PIC!

Thanks hameeds01...Can u tell how do u relate PUT with Timer?

Added after 7 minutes:

I did u made modifications but still only b0 LED is blinking and b1 is not blinking....
 

Re: INT prob with PIC!

Write in this way:

setup_timer_1(T1_DIV_BY_8 | T1_INTERNAL);

timer will overflow after = 2.04 msec

this is a very short time for an eye to observe that the LED is Blinking ...........

use an Oscilloscope to observe the change or insert a counter variable & check the counter to toggle the LED state
 

Re: INT prob with PIC!

Salam!
Has ur circuit started working. I doubt the calculation i think it should be

time =1000000/(8*65535);
it should be 1.90Hz.

For the 100msec time i think u should get 5Hz frequency which should be visible.
I simulated ur software and it is working but i will try to check it in detail.
Allah hafiz.
 

Re: INT prob with PIC!

Thanks to both of u but i got a very strange prob...I`ve also simulated the software in PIC SIMULATOR IDE its working fine...But when i burn the IC it doesnt work...Any ideas...Not only this but CAPTURE function of the timer 2 is also not working...Only and Only PWM works...Programmer Fault?
 

Re: INT prob with PIC!

Sorry man I was considering timer1 as 8-bit

Let me correct ur calculations sir waseem if u don’t mind

Over flow time = (8*65535) / 1000000 = 0.524 sec
Time period = 2 x 0.524 = 1.048 sec
Frequency = 1 / T = 0.9536 Hz
 

Re: INT prob with PIC!

Aoa,
yes hameed u r right i had written the calculation for frequency of interrupt not time.
Regards.

Added after 1 minutes:

well that may not be the reason for the program not working. Something is still wrong with ur code. Post ur complete code and if possible the hardware schematic of ur circuit.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top