/* DEMO96.c: Using a timer interrupt function to controll the 5-Digit 7-segment LED. Compiler: BC++ 3.1, Turbo C++ 1.01 (3.01), MSVC 1.52 Compile mode: Large Project: DEMO96.c ..\..\Lib\upac5000.lib Hardware: uPAC-5000 Description TimerOpen(): Starts the timer. TimerClose(): Stops the timer. If TimerOpen() is called within your program, it must call TimerClose() before exiting. InstallUserTimer(): Install a custom timer function and the function will be called at regular intervals of 1 ms. Each digit of the LED is numerically identified from left to right using the numbers 1 to 5. 5-Digit 7-segment LED show 0 to F. LED #1 will be updated every 1 sec LED #2 will be updated every 0.5 sec LED #3 will be updated every 0.4 sec LED #4 will be updated every 0.3 sec LED #5 will be updated every 0.2 sec [Dec 21, 2011] by Liam */ #include #include "..\..\lib\upac5000.h" void MyTimerFun(void) { static int count[5]={0, 0, 0, 0, 0}; static int Data[5]={0, 0, 0, 0, 0}; int i; for(i=0; i<5; i++){ count[i]++; } if(count[0]>=1000){ count[0]=0; Data[0]++; Data[0]&=0x0F; Show5DigitLedWithDot(1, Data[0]); } if(count[1]>=500){ count[1]=0; Data[1]++; Data[1]&=0x0F; Show5DigitLed(2, Data[1]); } if(count[2]>=400){ count[2]=0; Data[2]++; Data[2]&=0x0F; Show5DigitLed(3, Data[2]); } if(count[3]>=300){ count[3]=0; Data[3]++; Data[3]&=0x0F; Show5DigitLed(4, Data[3]); } if(count[4]>=200){ count[4]=0; Data[4]++; Data[4]&=0x0F; Show5DigitLed(5, Data[4]); } } void main(void) { int quit=0; InitLib(); /* InitLib() must be called before other functions in the library may be used */ Print("Each digit of the LED counts at a different speed\r\n"); Print("\r\nPress 'q' to quit\r\n"); Init5DigitLed(); TimerOpen(); InstallUserTimer(MyTimerFun); while(!quit) { if(Kbhit() && Getch()=='q') quit=1; } TimerClose(); }