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.

Urgent Help Needed to fix asm code error

Status
Not open for further replies.
Full Member level 1
Joined
May 1, 2010
Messages
119
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,308
Location
India, Kerala, Moolamattom
Visit site
Activity points
0
Thanks to all

Please Help me to fix an error in my asm code

Hope somebody help me


This is the code
------------------------------------------------------------------------------------------
Code:
#include <reg52.h>
#define ON 0
#define OFF 1
#define true 1;
#define false 0;
sbit LED = P1^0;
sbit sw =P3^0;

void Tmr0Init();

void Tmr0() interrupt 1 
{
unsigned char cnt;
cnt++;
if(cnt==500) {
	LED = ~LED; 
	cnt=0;
} 
TH0 = 0xDC; 
TL0 = 0x00;
}

void Tmr0Init(void) 
{
TMOD=TMOD&0xF0; 
TMOD=TMOD|0x01;
TH0 = 0xDC;
TL0 = 0x00;
ET0 = 1; 

}
void main(void)
{
Tmr0Init(); 
EA = 1; 
for(;;)
{
 if(sw == 0)
   {
    k=debounce(50);
    if(k==0){
		LED=0;
		TR0 = 1; 
	}
   }
   else{
		LED = 1;		
   } 
}
}

int debounce(unsigned int a)
{
 unsigned int i,j;
 j=sw;
 for(i=0;i<=a;i++)
 {
  for(i=0;i<=256;i++);
 }
 if(sw == j)
 {
  return true;
 }
 else
 {
  return false;
 }
}





----------------------------------------------------------------------------------

See the attachments

Thanks in advance

Manoj Soorya
 

Attachments

  • 89c51.png
    89c51.png
    220.3 KB · Views: 123
Last edited by a moderator:

Please Help me to fix an error in my asm code

I don't see a single line of assembly in your code, am I missing something.
You mention nothing of the error message you got or the line that has the problem.

- - - Updated - - -

One thing I notice is the use of a counter variable in the interrupt that is not static, that means the value is lost when you exit the handler.
In addition never use a local variable before initializing it, in your code below (assuming it was correct for this case) you will never know the initial value of cnt so don't assume 0.
Code:
unsigned char cnt;
    cnt++;

In order to preserve the value use
Code:
static unsigned char cnt=0;
    cnt++;
 

what compiler are you using ?
what is the error message ?
regards,


I am using keil for compiler

- - - Updated - - -

I don't see a single line of assembly in your code, am I missing something.
You mention nothing of the error message you got or the line that has the problem.

- - - Updated - - -

One thing I notice is the use of a counter variable in the interrupt that is not static, that means the value is lost when you exit the handler.
In addition never use a local variable before initializing it, in your code below (assuming it was correct for this case) you will never know the initial value of cnt so don't assume 0.
Code:
unsigned char cnt;
    cnt++;

In order to preserve the value use
Code:
static unsigned char cnt=0;
    cnt++;




Actually the code written my friend. I am not know to write the programe. He elped me and now he was bussy. I am posting the hode here with his permission.
The code and the schematic not compatible....help me please sir.......

Thank you very much
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top