Pic Project

Thread Starter

royalmadhu

Joined Feb 4, 2011
6
Hi i'm trying to build a circuit that tells the time in seconds in four 7 segment displays when a button is being pressed...I'm using a 16F84A... i have used latch enabled decoders .i have assigned the certain button to porta.f0


the problem is when i run the program in Proteus and it only shows 0000..no matter how long i pressed it..when i put count=4546 like a number in the main function it shows that...but it doesnt shpw it when i put it outside the main function..
this is my program

plzzz help me

thx in advance

Rich (BB code):
 unsigned int count,count1; 

void display(int,int,int,int)  ; 

void interupt(void) 
{ 

if (intcon.t0if==1) 
 { 
 if (porta.f0==1) 
 { 

count1=count1+1; 

if (count1==10) 
{ 
count1=0; 
count=count++; 
if (count ==9999) 
{ 
count=0; 
} 
} 
} 
} 
else if(porta.f1==1) 
{ 
count1=0; 
count=0; 
} 
intcon.t0if=0; 


} 

void main() 
{ 
int a,b,c,d; 
intcon= 0b10100000; 
option_reg= 0b00000111; 
trisa=0b11111; 
trisb=0b000000000; 
count1=count=0; 

while(1) 
{ 
a=count/1000; 
b=((count%1000)/100); 
c=(((count%1000)%100)/10); 
d=((((count%1000)%100)%10)/1); 
display(a,b,c,d); 
} 
} 

void display(int x,int y,int z,int w) 
{ 
if (x==0) 
{ 
portb=0b00000001; 
} 
if (x==1) 
{ 
portb=0b00010001; 
} 
if (x==2) 
{ 
portb=0b00100001; 
} 
if (x==3) 
{ 
portb=0b00110001; 
} 
if (x==4) 
{ 
portb=0b01000001; 
} 
if (x==5) 
{ 
portb=0b01010001; 
} 
if (x==6) 
{ 
portb=0b01100001; 
} 
if (x==7) 
{ 
portb=0b01110001; 
} 
if (x==8) 
{ 
portb=0b10000001; 
} 
if (x==9) 
{ 
portb=0b10010001; 
} 
if (y==0) 
{ 
portb=0b00000010; 
} 
if (y==1) 
{ 
portb=0b00010010; 
} 
if (y==2) 
{ 
portb=0b00100010; 
} 
if (y==3) 
{ 
portb=0b00110010; 
} 
if (y==4) 
{ 
portb=0b01000010; 
} 
if (y==5) 
{ 
portb=0b01010010; 
} 
if (y==6) 
{ 
portb=0b01100010; 
} 
if (y==7) 
{ 
portb=0b01110010; 
} 
if (y==8) 
{ 
portb=0b10000010; 
} 
if (y==9) 
{ 
portb=0b10010010; 
} 
if (z==0) 
{ 
portb=0b00000100; 
} 
if (z==1) 
{ 
portb=0b00010100; 
} 
if (z==2) 
{ 
portb=0b00100100; 
} 
if (z==3) 
{ 
portb=0b00110100; 
} 
if (z==4) 
{ 
portb=0b01000100; 
} 
if (z==5) 
{ 
portb=0b01010100; 
} 
if (z==6) 
{ 
portb=0b01100100; 
} 
if (z==7) 
{ 
portb=0b01110100; 
} 
if (z==8) 
{ 
portb=0b10000100; 
} 
if (z==9) 
{ 
portb=0b10010100; 
} 
if (w==0) 
{ 
portb=0b00001000; 
} 
if (w==1) 
{ 
portb=0b00011000; 
} 
if (w==2) 
{ 
portb=0b00101000; 
} 
if (w==3) 
{ 
portb=0b00111000; 
} 
if (w==4) 
{ 
portb=0b01001000; 
} 
if (w==5) 
{ 
portb=0b01011000; 
} 
if (w==6) 
{ 
portb=0b01101000; 
} 
if (w==7) 
{ 
portb=0b01111000; 
} 
if (w==8) 
{ 
portb=0b10001000; 
} 
if (w==9) 
{ 
portb=0b10011000; 
} 

}
 
Last edited by a moderator:

debjit625

Joined Apr 17, 2010
790
Check from datasheet if you have set properly the interupt reg or not like option reg , intcon reg in main function ,I dont think so you have did it properly .
If yes then also your program will not function properly because your logic is not correct i.e..
Not every time your interupt occurs,and you have gave a condition that the count variable be only updated if PORTA.F0 is 1 so it cant update its time if you dont press your switch.

Rich (BB code):
if (intcon.t0if==1) 
{ 
  if (porta.f0==1) 
  { 
    //.....your code..........
  }
}
To check
Put the codeof "if(porta.f0 == 1) {....}" from the interupt function inside the main's while() loop to check how it works.

Good Luck
 

debjit625

Joined Apr 17, 2010
790
One more thing when using language "C" we dont write that big algo as you did it for display function their are more better way to do that display stuff but for now its ok as it seems you are also new to "C".

Anyway welcome to AAC.
 

spinnaker

Joined Oct 29, 2009
7,830
Did you make any attempt at all to debug your own code?

First you need to determine the source of your problem. Is it input or your output that is causing the problem.

Determine that your input code is working as expected or not. Write a small sample program just to test the input. Post ONLY that code. But first debug it on your own. After and only after you have done some debugging on your own, post back with your findings and I will try and help further.
 
Top