# Pic microcontroller not giving any response.no output at all.plz help

Status
Not open for further replies.

#### mugheesnawaz

##### Member level 1
i am using pic 16f877a for my project and i am using very basic code to get 5V on certain pins,i am using 20Mhz crystal and two 22pF capacitors.i am giving +5v on VDD and gnd on Vss and giving +5V on MCLR.but i dont get any output at all.plz help.i have set the oscillator to HS as i am using 20Mhz crystal.maybe my crystal isnt working how do i verify if its working or not? i am using mplab.i have read on forums about giving 13V to MCLR? is it true? i am giving 5V as of now.

Code:
#include <htc.h>
#define _XTAL_FREQ 20000000
void main()
{
TRISD=0;
while(1)
{
RD2=0;
RD3=1;
RD4=0;
}
}

#### milan.rajik

##### Banned
MCLR should be pulled up to 5V using 10k resistor. How is config bits set ? In IDE ?

#### betwixt

##### Super Moderator
Staff member
NEVER put 13V on MCLR for normal use. It puts the PIC into programming mode so it should only be used by your programming equipment to load the code into the IC. At any other time it is quite likely to corrupt the program. You should have it pulled to 5V (or whatever VDD voltage you use) so the PIC is taken out of reset state.

You should also have decoupling capacitors across each pair of power pins.

Brian.

#### Aussie Susan

Just a note: defining the _XTAL_FREQ symbol does nothing unless you also use the various _delay macros. It does not in any way set the oscillator configuration.
To check whether the oscillator is working you could use a scope (assuming it has a high enough impedance).
However, if you are using MPLAB, then use the debug mode and single step your way through the code. If the oscillator is not working then the device will not respond to the debugger; if it is then you will be able to step your way through the program.
You might be getting caught by the RMW problem that can occur in devices that don't have the 'LAT' registers (as the later Microchip devices do). Try setting the whole of the PORTD register at once (and it does not need to be within the main loop) rather than various bits at a time. Also try setting more pins to '1' - the the moment you are only setting PORTD bit 3 to logical 1 (whereas the beginning of your post uses "pins" plural).
Susan

#### MUKESH.K.S

##### Full Member level 1
You can set the configuration bits like this

Code C - [expand]1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <htc.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 20000000
#endif
__CONFIG(FOSC_HS & WDTE_OFF& PWRTE_OFF & BOREN_OFF &
LVP_OFF & WRT_OFF & DEBUG_OFF & CPD_OFF & CP_OFF);
void main()
{
TRISD=0;
while(1)
{
RD2=0;
RD3=1;
RD4=0;
}
}

Last edited by a moderator:

Status
Not open for further replies.