interrupt question

This is a discussion on interrupt question within the C Programming forums, part of the General Programming Boards category; this programe shows digital clock and blink text.. in graphic mode but system is down... what's problem???? help me pls~~~~ ...

  1. #1
    Unregistered
    Guest

    Question 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;
    }
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,505
    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.

  3. #3
    Unregistered
    Guest

    Talking thanks

    thank you very much.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM
  4. interrupt handler functions in Visual C++ 6.0
    By scromer in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-07-2002, 06:06 PM
  5. Sound card interrupt problems
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-05-2001, 03:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21