-
interrupt question
this programe shows digital clock and blink text.. in graphic mode
but system is down...
what's problem????
help me pls~~~~
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <dos.h>
void interrupt(*old_blink)();
void interrupt (*old_timertick)();
void interrupt Blink();
void interrupt TimeDis();
void End_Time();
void Time_Display();
void Blink_Set(void);
void End_Blink(void);
unsigned int clock_tick = 0, blink_tick = 0, temp = 0;
void main(void)
{
int gdriver = DETECT, gmode;
int count= 0;
initgraph(&gdriver, &gmode, "");
Blink_Set();
Time_Display();
while(!kbhit())
{
}
End_Blink();
End_Time();
closegraph();
}
void Blink_Set(void)
{
disable();
old_blink = getvect(0x1c);
setvect(0x1c, Blink);
enable();
}
void interrupt Blink()
{
(*old_blink)();
blink_tick++;
if(blink_tick == 10)
{
if(temp % 2 == 0)
{
setcolor(WHITE);
outtextxy(300, 240, "test ^^ ");
}
else
{
setcolor(RED);
outtextxy(300, 240, "test ^^ ");
}
blink_tick = 0;
temp++;
}
}
void End_Blink(void)
{
setvect(0x1c, old_blink);
}
void End_Time(void)
{
setvect(0x1c,old_timertick);
}
//--------------------------------------------------------------------------
void Time_Display(void)
//--------------------------------------------------------------------------
{
disable();
old_timertick = getvect(0x1c);
setvect(0x1c, TimeDis);
enable();
}
//--------------------------------------------------------------------
void interrupt TimeDis()
//--------------------------------------------------------------------
{
char string[100], am_pm;
int save;
struct time t;
struct date d;
(*old_timertick)();
clock_tick++;
if(clock_tick > 18)
{
save = getcolor();
setcolor(WHITE);
gettime(&t);
getdate(&d);
settextstyle(0,0,1);
if(t.ti_hour > 12 )
{
t.ti_hour = t.ti_hour - 12;
am_pm = 'P';
}
else
am_pm = 'A';
sprintf(string, "%d/%d/%d %cM %d:%d:%d", d.da_year,
d.da_mon,d.da_day,am_pm, t.ti_hour, t.ti_min, t.ti_sec);
setfillstyle(SOLID_FILL, BLACK);
bar(4, 426,170, 444);
setcolor(WHITE);
settextjustify(LEFT_TEXT,CENTER_TEXT);
outtextxy(5, 423+(getmaxy()-423)/4, string);
setcolor(save);
clock_tick = 0;
}
}
-
For starters, doing lots of stuff inside ISRs is generally a bad idea, especially if you don't know for sure that such routines are safe to use in ISR's
Then I would do this
1. remove all the code from your interrupt routines, EXCEPT for the increment of the two counters.
2. Then do this
Code:
while(!kbhit())
{
printf( "Counts=%d %d\n", clock_tick, blink_tick );
}
Until this works, there's no point doing anything graphical.
Once you've seen your counters incrementing as expected, then move on to the more advanced stuff.
-
thanks
-
But don't do the printf() inside the interrupt. It will crash.
DOS tech ref states that it is safe to use int21h functions inside of an interrupt if the INDOS flag is set to 0. If not, don't invoke int21h. Some C i/o functions just invoke int21h so be very careful which functions you use and which ones you don't.
For instance, doing a read() in an interrupt handler will crash the system and will also crash Windows.
It has been my experience while writing a DOS sound system that you should not do any i/o within an interrupt handler and never before sending EOI to the PIC (when applicable)