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

📄 ledtest.c

📁 44b0x 的中断程序源码实例
💻 C
字号:
/****************************************************************************
【文  件  名  称】main.c
【功  能  描  述】三星S3C44B0X板demo程序代码
【程  序  版  本】4.0
【创建人及创建日期】龚俊//2002年11月19日19:26
【修改人及修改日期】龚俊//2004-12-8 17:25
****************************************************************************/

//***************************************************************************
#include "def.h"
#include "44b.h"
#include "44blib.h"

/************************* PORTS ****************************/

void __irq Eint4567Isr(void);
volatile char which_int=0;//标识发生了那个中断,4,5,6 or 7?

void Port_Init(void)
{
	// PORT A GROUP
	/*  BIT 9	8	7	6	5	4	3	2	1	0	*/
	/*  A24	  A23	A22	A21	A20	A19	A18	A17	A16	A0	*/	      
	/*  1		1	1	1	1	1	1	1	1	1	*/
	rPCONA = 0x3ff;	

	// PORT B GROUP
	/* BIT 10   9    8       7      6        5     4     3     2     1     0    */
	/*     /CS5 /CS4 /CS3    /CS2   /CS1     nWBE3 nWBE2 /SRAS /SCAS SCLS  SCKE	*/
	/*     NC   NC   RTL8019 USBD12 NV_Flash NC    NC    Sdram Sdram Sdram Sdram*/
	/*     1,   1,   1,      1,     1,       0,    0,    1,    1,    1,    1    */
	rPDATB = 0x7cf;
    
	//PORT C GROUP
	//BUSWIDTH=16													*/
	/*  PC15		14		13		12		11		10		9		8	*/
	/*	o		o		RXD1	TXD1	o		o		o		o	*/
	/*	NC		NC		Uart1	Uart1	NC		NC		NC		NC	*/
	/*   01		01		11		11		01		01		01		00	*/

	/*  PC7		6		5		4		3		2		1		0	*/
	/*   o		o		o		o		o		o		o		o	*/
	/*   NC		NC		NC		NC		NFALE 	NFCLE 	NFCE 	NFRB*/
	/*   01		01		01		01		01		01		01		00	*/
	
	
	rPCONC = 0x5f55ff55;   //除串口1外其它均为输出口
	rPUPC  = 0x3000000;	   //disable  PC12 PC13 pull-up other pull up
	rPDATC = 0x3fff;	   //All IO is high, PC8 = 1 LCD-Off, PC9 = 0 BackLight Of	
	
	//PORT D GROUP
	/*  PORT D GROUP(I/O OR LCD)										*/
	/*  BIT7		6		5		4		3		2		1		0	*/
	/*      VF		VM		VLINE	VCLK	VD3		VD2		VD1		VD0	*/
	/*	   10		10		10		10		10		10		10		10	*/
	
	rPCOND= 0xaaaa;	      //所有口均为功能2  LCD driver 
	rPDATC= 0xff;         // all high 
	rPUPD = 0x00;         //所有上拉电阻使能
	
	//These pins must be set only after CPU's internal LCD controller is enable
	
	//PORT E GROUP 
	/*  Bit 8		7		6		5		4		3		2		1		0		*/
	/*		ENDLAN	LED3	LED2	LED1	LED0	BEEP	RXD0	TXD0	CLKOUT	*/ 
	/*      00		01		01		01		01		01		10		10		11		*/
    rPDATE  = 0x3B7;
	rPCONE	= 0x556b;        // 0:CLKOUT 1:TXD0 2:RXD0 3:O 4:0 5:0  6:0 7:0
    rPUPE   = 0x0e;          // 3 4 5 6 7 I/0  enable  
    	
	//PORT F GROUP
	/*  Bit8		7		6		5		 4		3		2		1		0		*/   
	/*  IISCLK	IISDI	IISDO	IISLRCK	Input	Input	Input	IICSDA	IICSCL	*/
	/*	100		100		100		100		00		01		01		10		10		*/
	
	rPCONF = 0x24900a;	//0 1->IICSCL IICSDA, 2~4->input 5~8->IIS PORT
	rPUPF  = 0x000;		//enable all pull-up

	//PORT G GROUP
	/*  BIT7		6		5		4		3		2		1		0	 */
	/*	INT7		INT6		INT5		INT4		INT3		INT2		INT1		INT0	*/
	/*    S3		S4		S5		S6		NIC		EXT		IDE		USB	*/
	/*      11      11      11      11      11      11      11      11       */
	
	rPCONG = 0xffff;    //ENT7-ENT0 功能3
	rPUPG  = 0x00;		//disable all pull-up
	
//	rSPUCR = 0x7;       //D15-D0 pull-up disable
	rSPUCR = 0x4;       //D15-D0 pull-up enable

	rEXTINT = 0x0;	    //所有的外部硬件中断为低电平触发, extint0 为下降沿,extint1为上升沿	
//	rEXTINT = (4<<16)|(4<<8)|(4<<4);	//EINT1上升沿,EINT2上升沿,EINT4上升沿中断
//	rINTCON = 5;				// non vector mode, irq enable
//	rINTMOD = 0;				//all are irq mode
	
	//Define the Non_Cache area
	
	//rNCACHBE0=( ( (Non_Cache_End)>>12) <<16)|((Non_Cache_Start)>>12); 
	  
	rNCACHBE0 = Non_Cache_End;    //modify by lixiao
	rNCACHBE1 = Non_Cache_Start;   
}


/**********************外部中断4-7中断处理*************/

void __irq Eint4567Isr(void)
{
    which_int=rEXTINTPND;
   /*
   If EINT4 产生时, EXTINTPND[0] =1 (0001)1
   If EINT5 产生时, EXTINTPND[1] =1 (0010)2
   If EINT6 产生时, EXTINTPND[2] =1 (0100)4
   If EINT7 产生时, EXTINTPND[3] =1 (1000)8
   所以上面语句执行的结果是:
   If EINT4 产生时 which_int=1
   If EINT4 产生时 which_int=2
   If EINT4 产生时 which_int=4
   If EINT4 产生时 which_int=8
   */
   
   rEXTINTPND=0xf;
   
   /* clear EXTINTPND reg
   The interrupt service routine must clear the interrupt
   pending condition(INTPND) after clearing the
   external pending condition(EXTINTPND).
   */
   
   rI_ISPC=BIT_EINT4567;
   
   /* clear pending_bit */
}


/************************* SYSTEM *************************/

void Delay(int time)
{
    int i;
	int delayLoopCount=400;
    for(;time>0;time--)
	for(i=0;i<delayLoopCount;i++);
}


/****************************************************************************
【功能说明】系统主函数
****************************************************************************/
void Main(void)
{
   // unsigned int save_G,save_PG;
    rINTMSK=BIT_GLOBAL;  
    //  rNCACHBE0 = Non_Cache_End; 
	//rNCACHBE1 = Non_Cache_Start;
	//rNCACHBE0 = ((Non_Cache_End>>12)<<16)|(Non_Cache_Start>>12);
    //在上面的数据区域不使用高速缓存

    rSYSCFG = CACHECFG;    //8K字节cache,写缓冲使能,data abort使能
    Port_Init();		//IO口初始化    
    
    rINTMOD=0x0;
    rINTCON=0x1;
    /*中断初始化
    rINTMOD=0x0 设置为 IRQ mode
    rINTCON=0x1 设置为向量中断模式
    */
    pISR_EINT4567=(int)Eint4567Isr;
    /*
     中断服务程序入口地址定位
     ;pISR_EINT4567
     ;0xc7fff74: Eint4567Isr
     把Eint4567Isr 代码存放在地址为0xc7fff74 开始的内存空间里
     */
    // save_G=rPCONG;
   //  save_PG=rPUPG;
     /*保存原来I/O 端口的配置 */
    rPCONG=0xffff; //EINT7~0
    rPUPG=0x0; //pull up enable
     /*
    rPCONG=0xffff 把PortG 配置为8 个中断输入
    rPUPG=0x0 中断为上升沿触发
    */
    rINTMSK=~(BIT_GLOBAL|BIT_EINT4567); 
    /*开放屏蔽位*/
   while(1)
   {
    
     while(!which_int);
     switch(which_int)
      {
         case 1:         
                rPDATE = 0xfEf;
               	break;
         case 2:
         		rPDATE = 0xfDf;
         		break;
      	 case 4:
         		rPDATE = 0xfBf;
         	    break;
      	 case 8:
         		rPDATE = 0xf7f;
         		break;
      	 default:
        		 break;
         
       } 
     which_int=0;
    
  }  
  

}

⌨️ 快捷键说明

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