This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using the External Interrupt 1

Hi there, I am trying to get a signal to the P89LPC932 Micro Controller by using the External interrupt 1 (P1.4). I never tried this before and I am also a beginner programming. Can anyone help me figuring out why this program does not work. The interrupt is supposed to be edge triggered and every time an interrupt occurs a counter (NPulses) is incremented til it gets to 1000 pulses. then it goes back to zero. I think my problem is configuring the timers registers, but I am not too sure.

Here is the code.
Thank you,

============================================
#include <Reg932.h>
#include <stdio.h>

void init(void);
void brkrst_init(void);
void Pulses_recieved (void);
unsigned long NPulses; //amount of pulses received
unsigned int Glass;
void ToggleC1Input (void);
sbit Pulse = P1^4;
int Glassid, count;

void Main(void)
{
P2 = 0x00;
NPulses = 0;
Glass = 10;
Glassid = 0;
count = 0;
init();
brkrst_init();
Pulses_recieved();
}

void init(void)
{
P1M1 = 0xFF; // Input only
P1M2 = 0x00;
P2M1 = 0x00; // push pull output
P2M2 = 0xFF;
ES = 1; EA = 1;
}

void brkrst_init(void) // This function allows ISP entry through the UART break detect
{
AUXR1 |= 0x40; // enable reset on break detect, pg. 102
SCON = 0x50; // select the BRG as UART baud rate source, pg. 60
SSTAT = 0x00;
//TCON = 0x04;
BRGR0 = 0x70; // 9600 BAUD at 11.0592 MHz. Hex 0470= 1136 decimal
BRGR1 = 0x04;
BRGCON = 0x03; // enable BRG, pg. 59
}

void UART(void) interrupt 4
{
RI = 0;
}

void Pulses_recieved(void)
{
while(1)
{
TCON = 0x40;
IEN0 = 0x04;
EA = EA | 1;
}
}

void ExtPulses (void) interrupt 2
{
NPulses++;
if (NPulses == 1000)
{
NPulses = 0;
Glassid++;
P2 = Glassid;
}
}
=============================================

Parents
  • How are you Oleg Sergeev. I wanted to thank you for your help on this part of the project I'm implementing. However, I need to put the micro controller in Power Down Mode if it is not receiving any pulses at the T0 pin (P1^2). Do you have any ideas on how can this be done. I'm thinking of putting a waiting period and if no pulses are received then go to sleep...how much time should I wait...how do I calculate that.
    Thank you again

Reply
  • How are you Oleg Sergeev. I wanted to thank you for your help on this part of the project I'm implementing. However, I need to put the micro controller in Power Down Mode if it is not receiving any pulses at the T0 pin (P1^2). Do you have any ideas on how can this be done. I'm thinking of putting a waiting period and if no pulses are received then go to sleep...how much time should I wait...how do I calculate that.
    Thank you again

Children
  • Hi,
    What is the problem to put MCU into Power Down mode? The main problem I see is that after PD mode will be activated your MCU stays at this mode till external reset generated (some MCUs allow to wake up from other inputs; unfortunately - not via T0/T1 pins). Are you sure that you need to stop all the program once really? Maybe it should be Idle mode?
    Anyway if so then I dunno about waiting time calculation because we need to know about frequence of input pulses at least.
    Btw, sorry about silence. You know, the main usage of the forum is the compiler/linker/debuger problems, but the program issues itself --- I recommend you to visit http://www.8052.com

    good days!

  • Dear:
    Oleg Sergeev
    The "external interrupt" program you helped on (receiving pulses through timer 0)is working fine. I have added more details (tasks) to it and now it looks like its counting more pulses than the expected. This is a multitasking problem (I think) could you give me an idea what could be wrong?
    Thank you