Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16f877a nothing happening

Status
Not open for further replies.

normad

Member
hey i programmed a 16f877a and once i plugged it into my board nothing seems to be happenning.. (sigh) yes ive checked power on both vdds and grounds on vss.. and yes ive connected a pull up to mclre..
my suspicion is on the crystal.. could it be that i burnt it while soldering it? or i may have dropped it once.. theres no way for me to know exactly cause this pic doesnt have an internal clock.. (does it?) can someone point me in the ryt direction to figure out if it is actually the crystal (i dont have access to an oscilloscope)
or could it be something else? im positive i set the configuration bit correctly.. i double checked.. but this is the first time im working with this particular pic
please help.. ive got deadline on monday :(

thanks in advance
 
Have you verifyed the code? write the code and configuration. P.S. Oscillators don't get corrupted by dropping. I think you may have configuration bits set wrong.
 
and it has no internal oscillator
 
When I run into this situation, I generally put the pic on a breadboard and run it off of the programmer (pickit2) just to verify the operation of the code AND the mcu.

The last protoboard problem I had was a bypass cap (you are using bypass caps right?) between vdd/vss was shorted. So take your dmm and verify no shorts etc. What kind of caps are you using for the crystal? What is the speed of the crystal? What are you config settings for said clock speed?

good luck.
 
Last edited:
the code is a bit long.. shall i post it nyways? i tried a simple program but still nothing happens.. the configuration part is

__CONFIG(LVPDIS & XT & WDTDIS & PWRTDIS & BORDIS & DUNPROT & WRTEN & DEBUGDIS & UNPROTECT);

and im using hitech c with mplab

i simulated the whole thing with proteus and it works just fine.. so i doubt its the configuration word
 
You can ruin a crystal soldering it. But not likely. Most times a crystal don't work it wrong kind bad caps or wrong configure
 
hmm.. could be the caps ryt.. i used two 22pf ones because of my experience with the 16f628a but i just saw on the datasheet that they recommend 15pf for the 4M crystal.. would that make much of a difference?
and if the program gets written to and verified completely it cant be nything wrong with the pic can it?
 
Crystals usually work with a range between 15-33pf i use 18 or 22 personally with USB and TCP/IP which are time critical and have had no problems at all, I think Microchip even use 18 or 22 on some of their demo boards.

Start with the basics.

Simple app to toggle a pin on and off every 1 second, then use a multimeter to check, or alternatively wire up a LED with a 330R resistor (if 5v VCC) to get visual.

If it doesn't work try a different PIC, also, if you are using proto board make sure that the tracks are cut correctly. And if using breadboard make sure there is no stray wires linking to something else.

I presume you program the chip out of circuit? as MPLAB holds the reset until you release it.

I have only had one PIC not work correctly since I have been using them, and there was an internal short as the PIC got red hot!

Wilksey
 
yeah well i tried that.. i checked the connections and everything.. and my simple program didnt work either..
 
Have you tried simulating the program? loading the HEX into a simulator such as Proteus or Oshonsoft?

Just to be sure your application works?

Wilksey
 
nopes i have neither :( but i guess ill go and get them tomorrow..

and eric heres the code :) its in c though

Code:
#include <htc.h>

__CONFIG(LVPDIS & XT & WDTDIS & PWRTDIS & BORDIS & DUNPROT & WRTEN & DEBUGDIS & UNPROTECT);

#define _XTAL_FREQ 4000000

char i_time = 0, d_time = 0, g_time = 0, g2_time = 0; 
int w_time = 0;
bit igno = 0, debo = 0;
bit check = 0;
bit swap = 0;
bit wait = 0,grace = 0, grace2 = 0;
bit off = 0, start = 0,safe = 0, power = 0;
bit blink1 = 0,blink2 = 0,blink3 = 0,blink4 = 0;
bit check_i = 0;
int time = 0;

void config();
void startup();

union outp {

	char con;
	struct one {
		unsigned AC7:1,AC6:1,AC5:1,AC4:1,AC3:1,AC2:1,AC1:1,NU:1;
	};
	struct one bits;
	
};

union outp output;

void main() {

	check_i = 0;
	config();
	startup();

	while(1) {

		if(start) {
			start = 0;
			if(RB6 && RB7)
				power = 1;
			else {
				grace2 = 1;
				TMR1ON = 1;
			}
			
		}
		if(power) {
			safe = 0;
			
			RD0 = 1; //turning on contactor drive
			debo = 1;
			TMR2ON = 1;
			while(debo);
	
			while(((RD6 == output.bits.AC1) || (RD5 == output.bits.AC2) || (RD4 == output.bits.AC3) || (RB0 == output.bits.AC4) || (RB1 == output.bits.AC5) || (RB2 == output.bits.AC6) || (RB3 == output.bits.AC7)) && check_i) {
				blink1 = 1;
				TMR1ON = 1;
			}
			blink1 = 0;

			RC2 = 1; //turning on main contactor
			debo = 1;
			TMR2ON = 1;
			while(debo);
			
			while(RD7 && check_i) {
				blink2 = 1;
				TMR1ON = 1;
			}
			blink2 = 0;

			power = 0;
			blink4 = 0;
			RD2 = 0;
			RD3 = 0;
			
		}
	
		if(off) {
			
			RC2 = 0;	//turning off main contactor
			debo = 1;
			TMR2ON = 1;
			while(debo);
			
			while(!RD7 && check_i) {
				blink2 = 1;	
				TMR1ON = 1;
			}
			blink2 = 0;

			RD0 = 0;  //turning off contactor drive

			debo = 1;
			TMR2ON = 1;
			while(debo);
			
			while((!RB0 || !RB1 || !RB2 || !RB3 ||  !RD4 || !RD5 || !RD6) && check_i) {
				blink1 = 1;
				TMR1ON = 1;
			}
			blink1 = 0;
			
			wait = 1;
			blink4 = 1;
			TMR1ON = 1;
			off = 0;
			safe = 1;

			
		}

		if(swap && safe) {			
			
			RA0 = 0;
			RA1 = 0;
			RA2 = 0;
			RA5 = 0;
			RE1 = 0;
			RE2 = 0;
			RC1 = 0;
			
			switch (output.con) {
			
				case 1:
					RA1 = 1;
					break;
				case 2:
					RA0 = 1;
					break;
				case 4:
					RA2 = 1;
					break;
				case 8:
					RA5 = 1;
					break;
				case 16:
					RE1 = 1;
					break;
				case 32:
					RE2 = 1;
					break;
				case 64:
					RC1 = 1;
					break;
			} 
			
			swap = 0;

			if(!RB6 || !RB7) {
				grace = 1;
				TMR1ON = 1;
			}

		}

			
	}
	
}

void config() {
	
	GIE = 1;
	PEIE = 1;
	ADCON0 = 0b00000000; //AD module off;
	ADCON1 = 0b00001111; //port A and port B digital IO;

	PORTA = 0;
	TRISA = 0b00011000; //configure port A
	RBIE = 1;
	TRISB = 0b11111111; //configure port B
	PORTC = 0;
	TRISC = 0b11111001; //configure port C
	PORTD = 0;
	TRISD = 0b11110000; //configure port D
	PORTE = 0;
	TRISE = 0b00000001; //configure port E

	TMR2IE = 1;
	T2CON = 0b01111011;
	TMR2 = 0;
	PR2 = 0b00100111; // configure timer 2 : prescalar 16 : post scalar 16

	TMR1IE = 1;
	TMR1H = 0b00001011;
	TMR1L = 0b11011100;
	T1CON = 0b00110000; //configure timer 1 : prescalar 8

	

}

static void interrupt int_handler(void) {

	if(TMR1IF) {

		TMR1IF = 0;
		TMR1H = 0b00001011;
		TMR1L = 0b11011100;

		if(check)
			time++;

		if(grace)
			g_time++;
		
		if(grace2)
			g2_time++;

		if(wait)
			w_time++;
	
		if(grace2 && (g2_time>12)) {
			start = 1;
			grace2 = 0;
			g2_time = 0;
		}
	
		if(blink1) {
			RD2 = !RD2;
			RD3 = 0;
		}
		
		if(blink2) {
			RD3 = !RD3;
			RD2 = 0;
		}

		if(!blink1 && !blink2 && blink3) {
			RD2 = !RD2;
			RD3 = RD2;
		}

		if(!blink1 && !blink2 && !blink3 && blink4) {
			RD2 = !RD2;
			RD3 = !RD2;
		}
	
		if(grace && (g_time>10)) {
			if(!RB6) {
				if(output.con<64) {
					output.con = output.con << 1;
				}
				else 
					blink3 = 1;
			}
			if(!RB7) {
				if(output.con>1) {
					output.con = output.con >> 1;
				}
				else
					blink3 = 1;
			}

			if(!safe)
				off = 1;

			swap = 1;
			
			grace = 0;
			g_time = 0;
		}

		if(wait && (w_time>30)) {    //*****************************NEED TO MAKE IT 360**************************
			start = 1;
			wait = 0;
			w_time = 0;
		}

		if(check && (time>10))	{
			
			if(!RB6) {
				if(output.con<64) {;
					output.con = output.con << 1;
				}
				else 
					blink3 = 1;
			}
			if(!RB7) {
				if(output.con>1) {
					output.con = output.con >> 1;
				}
				else
					blink3 = 1;
			}

			if(!safe)
				off = 1;

			swap = 1;

			check = 0;
			time = 0;
		}

		if(!wait && !grace2 && !check && !grace && !blink1 && !blink2 && !blink3 && !blink4)
			TMR1ON = 0;
	}

	if(TMR2IF) {
		TMR2IF = 0;
		TMR2 = 0;
		if(igno) {
			i_time++;
			if(i_time>15) {
				igno = 0;
				i_time = 0;
				check = 1;
				time = 0;
				TMR1ON = 1;
			}
		}
		if(debo) {
			d_time++;
			if(d_time>15) {
				debo = 0;
				d_time = 0;
			}
		}
		if(!igno && !debo)
			TMR2ON = 0;
	}

	if(RBIF) {
		RBIF = 0;
		if(!igno) {

			if(check) {
				check = 0;
				time = 0;
			}

			if(grace) {
				grace = 0;
				g_time = 0;
			}

			if(blink3) 
				blink3 = 0;
				
			if(!RB7 || !RB6) {		
				igno = 1;
				TMR2ON = 1;
			}
		}
	}

}

void startup() {

	RA5 = 1;
	output.con = 0b0001000;
	time = 0;
	RD0 = 1;
	RC2 = 1;
	safe = 0;

}
 
Woops its in 'C', I am afraid I dont do 'C',,, there are plenty of 'C' users on the Forum.

If you give your location some member may live close to you who could check out your suspect PIC..
 
yeah i recall you being familiar with assembly from previous posts i read :) thanks anyways.. :)

and i highly doubt theres anyone nearby me as im from srilanka.. (yeah its a country hehe)

i shall try changing my caps and crystal tomorrow and ill be back with the results..
 
yeah i recall you being familiar with assembly from previous posts i read :) thanks anyways.. :)

and i highly doubt theres anyone nearby me as im from srilanka.. (yeah its a country hehe)

i shall try changing my caps and crystal tomorrow and ill be back with the results..

Hi,
As a PIC test you could use a resistor/capacitor oscillator and edit the PIC's CONFIG code to suit.

I sold some laser rangers into Colombo, Sri Lanka thru the British Crown Agency....:)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top