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

📄 lj.cpp

📁 综合微机通用总线、定时计数器、并行接口、中断控制器等芯片等控制原理
💻 CPP
字号:
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef __cplusplus
  #define __CPPARGS ...
#else
  #define __CPPARGS
#endif
#define pt0 0x304
#define pt1 0x305
#define pt2 0x306
#define ct1 0x307
#define ct2 0x303
#define pta 0x300
#define ptb 0x301
#define ptc 0x302
#define o1m 0x21
#define o2m 0x20
#define o1f 0xa1
#define o2f 0xa0
#define COLOCK 1193180
#define MS 10/10000
#define INTR 0x72
short int Lj[14] = {131,147,165,175,196,220,247,252,294,330,349,392,440,494};
short int nLj0[] = {

    131,165,147,131,175,196,131,330,175,220,
    0
};
short int nTimeDelay0[] = {
    8,8,8,8,8,8,8,8,8,8,
};
short int nLj1[] = {

    220,294,196,220,
	294,252,
	220,252,220,196,
	175,196,
	220,220,294,
	220,196,175,165,
	147,196,
	147,
    0
};
short int nTimeDelay1[] = {
    8,8,8,8,
	16,8,
	8,4,8,8,
	16,8,
	16,8,8,
	8,8,8,8,
	16,8,
	16,
};
short int nLj2[] = {

    330,330,330,440,
	392,330,
	392,252,220,
	294,
	196,165,196,220,
	252,294,
	330,392,247,220,196,
	220,
    0
};
short int nTimeDelay2[] = {
    8,4,8,8,
	16,8,
	8,16,8,
	16,
	8,8,8,8,
	16,8,
	8,8,8,8,8,
	16,
};
short int nLj3[] = {

    440,392,330,294,
    252,294,
	330,294,252,220,
	196,
	196,196,220,
	252,294,330,294,252,
	294,
    0
};
short int nTimeDelay3[] = {
    8,4,8,8,
    16,8,
	8,4,8,8,
	16,
	16,8,8,
	8,4,8,8,
	8,4,4,4,8,
	16,
};
short int* ppLj[] = {nLj0,nLj1,nLj2};
short int* pptimedelay[] = {nTimeDelay0,nTimeDelay1,nTimeDelay2};
short int* ptimedelay;
short int* pLj;
void interrupt (*oldhandler)(__CPPARGS);
void interrupt liujing(__CPPARGS)
{
	 disable();
   (*ptimedelay)--;
	 outportb(o2f,0x62);
     outportb(o2m,0x20);
	 enable();
}

int main()
{
	int i=0;
	int Ljstatus;
	int Ljout;
	int Ljsellect;
   Ljsellect = inportb(pta);
  printf("%d\n",Ljsellect);
  //getch();
	if(Ljsellect > 3)
		return 0;
	oldhandler=getvect(INTR);
	setvect(INTR,liujing);
	Ljstatus = inportb(o1f);
	outportb(o1f,Ljstatus&0xfb);
	Ljstatus = inportb(o1m);
	outportb(o1m,Ljstatus&0xfb);
	outportb(ct2,0x90);
    outportb(ct2,0x0c);
    outportb(ct2,0x00);

    outportb(ct1,0xb6);
	outportb(ct1,0x36);
    
    
	ptimedelay = pptimedelay[Ljsellect-1];
	pLj = ppLj[Ljsellect-1];

	while(*pLj && !kbhit())
	{
	  outportb(pt2, (unsigned char)(COLOCK / *pLj % 256));
	  outportb(pt2, (unsigned char)(COLOCK / *pLj/ 256));

	   

	  outportb(pt0,(unsigned char)(100));
	  outportb(pt0,(unsigned char)(100));

      outportb(ct2, 0x01);
	  outportb(ct2, 0x0d);
outportb(ct2,0x0b);



	   while(*ptimedelay)
	   {
		   printf("%d\n",*pLj);
		   printf("%d\n",*ptimedelay);
        for(i=0;i<14;i++)
          {
             if(Lj[i] == *pLj)
               {
                   outportb(ptb,i);
                   break;
               }
          }

		   if(kbhit())
			   break;

	   }

	   outportb(ct2,0x0c);
	   outportb(ct2,0x00);


	   ptimedelay++;
	   pLj++;
	   
	}

	outportb(ct2,0x0c);
	outportb(ct2,0x00);
	setvect(INTR,oldhandler); 
	Ljstatus=inportb(0xa1);
	outportb(o1f,Ljstatus|0x04);
	Ljstatus=inportb(0x21);
	outportb(o1m,Ljstatus|0x04);
	return 0;
}

.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -