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.

Someone tell me what's wrong with a simple led blinking program/circuit!

Status
Not open for further replies.

DanT29

Newbie level 4
Joined
Jul 5, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,345
Hey guys can someone tell me what I'm doing wrong with the simple led blinking program. I'm using the PIC16f628a, Hi-Tech C complier(Lite), pickit 2 and MPLAB v8.88.


Code:
#include<htc.h>
#define _XTAL_FREQ 4000000

void main (void){

TRISB=0b00000000;
PORTB=0b00000001;

while(1){
PORTB=0b00000000;
__delay_ms(1000);
PORTB=0b000000001;
__delay_ms(1000);
}
}

I have also used this code and it does not work:
Code:
#include<htc.h>
#define _XTAL_FREQ 4000000

void main (void){

TRISB=0x00;
PORTB=0xFF;

while(1){
PORTB=0x00;
__delay_ms(1000);
PORTB=0xFF;
__delay_ms(1000);
}
}

I have 5 volts going into VDD and VSS connected to ground while RB0(pin 6) is connected to a resistor which is connected in series with an LED that goes back to ground.

What's odd is when I remove VSS from ground it light's up slightly but doesn't blink. Thanks for the help guys!
 
Last edited:

Could it be that you have the LED the wrong way around? Try to take the LED off and check B0 with a multimeter. That will confirm that the PIC is OK, and the LED is the wrong way around.

Have Fun
 

Can you share your circuit? Try resistor value of 330 ohm
 

Thanks for the replies guys. I have to go buy a multimeter soon I keep forgetting to I will check as soon as I get one. As for posting my circuit do you guys know any good software I can use to simulate and post the design of my circuit? Thanks for the link also!

- - - Updated - - -

Using the link https://www.oz1bxm.dk/PIC/628LED.htm given to me, I was able to make the led blink. So there is a software issue I believe can anyone help with that? I don't really understand assembly and I want to code in C. I also do not know why there is a 5v supply connected to the MCLR in the link I posted any clarifications will be greatly appreciated!
 
Last edited:

watchdog is OFF?
if not at begining of your code disable it!

__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON
 

Can someone tell me what's wrong with this code? My diagram is similar to the one posted on this website : https://www.oz1bxm.dk/PIC/628LED.htm except I am using Pin RB8 to go into the LED and my MCLR goes directly to 5V without a resistor.


Code:
#include<htc.h>
#include<stdio.h>
#include <stdlib.h>

#define _XTAL_FREQ 4000000



int main(void)
{
__CONFIG(FOSC_INTOSCIO& LVP_OFF & WDTE_OFF   & PWRTE_ON  & BOREN_ON);
	TRISB=0x00; // PORTB is output

while(1)
{
	PORTB=0x00;
	__delay_us(1000);
	PORTB=0xFF;
	__delay_us(1000);
}

return (0);

}
 

As for posting my circuit do you guys know any good software I can use to simulate and post the design of my circuit?

Use proteus for simulation.
Also check the crystal connections to uC.

Best wishes :)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top