⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wang_timer1.c

📁 美国tern公司开发的嵌入式开发平台586E
💻 C
字号:
/*
Courtesy of: nokamil@yahoo.com, submitted 3/6/2003.
All rights reserved, no warranties offered.

This program can be used to calculate the time of any event in 586 engine
Note that clock is 33.333Mhz/4 = 8.3325MHz therfore one clock pulse = inverse of it ie. .12Usec.
Therefore 49998pulses = 6msec. So interrupt will generate after every 6 msec.
*/


#include <dos.h>
#include <math.h>
#include <float.h>
#include	<string.h>
#include	"586.h"		 				// 586E initialization
#define MMCR 0xdf00
unsigned int t0,ta,tb,tmStart,tmStop,ledd,t1,t2,actualtime1,xiaoshu1;
unsigned int a,b,c,d,e,f,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
float actualtime = 0.0,xiaoshu=0.0;
void interrupt far t0_isr (void);

void main(void){
	sc_init();//586 initialization
   //初始化pio口
   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

   tmStart = 0xe001;	//	start count word
	tmStop = 0x8000;	//	stop count word

   //Start Timer
	ta=(unsigned int)49998;// equivalent to 6 msecAs one clock=1/8.3325 = .120012 microsec
	tb=(unsigned int)49998;
   t0=0;
	t0_init(tmStart,ta,tb,t0_isr);
   t1=t0_rd();

   //Here you can paste your code, here i insert delay() function
   delay_ms(500);

   //Stop the timer
   t2=t0_rd();
	t0_init(tmStop,ta,tb,t0_isr);
   actualtime =(t2-t1)*.00014 + t0*7; //原来0.00012,6

   while(1)
   {//dispose float data
   actualtime1=(int)actualtime;
   xiaoshu=actualtime-actualtime1;
   a=actualtime1/1000;
   actualtime1=actualtime1%1000;
   b=actualtime1/100;
   actualtime1=actualtime1%100;
   c=actualtime1/10;
   actualtime1=actualtime1%10;
   d=actualtime1%10;
   xiaoshu=xiaoshu*100.0;
   xiaoshu1=(int)xiaoshu; //
   e=xiaoshu1/10;
   f=xiaoshu1%10;
   // display//
   x=led1[a]|0xfe00; //千位
   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);  //can not use outport command
   delay_ms(3);
	x=led1[b]|0xfd00; //百位
   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);
   delay_ms(3);
   x=led1[c]|0xfb00; //十位
   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);
   delay_ms(3);
   x=led1[d]|0xf780; //个位,加上小数点
   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);
   delay_ms(3);
   x=led1[e]|0xef00; //十分位
   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);
   delay_ms(3);
   x=led1[f]|0xdf00; //百分位?   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);
   delay_ms(3);
   }
}


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 + -