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.

8051 external interrupt problem

Status
Not open for further replies.

0killingsoul0

Junior Member level 2
Junior Member level 2
Joined
Feb 8, 2012
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,432
View attachment one.bmpHi all. I am getting a weird type of error.Its a simle code to count the interrupts in ten second. When i physically implement the circuit on bread board , its counting more low level signals ( grounding the pin 3.2) . Like if i ground it once it should count/display one but its displaying larger value. This code is working perfectly on proteus and on trainer kit. But dont know what i am missing in circuit its not working.



View attachment one.bmp


View attachment one.rar


Code:
 				 		   // Program to interface single seven segment
 
#include<reg51.h>
 char num[]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10};		// Hex values corresponding to digits 0 to 9


unsigned int counter;
unsigned int counter1;
unsigned int counter2;
unsigned int counter3;

unsigned int counter4;



delay_ms(int time)		// Time delay function
{
	int i,j;
 	for(i=0;i<time;i++)
  	for(j=0;j<1275;j++);
}
	



 ////////////// iNTERUPT tO cOUNT
void ex0_isr (void) interrupt 0
{
	counter++;   // Increment the count
}



void countdelay(void)
{
	TMOD=0x01;
	TL0=0x00;
	TH0=0x00;
	TR0=1;
	while (TF0==0);
	TR0=0;
	TF0=0;
}


void main()
{  
unsigned int c;	
 

 IT0 = 1;   // Configure interrupt 0 for falling edge on /INT0 (P3.2)
	  EX0 = 1;   // Enable EX0 Interrupt
    
	  EA = 1;    // Enable Global Interrupt Flag
	


  //  counter=6709;

	P0=num[0]; 
		P1=num[0]; 
		P2=num[0];



	while(1)
	{
	

		


			 for(c=0;c<154;c++)
		  {
		    countdelay();		 // 65.535 ms delay
		  }

	
		 
		 
		 
	
		 
	
	
		  counter1=counter%10;

	
	
		  counter2=(counter/10)%10;

	      counter3=(counter/100)%10;
	

		  

     	P0=num[counter1]; 
		P1=num[counter2]; 
		P2=num[counter3]; 
		counter=0;
	}

}
 

could you post the trainer kit you were using? (if you have an schematic, post it too) as it seems a bit more complex than your simple push button...

in simulation this will work with no flaws, but in a real implementation the bouncing and debouncing of the push button WILL ALWAYS produce extra pulses for the microcontroller.
there you implement a debouncing circuit.
you could search more, but the one i used a lot is the **broken link removed** as it will do the job.


now, maybe you can improve a little with an external pull-up for the push-button, something like 4k7 or 10k ohm,
otherwise you need to implement this in software, but it's a difficult task as you wanted to count via interrupt.

That's why me would like to see which development kit you used and worked...
 

Hi,

Initial value for variable counter in main program should be set to 0. ie. counter=0; . Tq.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top