| Author |
Message |
evaang2003
Joined: 28 May 2009 Posts: 14
|
09 Jun 2009 7:10 light up led source code |
|
|
|
|
hi, i currently play with led using pic16f877a.
i connect one led to port b bit7.
the result i want to get is just to lit the led.
however, it does not response.
here is the source code i write using ccs picc compiler.
#include <16f877a.h>
void main()
{
output_high(PIN_B7);
}
can anybody tell me what went wrong?
|
|
| Back to top |
|
 |
xxtigerxx
Joined: 05 Jun 2001 Posts: 240 Helped: 5 Location: Greece
|
09 Jun 2009 7:28 light up led source code |
|
|
|
|
you must make the B7 output..
TRISB7=0;
after
PB7=1;
|
|
| Back to top |
|
 |
saeed_pk
Joined: 20 May 2006 Posts: 199 Helped: 5 Location: Islamabad, Pakistan
|
09 Jun 2009 8:15 light up led source code |
|
|
|
|
| Yes you have to clear the the TRISB7 bit to make this pin output make sure about CONFIG word if DEBUG is enabled this pin may not function.
|
|
| Back to top |
|
 |
bld
Joined: 25 Jul 2006 Posts: 54 Helped: 7 Location: Iasi, Romania
|
09 Jun 2009 8:47 Re: light up led source code |
|
|
|
|
I would suggest:
| Code: |
#include <16f877a.h>
void main()
{
output_high(PIN_B7);
while(1);
}
|
In your code, after the the LED is on, the microcontroler reaches the end of the program and resests. So the result will be a blinking of the LED with a very small duty factor and maybe that's why you can't see any light.
I've never used CCS compiler but maybe you need to set pin RB7 as output separately before putting it high.
|
|
| Back to top |
|
 |
evaang2003
Joined: 28 May 2009 Posts: 14
|
10 Jun 2009 4:43 Re: light up led source code |
|
|
|
|
well, i modify the code to:
#include<16f877a.h>
#BYTE PORTB=0x06
#BIT PORTB7=PORTB.7
void main(void)
{
set_tris_b(0x00);
output_high(PIN_B7);
while(1);
}
sadly, it din work:(
|
|
| Back to top |
|
 |
xxtigerxx
Joined: 05 Jun 2001 Posts: 240 Helped: 5 Location: Greece
|
10 Jun 2009 6:20 light up led source code |
|
|
|
|
can you tell me which compiler you r using?
maybe your problem is hardware..
Try run in simulation. it works?
|
|
| Back to top |
|
 |
bld
Joined: 25 Jul 2006 Posts: 54 Helped: 7 Location: Iasi, Romania
|
10 Jun 2009 8:11 Re: light up led source code |
|
|
|
|
| I can't see in your code if you set the configuration bits of the controller, especially the oscillator configuration...
|
|
| Back to top |
|
 |
evaang2003
Joined: 28 May 2009 Posts: 14
|
10 Jun 2009 9:49 Re: light up led source code |
|
|
|
|
i just want to test the i/o function of pic16f877a.
i experiment it with one led, 4MHz oscilator but it din work.
i m using ccs compiler.
i then include these into source code but it din work.
#use dalay(clock=4000000)// 4MHz crytal is used.
it din work.
why???
|
|
| Back to top |
|
 |
jumper2high
Joined: 24 May 2009 Posts: 62 Helped: 3 Location: Serbia
|
10 Jun 2009 12:45 Re: light up led source code |
|
|
|
|
What exactly are you expecting the LED to do?
The way you created it, the moment the chip gets power it'll turn the LED on and that's it. If you want it to blink, you'll need to turn it on, wait and then turn it off. You do this by using a delay function, usually called DelayMs(X) where X is the number of milliseconds you want to wait.
|
|
| Back to top |
|
 |
Google AdSense

|
10 Jun 2009 12:45 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
evaang2003
Joined: 28 May 2009 Posts: 14
|
11 Jun 2009 3:11 Re: light up led source code |
|
|
|
|
i now know the fatal error that occur.
my compiler is damaged that it generate rubbish hex code.
thanks for those try to help me.
i will work it on after i get the new compiler.
|
|
| Back to top |
|
 |