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

📄 led.c

📁 F2407的10个C语言例程代码
💻 C
字号:
#include "2407c.h"                    

#define T1MS		0x9c3f          /* 9c3fH=40000-1 */

void interrupt gptime1(void);   	/* 中断服务程序,定时器计数T1MS次时中断调用 */
void gp_init(void);      	        /* 定时器初始化 */
void delay(int);                    /* 延时子程序 */

unsigned int uWork,nCount; 
int x=0; 


main()
{
	nCount=0;

	asm(" setc INTM");              /* 关中断,进行关键设置时不允许发生中断,以免干扰 */
    
    *WDCR=0x0E8;       
//	*WDCR=0x6f;
//	*WDKEY=0x5555;
//	*WDKEY=0xaaaa;		            /* 关闭看门狗中断 */

	*SCSR1=0x81fe;    	            /* 设置DSP运行频率40m */
	(*MCRB)=0;
	
	uWork=(*MCRC);     
	uWork&=0x0ffbf;	                /* 设置PF6脚为I/O口 */	
	(*MCRC)=uWork;

	
	gp_init();   		            /* 初始化定时器 */
	
	*IMR=0x2;		                /* 使能定时器中断(INT2) */
	*IFR=0x0ffff;                   /* 清除所有中断标志 */
	
	asm(" clrc INTM");              /* 开全局中断 */

	while ( 1 );		            /* 循环,等待中断发生 */
}               

/************************************
	中断服务程序:响应INT2中断
*************************************/
void interrupt gptime1(void)	    /* 中断服务程序定义,须使用interrupt声明 */
{  
   
   uWork=(*PIVR);		            /* 读外设中断向量寄存器 */
   switch(uWork)
   {  
   		case 0x27:		            /* T1PINT,0x27为定时器1的周期中断的向量值 */
   		{    
   		    x=x+1;
            if(x>128) x=0;
	        (*EVAIFRA)=0x80;        /*复位定时器1周期中断标志位*/
			
	     switch(x)
			 { 
	           case 0x1:
		       { asm(" ldp	 #0 ");
                 asm(" splk #1,60h ");
	             asm(" out 60h,100h ");
	             asm(" splk #1,60h ");
	             asm(" out 60h,100h ");
	             delay(500);
	             break;
	             }
	           case 0x2:
		       { asm(" ldp	 #0 ");
                 asm(" splk #2,60h ");
	             asm(" out 60h,100h ");
	             asm(" splk #2,60h ");
	             asm(" out 60h,100h ");
	             delay(500);
	             break;
	             } 
	           case 0x4:
			   { asm(" ldp	 #0 ");
                 asm(" splk #4,60h ");
	             asm(" out 60h,100h ");
	             asm(" splk #4,60h ");
	             asm(" out 60h,100h ");
	             delay(500); 
	             break;
	             }
               case 0x8:
			   { asm(" ldp	 #0 ");
                 asm(" splk #8,60h ");
	             asm(" out 60h,100h ");
	             asm(" splk #8,60h ");
	             asm(" out 60h,100h "); 
	             delay(500);
	             break;
	             }
			   case 0x10:
			   { asm(" ldp	 #0 ");
                 asm(" splk #16,60h ");
	             asm(" out 60h,100h ");
	             asm(" splk #16,60h ");
	             asm(" out 60h,100h ");
	             delay(500);
	             break;
	             }
		       case 0x20:
	           { asm(" ldp	 #0 ");
                 asm(" splk #32,60h ");
	             asm(" out 60h,100h ");
	             asm(" splk #32,60h ");
	             asm(" out 60h,100h ");
	             delay(500);
	             break;
	             }
			   case 0x40:
			   { asm(" ldp	 #0 ");
                 asm(" splk #64,60h ");
	             asm(" out 60h,100h ");
	             asm(" splk #64,60h ");
	             asm(" out 60h,100h ");
	             delay(500);
	             break;
	             }
			   case 0x80:
			   { asm(" ldp	 #0 ");
                 asm(" splk #128,60h");
	             asm(" out 60h,100h ");
	             asm(" splk #128,60h");
	             asm(" out 60h,100h ");
	             delay(500);
	             break;
	             }
              }
    }
   }  
   
}                       

void gp_init(void)
{
   *EVAIMRA = 0x80;		            /* 使能T1PINT即通用定时器1周期中断 */
   *EVAIFRA = 0x0ffff;	            /* 清除中断标志 */
   *GPTCONA = 0x0000;	
   *T1PR    = T1MS; 	            /* 周期寄存器=40000 */
   *T1CNT   = 0;	             	/* 计数初值=0 */
   *T1CON   = 0x1040;	            /* 设置连续增计数模式,启动计数器 */
}
    
void delay(int period)
{
    int i, j,;
    
    for(i=0; i<period; i++)
    {
        for(j=0; j<period>>1; j++);
        
    }
}



 

⌨️ 快捷键说明

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