📄 wang_cnt0.c
字号:
/*********************************************************************
586_cnt0.c Test program for SC520 Timer0 6-20-2001
P13=Slave2 PIC IR0, interrupt vector=0x50, GP timer0
Timer 0 will count pulses on TMRIN0 (pin J4.4) until reach ta+tb, interrupt us,
and then roll over. LED will blink once per interrupt.
To check current count value, call t0_rd().
*********************************************************************/
#include <dos.h>
#include "586.h" /* 586E initialization */
#define MMCR 0xdf00
unsigned int t0,ta,tb,tm,ledd,t1;
unsigned int a,b,c,d,x,i;
unsigned char led1[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D, //0,1,2,3,4,5
//0 1 2 3 4 5
0x7D,0x07,0x7F,0x6F,0x77,0x7C, //6,7,8,9,A,B
//6 7 8 9 10 11
0x39,0x5E,0x79,0x71,0x73,0x3E, //C,D,E,F,P,U
// 12 13 14 15 16 17
0x76,0x38,0x40,0x6E,0x0FF,0x00, //H,L,-,Y, 全屏 ,'全暗'
//18 19 20 21 22 23
0x37,0x3F,0x6D,0x06,0x2F,0x6F, //N,O,S,I,error,G,
//24 25 26 27 28 29
0x0E,0x67,0x50,0x31}; //J,Q,R,T
//30 31 32 33
void interrupt far t0_isr (void);
void main(void)
{
sc_init();
/* counting exteranl events on TMRIN0 (pin J4.4) */
//初始化pio
pio_init(0, 2); // PIO 0=LED as output
for(i=2;i<27;i++){
pio_init(i, 2); // PIO 2-26 as output
}
pio_init(28, 2); // PIO 28 as output
pio_init(29, 2); // PIO 29 as output
pio_init(30, 2); // PIO 30 as output
//初始化cmpmaxa,cmpmaxb
ta=(unsigned int)1000; //0xffff
tb=(unsigned int)1000;
// tm = 0xe005; // start count, interrupt enabled, external clock, continuous mode.
// See chapter 17 of AMD_DOCS\sc520\sc520_user_manual.pdf from
// root directory of CD-ROM (EV-P Kit/DV-P Kit) for info on
// TIMER0 control register
tm = 0xe005; // same as above, just without interrupt ;noncontinuous
t0_init(tm,ta,tb,t0_isr);
t0=0;
ledd=0;
while(1)
{
t1=t0_rd(); // read current value of counter
// use watch window to see ta increment as
// provide low signal on pin J4.4
a=t1/1000;
ta=t1%1000;
b=t1/100;
ta=t1%100;
c=t1/10;
d=t1%10;
//display
x=led1[a]|0xfe00;
x=x<<2;
poke(MMCR, _PIODATA15_0_,x); //can not use outport command
delay_ms(10);
x=led1[b]|0xfd00;
x=x<<2;
poke(MMCR, _PIODATA15_0_,x);
delay_ms(10);
x=led1[c]|0xfb00;
x=x<<2;
poke(MMCR, _PIODATA15_0_,x);
delay_ms(10);
x=led1[d]|0xf700;
x=x<<2;
poke(MMCR, _PIODATA15_0_,x);
delay_ms(10);
} // end of while(1)
} // end of main
/*
// Function: t0_isr
//
// Timer0 Interrupt handler. Increment t0
// P13=Slave2 PIC IR0, interrupt vector=0x50, GP timer0
*/
void interrupt far t0_isr (void)
{
t0++;
pokeb(MMCR,_GPTMRSTA_,0x01|peekb(MMCR,_GPTMRSTA_)); // Clear T0 status
// Issue the EOI to interrupt controller
outportb(_S2PICOCW2_IO,0x60); // Specific EOI for slave 2 IR0
outportb(_MPICOCW2_IO,0x65); // Specific EQI for master IR5
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -