electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Light up led source code - what went wrong ?


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Light up led source code - what went wrong ?
Author Message
evaang2003



Joined: 28 May 2009
Posts: 14


Post09 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


Post09 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


Post09 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


Post09 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


Post10 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


Post10 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


Post10 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


Post10 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


Post10 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
Google Adsense




Post10 Jun 2009 12:45   

Ads




Back to top
evaang2003



Joined: 28 May 2009
Posts: 14


Post11 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
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Light up led source code - what went wrong ?
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
What is LED Light, LED which visible in direct Sunlight (2)
LED moving message .. whats wrong with this code help??? (3)
errors in source codes - what am I doing wrong? (3)
verilog source code for traffic light controller (4)
What wrong with my C code (4)
What is wrong with my simple code? (4)
Help: what is wrong with my verilog code? (8)
LED Scrolling Message Source Code (10)
what in the world is wrong with this C code??? (6)
what wrong in this VHDL code plz help me (3)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS