• 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.

Problem with PIC code

Thread starter #1
I have recently burn a pic 16f690. But the chip is not giving desirable output. It is not not for any I/P and giving garbage value like a counter. But it should take I/P and give O/P according to I/P.
I think the problem is in the given part of the code below. I am using 4MHz oscillator and 22pf booster. If anybody can help I will be really thankful to him.

"
#include<pic.h>
#define _XTAL_FREQ 4000000 //4MHz Crystal

__CONFIG (INTIO & WDTDIS & PWRTEN & MCLREN & UNPROTECT & UNPROTECT & BORDIS & IESODIS & FCMDIS); "
 

Pommie

Well-Known Member
Most Helpful Member
#4
If you are using an external crystal then your config needs state XT oscillator. However, I doubt that is your problem and, as Ian says, you need to post your code.

Mike.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#5
If you are using an external crystal then your config needs state XT oscillator. However, I doubt that is your problem and, as Ian says, you need to post your code.

Mike.
Oh Yeah... Missed that... However that usually causes the pic not to run atall, I've never tried to run a pic like that so it'll be guesswork
 
Thread starter #6
Thanks guys. Here is my code
#include<pic.h>
#include<pic.h>
#include<htc.h>
#define _XTAL_FREQ 4000000 //4MHz Crystal

__CONFIG (INTIO & WDTDIS & PWRTEN & MCLREN & UNPROTECT & UNPROTECT & BORDIS & IESODIS & FCMDIS);

#define votting_time 3000

int BNP,AL,JP,GJM,HI;

display(int x)
{
int y,z;
y=x/10;
z=x%10;
PORTC=(y<<4)+z;
}

int main()
{

ANSEL=0;
ANSELH=0;

TRISA=0b111111;
TRISB4=1;
TRISB5=1;
TRISB6=1;
TRISB7=1;
TRISC=0b00000000; //PORTC As Output Port
PORTC=0;




while(1)
{
BNP=eeprom_read(1);
AL=eeprom_read(2);
JP=eeprom_read(3);
GJM=eeprom_read(4);
HI=0;

if(RB4==1)
{

if(RA0==0)
{
BNP++;
eeprom_write(1,BNP);
display(BNP+AL+JP+GJM+HI); // display data to 7segment
__delay_ms(votting_time);
}

else if(RA1==0)
{
AL++;
eeprom_write(2,AL);
display(BNP+AL+JP+GJM+HI); // display data to 7segment
__delay_ms(votting_time);
}


else if(RA2==0)
{
JP++;
eeprom_write(3,JP);
display(BNP+AL+JP+GJM+HI); // display data to 7segment
__delay_ms(votting_time);

}
else if(RB7==0)
{
GJM++;
eeprom_write(4,GJM);
display(BNP+AL+JP+GJM+HI); // display data to 7segment
__delay_ms(votting_time);
}
else if(RA3==0)
{
HI++;
eeprom_write(5,HI);
display(BNP+AL+JP+GJM+HI); // display data to 7segment
__delay_ms(votting_time);
}
}

if(RB4==0)
{

if(RA0==0)
{
display(eeprom_read(1)); // display data to 7segment
}


else if(RA1==0)
{
display(eeprom_read(2)); // display data to 7segment
}

else if(RA2==0)
{
display(eeprom_read(3)); // display data to 7segment
}

else if(RB7==0)
{
display(eeprom_read(4)); // display data to 7segment
}
else if(RA3==0)
{
display(eeprom_read(5)); // display data to 7segment
}
__delay_ms(2000); // 2 sec dealy


}

if(RB6==0)
{

if(eeprom_read(1)>eeprom_read(2))
{
if(eeprom_read(1)>eeprom_read(3))
{
if(eeprom_read(1)>eeprom_read(4))
{
if(eeprom_read(1)>eeprom_read(5))
{
display(1);
__delay_ms(3000);
}
else display(5);
}
else if(eeprom_read(4)>eeprom_read(5))
{
display(4);
__delay_ms(3000);
}
else display(5);
__delay_ms(3000);
}
else if(eeprom_read(3)>eeprom_read(4))
{
if(eeprom_read(3)>eeprom_read(5))
{
display(3);
__delay_ms(3000);
}
else display(5);
__delay_ms(3000);
}
else if(eeprom_read(4)>eeprom_read(5))
{
display(4);
__delay_ms(3000);
}
else display(5);
__delay_ms(3000);
}
else if(eeprom_read(2)>eeprom_read(3))
{
if(eeprom_read(2)>eeprom_read(4))
{
if(eeprom_read(2)>eeprom_read(5))
{
display(2);
__delay_ms(3000);
}
else display(5);
__delay_ms(3000);
}
else if(eeprom_read(4)>eeprom_read(5))
{
display(4);
__delay_ms(3000);
}
else display(5);
__delay_ms(3000);
}
else if(eeprom_read(3)>eeprom_read(4))
{
if(eeprom_read(3)>eeprom_read(5))
{
display(3);
__delay_ms(3000);
}
else display(5);
__delay_ms(3000);
}
else display(5);
__delay_ms(3000);
}







if(RB5==0)
{
BNP=0;
AL=0;
JP=0;
GJM=0;
HI=0;

eeprom_write(1,BNP); // Erase Data AL
eeprom_write(2,AL); // Erase Data AL
eeprom_write(3,JP); // Erase Data AL
eeprom_write(4,GJM); // Erase Data AL
eeprom_write(5,HI); // Erase Data AL
display(0); // display data to 7segment
__delay_ms(2000); // 2 sec dealy
}

return 0;

}

}
 
Last edited:

Latest threads

EE World Online Articles

Loading

 
Top