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

📄 main.c

📁 用来测试mcf5249的嵌入式测试程序
💻 C
字号:
/********************************************************************/
/*
 * File:		main.c
 * Purpose:		Function prototypes and memory map information.
 *
 * Notes:
 *
 * Author:		Li KunHua
 * Date:        2003-03-31 
 *
 * Modifications:
 *
 */
/********************************************************************/

#include "base.h"


/********************************************************************/
extern void main(void);

void main(void)
{   
    /* Setup SR to 0x2700 */
    asm(move.w  #0x2000,SR);

    /* Setup SP to A7 */
    asm(lea     _SP_INIT,a7);

	/* Point VBR to VECTOR_TABLE[] */
	asm(move.l  #VECTOR_TABLE,d0);
	asm(movec   d0,VBR);

	/* Point MBAR to IMM_ADDRESS */
    asm(move.l  #IMM_ADDRESS,d0);
	asm(addq.l	#1,d0);
	asm(movec	d0,MBAR);
	/* Point MBAR2 to IMM2_ADDRESS */
    asm(move.l  #IMM2_ADDRESS,d0);
	asm(addq.l	#1,d0);
	asm(movec	d0,MBAR2);

	/* Point RAMBAR to INT_SRAM_ADDRESS */
    asm(move.l  #INT_SRAM0_ADDRESS,d0);	    // locate SRAM0, validate it!INT_SRAM_SIZE
	asm(add.l	#0x00000021,d0);
	asm(movec	d0,RAMBAR0);
    asm(move.l  #INT_SRAM1_ADDRESS,d0);	    // locate SRAM1, validate it!INT_SRAM_SIZE
	asm(add.l	#0x00000021,d0);
	asm(movec	d0,RAMBAR1);

	imm = (MCF5249_IMM *)(IMM_ADDRESS);
	imm2 = (MCF5249_IMM2 *)(IMM2_ADDRESS);

   	plldelay();
	/* Init PLL */
	imm2->pll.PLLCR &= ~MCF5249_PLL_PLLCR_PLLBP;
	asm(nop);
	imm2->pll.PLLCR = MCF5249_PLL_VAL;		// PLLCR -- PLL control register
                                    	    // CPU clock = 39.984MHz
                                    	    // AUDIOCLK = Fxtal/2 = 5.6448MHz
                                    	    // MCLK1 = Fxtal/2 = 5.6448MHz
                                    	    // MCLK2 = Fxtal/2 = 5.6448MHz
   	plldelay();
    while(!((imm2->pll.PLLCR & MCF5249_PLL_PLLCR_LOCK)==MCF5249_PLL_PLLCR_LOCK));
   	plldelay();

    /* Invalidate the cache and disable it */
    //mcf5249_wr_cacr(MCF5249_CACR_CINVA);

    /*
     * Setup ACRs so that if cache is turned on, only SDRAM 
	 * and Flash are cached
     */
    mcf5249_wr_acr0( 0
        | MCF5249_ACR_BASE(SDRAM_ADDRESS)
        | MCF5249_ACR_MASK(0x00000000)
        | MCF5249_ACR_E
		| MCF5249_ACR_CM_00
        | MCF5249_ACR_S_IGNORE
		);
    mcf5249_wr_acr1( 0
        | MCF5249_ACR_BASE(FLASH_ADDRESS)
        | MCF5249_ACR_MASK(0x00000000)
        | MCF5249_ACR_E
		| MCF5249_ACR_CM_00
        | MCF5249_ACR_S_IGNORE
		);//*/

	/*************************************************************************/
	/*************************************************************************/
	/*************************** Main Program Start **************************/
	/*************************************************************************/
	/*************************************************************************/
	mcf5249_init();
   
    Keyflags = 0;
    Keyloop = 0;

    //Testflags = mcf5249_sdram_test();
    //Testflags = mcf5249_flash_test();
    LCD_Init();
	//DM9000_init();
	//DM9000_test();
    
	while(1)
	{
		/* Get Key */
		imm2->adc.ADCONFIG = 0x0404;
		delay1ms();
		if(imm2->adc.ADVALUE<0x0a30)
		{
			delay10ms();
			Keyloop = imm2->adc.ADVALUE;
			if(Keyloop<0x0300) Keyflags = 0x01;
			if((Keyloop<0x0610)&&(Keyloop>0x0300)) Keyflags = 0x02;
			if((Keyloop<0x0890)&&(Keyloop>0x0610)) Keyflags = 0x03;
			if((Keyloop<0x0a30)&&(Keyloop>0x0890)) Keyflags = 0x04;
		}
		else
		{
			imm2->adc.ADCONFIG = 0x0504;
			delay1ms();
			if(imm2->adc.ADVALUE<0x0a30)
			{
				delay10ms();
				Keyloop = imm2->adc.ADVALUE;
				if(Keyloop<0x0300) Keyflags = 0x11;
				if((Keyloop<0x0610)&&(Keyloop>0x0300)) Keyflags = 0x12;
				if((Keyloop<0x0890)&&(Keyloop>0x0610)) Keyflags = 0x13;
				if((Keyloop<0x0a30)&&(Keyloop>0x0890)) Keyflags = 0x14;
			}
		}

		if(Keyflags!=0)
		{
			switch(Keyflags)
			{
				case 0x01:
					LCD_DisplayText("<PLAY/PAUSE>键");
					imm2->gpio.GOR &= ~MCF5249_GPIO15;  //LED1
					imm2->gpio.GOR |= MCF5249_GPIO23;   //LED2
					imm2->gpio.G1OR &= ~MCF5249_GPIO50; //LED3
					imm2->gpio.G1OR |= MCF5249_GPIO46;  //LED4
					imm2->gpio.G1OR &= ~MCF5249_GPIO55; //LED5
					imm2->gpio.GOR |= MCF5249_GPIO3;    //LED6
					break; 
				case 0x02:
					LCD_DisplayText("<K_STOP>键");
					imm2->gpio.GOR |= MCF5249_GPIO15;   //LED1
					imm2->gpio.GOR &= ~MCF5249_GPIO23;  //LED2
					imm2->gpio.G1OR |= MCF5249_GPIO50;  //LED3
					imm2->gpio.G1OR &= ~MCF5249_GPIO46; //LED4
					imm2->gpio.G1OR |= MCF5249_GPIO55;  //LED5
					imm2->gpio.GOR &= ~MCF5249_GPIO3;   //LED6
					break; 
				case 0x03:
					LCD_DisplayText("<K_FF>键");
					imm2->gpio.GOR |= MCF5249_GPIO15;   //LED1
					imm2->gpio.GOR |= MCF5249_GPIO23;   //LED2
					imm2->gpio.G1OR &= ~MCF5249_GPIO50; //LED3
					imm2->gpio.G1OR &= ~MCF5249_GPIO46; //LED4
					imm2->gpio.G1OR |= MCF5249_GPIO55;  //LED5
					imm2->gpio.GOR |= MCF5249_GPIO3;    //LED6
					break; 
				case 0x04:
					LCD_DisplayText("<K_REW>键");
					imm2->gpio.GOR &= ~MCF5249_GPIO15;  //LED1
					imm2->gpio.GOR &= ~MCF5249_GPIO23;  //LED2
					imm2->gpio.G1OR |= MCF5249_GPIO50;  //LED3
					imm2->gpio.G1OR |= MCF5249_GPIO46;  //LED4
					imm2->gpio.G1OR &= ~MCF5249_GPIO55; //LED5
					imm2->gpio.GOR &= ~MCF5249_GPIO3;   //LED6
					break; 
				case 0x11:
					LCD_DisplayText("<DISPLAY>键");
					imm2->gpio.GOR &= ~MCF5249_GPIO15;  //LED1
					imm2->gpio.GOR &= ~MCF5249_GPIO23;  //LED2
					imm2->gpio.G1OR &= ~MCF5249_GPIO50; //LED3
					imm2->gpio.G1OR &= ~MCF5249_GPIO46; //LED4
					imm2->gpio.G1OR &= ~MCF5249_GPIO55; //LED5
					imm2->gpio.GOR &= ~MCF5249_GPIO3;   //LED6
					break; 
				case 0x12:
					LCD_DisplayText("<MENU_SELECT>键");
					imm2->gpio.GOR &= ~MCF5249_GPIO15;  //LED1
					imm2->gpio.GOR &= ~MCF5249_GPIO23;  //LED2
					imm2->gpio.G1OR |= MCF5249_GPIO50;  //LED3
					imm2->gpio.G1OR &= ~MCF5249_GPIO46; //LED4
					imm2->gpio.G1OR &= ~MCF5249_GPIO55; //LED5
					imm2->gpio.GOR &= ~MCF5249_GPIO3;   //LED6
					break; 
				case 0x13:
					LCD_DisplayText("<VOL+/MENU+>键");
					imm2->gpio.GOR &= ~MCF5249_GPIO15;  //LED1
					imm2->gpio.GOR |= MCF5249_GPIO23;   //LED2
					imm2->gpio.G1OR |= MCF5249_GPIO50;  //LED3
					imm2->gpio.G1OR |= MCF5249_GPIO46;  //LED4
					imm2->gpio.G1OR &= ~MCF5249_GPIO55; //LED5
					imm2->gpio.GOR &= ~MCF5249_GPIO3;   //LED6
					break; 
				case 0x14:
					LCD_DisplayText("<VOL-/MENU->键");
					imm2->gpio.GOR |= MCF5249_GPIO15;   //LED1
					imm2->gpio.GOR &= ~MCF5249_GPIO23;  //LED2
					imm2->gpio.G1OR &= ~MCF5249_GPIO50; //LED3
					imm2->gpio.G1OR &= ~MCF5249_GPIO46; //LED4
					imm2->gpio.G1OR &= ~MCF5249_GPIO55; //LED5
					imm2->gpio.GOR |= MCF5249_GPIO3;    //LED6
					break;
			}
			
			if(Keyflags<0x11)
			{
				imm2->adc.ADCONFIG = 0x0404;
				delay1ms();
				while(imm2->adc.ADVALUE<0x0a30);
				delay10ms();
				while(imm2->adc.ADVALUE<0x0a30);
			}
			else
			{
				imm2->adc.ADCONFIG = 0x0504;
				delay1ms();
				while(imm2->adc.ADVALUE<0x0a30);
				delay10ms();
				while(imm2->adc.ADVALUE<0x0a30);
			}
			
			Keyflags = 0;
			Keyloop = 0;
		}
	} // Main Loop
}

⌨️ 快捷键说明

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