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

📄 keyint1.c

📁 DSP240 用的程序 电机及基本的 希望有用的朋友
💻 C
字号:
#include "C240.h" 
/* define Input/Output variable value */
ioport unsigned int port0,port1,port2,port3,port4,port5; 
/*******************************************************************/
void disable_interrupts()
{
 asm(" SETC INTM");
}

/*********************************************/                  
void dsp_setup() 
{
 unsigned int temp;
 /*********************************************/
 /* Disable watchdog timer */
 /*********************************************/
 temp = WDCR;
 temp = temp|0x68;
 WDCR = temp;
 /*********************************************/
 /* initialize PLL module (20 MHz XTAL1) */
 /*********************************************/
 CKCR1 = 0x60;      	/* crystal=20MHz CPUCLK = 20MHz */
                    	/* and 1x PLL mult ratio */
 CKCR0 = 0x03;      	/* low–power mode 0, */
                    	/* ACLK enabled, */
                    	/* PLL enabled, */
                    	/* SYSCLK=CPUCLK/2 */
 SYSCR = 0x40c0; 
 XINT1CR=0x0006;
 OCRB=0x0fe;
 PCDATDIR=0x0701;
     
}
 
/*********************************************/                  
void keyboard_ISR() 
{
 int i; 
 unsigned int scan_in,scan_out,x2;
 int row,column=0,key_NO;   /* row=0,1,2;  column=1,2,3,4 */
 row=4;
 for(i=0;i<2500;i++);
 scan_in=port1;
 x2=scan_in & 0x0f;
 if (x2!=0x0f)
 {              
 switch(x2)
 	{
 	 case 0x0e: column=1; 
 	            break;
 	 case 0x0d: column=2;
 	 			break;
 	 case 0x0b: column=3;
 	 			break;
     case 0x07: column=4;
     			break;
     default  : column=17;
    }
 scan_out=0x0f7;
 port0=scan_out;            /* scan keyboard */
 /*for(i=0;i<2000;i++);  */
 scan_in=port1;
 while ((scan_in & 0x0f)==0x0f)
 	{
 	 scan_out=scan_out>>1;
 	 port0=scan_out; 
 	 /*for(i=0;i<2000;i++);*/ 
 	 scan_in=port1;
 	 row--;
 	 if (row==0)
 	 	{
 	 	 row=17;
 	 	 break;
 	 	}
 	}
 key_NO=4*(row-1)+column; 
 port0=0x00;
 x2=port1;
 while ((x2&0x0f)!=0x0f)
 	{
 	x2=port1;
 	port0=0x00;
 	}
 for(i=0;i<2500;i++);
 x2=port1;
 while ((x2&0x0f)!=0x0f)
 	{
 	x2=port1; 
 	port0=0x00;
 	} 
 /*port2=0x03;
 port3=0x00;  */
 switch(key_NO)
 	{  
     case 1  : port4=0x00;
               port5=0x01;
               break;
     case 2  : port4=0x00;
               port5=0x02;
               break;
     case 3  : port4=0x00;
               port5=0x03;
               break;
     case 4  : port4=0x00;
               port5=0x04;
               break;
     case 5  : port4=0x00;
               port5=0x05;
               break;
     case 6  : port4=0x00;
               port5=0x06;
               break;
     case 7  : port4=0x00;
               port5=0x07;
               break;
     case 8  : port4=0x00;
               port5=0x08;
               break;
     case 9  : port4=0x00;
               port5=0x09;
               break;
     case 10 : port4=0x01;
               port5=0x00;           
               break;
     case 11 : port4=0x01;
               port5=0x01;
     		   break;
     case 12 : port4=0x01;
               port5=0x02;
               break;                  
     case 13 : port4=0x01;
               port5=0x03;
               break;
     case 14 : port4=0x01;
               port5=0x04;
     		   break;
     case 15 : port4=0x01;
               port5=0x05;                
     		   break;
     case 16 : port4=0x01;
               port5=0x06;
               break;
 	 default : port4=0x09;
 	           port5=0x09;
 	           break;               
 	} 
 }
} 
  
/*************************************/
 
/* ***************************************************************** */
/* The main program  
/* ***************************************************************** */

main()
{
 unsigned int velocity;
 unsigned int x1;
 int i;
 disable_interrupts();
 dsp_setup();
 port2=0x03;
 port3=0x0;
 port4=0x0;
 port5=0x0;
 for(;;)
 {
 port2=0x0ff;
 if (PCDATDIR & 0x01)
 	PCDATDIR=0x0700;
 else
 	PCDATDIR=0x0701;
 port0=0x00;
 x1=XINT1CR;
 if (x1 & 0x8000)
 	{   
 	keyboard_ISR();
 	XINT1CR=0x0006;
 	} 
 }
 
} 



⌨️ 快捷键说明

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