i have a problem regarding using timer0 interrupt service routine and calling function. my program will decrement the i and j (static unsigned int) everytime timer0 overflow. my program working as i wish if both of these function below are in the same file (main.c). but if i move the mINT_TIMER0 to another file (timer.c), my program doesn't work. in file main.c
static void timer0_isr (void) interrupt 1 { mINT_TIMER0(); }
#pragma NOAREGS void mINT_TIMER0 (void) { TR0 = 0; TH0 = (65536-8950)/256; TL0 = (65536-8950)%256; TR0 = 1; i--; j--; } #pragma AREGS
Have you heard of Header Files? This is standard 'C' - nothing specifically to do with Keil - so see any 'C' textbook!
in main.c and timer.c, i use
#include "control.h"
#include "w925e240.h" #include "main.h" #include "sfr.h"
#ifndef main_HEADER_FILE #define main_HEADER_FILE 1 static unsigned int i; static unsigned int j; void mTIMER0_INIT (void) ; void mINT_TIMER0 (void) ; #endif
Your header file is a little weird. Are you aware that you declare 2 ints in EVERY FILE where this header is included? This will rapidly eat up all of your data space. Jon
ah ... thanks ... it's ok now ... in main.c,
#include "control.h" volatile unsigned int i; volatile unsigned int j;
#include "control.h" extern volatile unsigned int i; extern volatile unsigned int j;
Yep - that's a lot better. Jon