cancel
Showing results for 
Search instead for 
Did you mean: 

How to make the keyword "click" to increment every time it enters the interrupt module. Please see the code below and help me out. All the time "Click" remains 0.

VSrin
Associate II

#include <iostm8l.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <stdint.h>

#include <math.h>

#include "defs.h"

static int click = 0;

void delay(unsigned long dd)

{

  unsigned long i;

  for (i=0;i<dd;i++) nop(); 

}

void RTC(void)

{

unsigned long j = 0;

PE_ODR |= 0x80; // led indication for reset 

if( click == 2) // reset module

{

click = 0;

 PC_ODR &= ~(1<<3); //pc3 in place of push button - turn it off here

 for(j = 0;j<20;j++)

 {

  delay(_250ms_); // 4.3 seconds in real

 }

}

if(click == 1) // on module

{

click++;

PC_ODR &= ~(1<<3); //turn it off

for(j = 0;j<8;j++)

 {

delay(_250ms_); // wait

 }

}

if (click == 0) // off module

{

PC_ODR &= ~(1<<3); //turn it off

click++;

 for(j = 0;j<8;j++)

 {

delay(_250ms_); // wait

 }

  PC_ODR |= (1<<3); // turn it on

 for(j = 0;j<8;j++)

 {

delay(_250ms_); // wait

 }

 PC_ODR &= ~(1<<3); //turn it off

 for(j = 0;j<8;j++)

 {

delay(_250ms_); // wait

 }

}

RTC_ISR2=0x00; // clear interrupt flags

}

void SetupTimers(void)

{

CLK_CRTCR=0x04; // use iternal LSI/1 clock @ ~38KHz

 RTC_WPR=0xCA;

RTC_WPR=0x53;

RTC_CR2=0x00; // disable wakeup timer for register update

while(!(RTC_ISR1 & 0x04));

  RTC_CR1=0x04; // set 1hz clk

RTC_WUTRH=0x00; // change here for time change

RTC_WUTRL=0x78; //2 min timer

RTC_CR3=0x00; 

RTC_CR2=0x44; // turn on timer and interrupt

RTC_WPR=0xFF; // lock the device

}

main()

{

CLK_DIVR = 0x00; // Set the frequency to 16Mhz

CLK_PCKENR2 = 0x07; // clock for timer1

 PC_DDR = 0x08; //direction input for push button

PC_CR1 = 0x08; //floating input pc3

PE_DDR = 0x80; // direction output for led

 PE_CR1 = 0x80; // fast push pull mode

SetupTimers();

_asm("rim\n"); // enable interrupt

while(1)

{

PC_ODR |= (1<<3); // turn it on

PE_ODR &= ~(0x80);

}

}

0 REPLIES 0