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

📄 graphicanimation.c

📁 The GraphicAnimation project is a program for the AT91RM9200 using Atmel AT91RM9200-EK Evaluation B
💻 C
字号:
/******************************************************************************/
/* GraphicAnimation.C: Graphic animation on VGA monitor                       */
/******************************************************************************/
/* This file is part of the uVision/ARM development tools.                    */
/* Copyright (c) 2005-2006 Keil Software. All rights reserved.                */
/* This software may only be used under the terms of a valid, current,        */
/* end user licence from KEIL for a compatible version of KEIL software       */
/* development tools. Nothing else gives you the right to use this software.  */
/******************************************************************************/

#include <stdio.h>
#include "ics1523.h"
#include "s1d13806.h"
#include <AT91RM9200.h>
#include <lib_AT91RM9200.h>

/* Master Clock                                                               */
#define MCK_KHz  60000	

/* Video Graphic Controller addresses                                         */
#define S1D13806_BASE           ((unsigned char *) 0x40000000 )
#define S1D13806_DISP_MEM_BASE  (((int) S1D13806_BASE) + ((int) 0x200000) )

/* Resolution of the display (screen)                                         */
#define RES_W    640
#define RES_H    480

/* Image Size                                                                 */
#define IMAGE_W  200
#define IMAGE_H  150

/* Start of data in background image where the animation is displayed         */
#define BACK_START ((((RES_H-IMAGE_H)>>1)-1)*RES_W+(((RES_W-IMAGE_W)>>1))-1)<<1

/*----------------------------------------------------------------------------
 * Externals
 *----------------------------------------------------------------------------*/

/* Interrupt handlers                                                         */
extern void AT91F_ST_ASM_HANDLER(void);

/* Function from init.c                                                       */
extern void AT91F_DBGU_Printk(char *buffer);

/*----------------------------------------------------------------------------
 * Global variables
 *----------------------------------------------------------------------------*/

/* Image data buffer declaration                                              */
extern unsigned char animation[] ;

/* Background picture data buffer declaration                                 */
extern unsigned char screen[] ;

/* Animation address look_up table                                            */
int address_tbl[] = {   0                  ,  2*(IMAGE_W*IMAGE_H),  4*(IMAGE_W*IMAGE_H),  6*(IMAGE_W*IMAGE_H), 
                        8*(IMAGE_W*IMAGE_H), 10*(IMAGE_W*IMAGE_H), 12*(IMAGE_W*IMAGE_H), 14*(IMAGE_W*IMAGE_H), 
                       16*(IMAGE_W*IMAGE_H), 18*(IMAGE_W*IMAGE_H), 20*(IMAGE_W*IMAGE_H), 22*(IMAGE_W*IMAGE_H), 
                       24*(IMAGE_W*IMAGE_H), 26*(IMAGE_W*IMAGE_H), 28*(IMAGE_W*IMAGE_H), 30*(IMAGE_W*IMAGE_H), 
                       32*(IMAGE_W*IMAGE_H), 34*(IMAGE_W*IMAGE_H), 36*(IMAGE_W*IMAGE_H), 38*(IMAGE_W*IMAGE_H) };

/* Buffer for picture to draw                                                 */
unsigned short buf_ani[IMAGE_W*IMAGE_H];

/* System timer counter                                                       */
unsigned int StTick = 0;


/*----------------------------------------------------------------------------
 * AT91F_GetTickCount
 *
 * Description: This function returns the value of the system timer
 *----------------------------------------------------------------------------*/

unsigned int AT91F_GetTickCount(void)
{
  return(StTick);
}


/*----------------------------------------------------------------------------
 * AT91F_ST_HANDLER
 *
 * Description: This function is invoked by main
 *----------------------------------------------------------------------------*/

void AT91F_ST_HANDLER(void)
{
volatile int StStatus;
  /* Read the system timer status register                                    */
  StStatus = *(AT91C_ST_SR);
  StTick++;
}


/*----------------------------------------------------------------------------
 * AT91F_ST_SetPeriodIntervalTimer
 *
 * Description: Set Periodic Interval Interrupt (period min <=> 1/32768 s)
 *----------------------------------------------------------------------------*/

__inline void AT91F_ST_SetPeriodIntervalTimer(AT91PS_ST pSt, unsigned int period)
{
	volatile int status;
	pSt->ST_IDR = AT91C_ST_PITS;	/* Interrupt disable Register */

	status = pSt->ST_SR;
    pSt->ST_PIMR = period;			/* Period Interval Mode Register */
}


/*----------------------------------------------------------------------------
 * ClearDisplay
 *
 * Description: Clear the display
 *----------------------------------------------------------------------------*/

__inline void ClearDisplay (void)
{
  int           i = (RES_W*RES_H);
  short *disp_mem = (short *) S1D13806_DISP_MEM_BASE ;

  while (i--)
    *disp_mem++ = 0x0000;
}


/*----------------------------------------------------------------------------
 * DisplayPicture
 * 
 * Description: Display picture from requested address, at position pos_x and 
 *              pos_y, of width and height
 *----------------------------------------------------------------------------*/

__inline void DisplayPicture (unsigned short *address, int pos_x, int pos_y, int width, int height)
{
  int i;
  int j = RES_W + width;
  short *disp_ptr  = (short *) (S1D13806_DISP_MEM_BASE) + (RES_W*(pos_y+height-1)) + pos_x;

  while (height--)  {
    i = width;
    while (i--)
      *disp_ptr++ = *address++;
    disp_ptr -= j;
  }
}


/*----------------------------------------------------------------------------
 * PreparePicture
 * 
 * Description: Prepares picture for display, uses background instead of      
 *              color value 0x0000 (black)
 *----------------------------------------------------------------------------*/

__inline void PreparePicture (unsigned short *ptr_buf_ani, unsigned short *ptr_image, unsigned short *ptr_back, int image_w, int image_h)
{
  int   i, j;
  unsigned short data;

  j = RES_W - image_w;
  while (image_h--)  {
    i = image_w;
    while (i--)  {
      data = *ptr_image++;
      if (data == 0)  {
        *ptr_buf_ani++ = *ptr_back;
      }  else  {
        *ptr_buf_ani++ = data;
      }
      ptr_back++;
    }
    ptr_back += j;
  }
}


/*----------------------------------------------------------------------------
 * main
 *
 * Description: The program main function
 *----------------------------------------------------------------------------*/

int main()
{
  int   i = 0;
  int   delay;

  AT91PS_S1D13806_Desc s1d13806_base = (AT91PS_S1D13806_Desc) S1D13806_BASE;
	 
  AT91F_DBGU_Printk("\n\r");
  AT91F_DBGU_Printk("*********************************\n\r");
  AT91F_DBGU_Printk("* The Keil 'ARM' Animation DEMO *\n\r");
  AT91F_DBGU_Printk("*********************************\n\r");

  /* System Timer Initialization                                              */
  AT91F_ST_SetPeriodIntervalTimer(AT91C_BASE_ST, 0x3);         /* Period <=> 100us      */
  AT91F_ST_EnableIt(AT91C_BASE_ST, AT91C_ST_PITS);
	
  AT91F_AIC_ConfigureIt(AT91C_BASE_AIC,                        /* AIC base address      */
                        AT91C_ID_SYS,                          /* System peripheral ID  */
                        AT91C_AIC_PRIOR_HIGHEST,               /* Max priority          */
                        AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, /* Level sensitive       */
                        AT91F_ST_ASM_HANDLER );						

  /* Enable ST interrupt                                                      */
  AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_SYS);

  /* ICS1523 Clock Generator Initialization                                   */
  AT91F_ICS1523_Init((unsigned int) Clock_Conf, (unsigned int) MCK_KHz);
  AT91F_DBGU_Printk("Clock generator init OK\n\r");
    
  /* Epson S1D13806 Initialization for a CRT Monitor                          */
  AT91F_S1D13806_Init(  s1d13806_base,
					              S1D13806_DISP_MEM_BASE,
					              (unsigned int) CRT_Display_Conf,
					              (unsigned int) Display_Def_0,
					              (unsigned int) Char_Def_0, 
					              (unsigned int) MCK_KHz);
  AT91F_DBGU_Printk("S1D13806 Display Controller Init OK\n\r");

  /* Clear the display                                                        */
  ClearDisplay();
  AT91F_DBGU_Printk("Display Cleared\n\r");

  /* Display background picture                                               */
  DisplayPicture ((unsigned short*)screen, 0, 0, RES_W, RES_H);
  AT91F_DBGU_Printk("Display background\n\r");

  AT91F_DBGU_Printk("Animating 'ARM'\n\r");

while(1)  {
  /* Calculate pause (different for different pictures)                       */
  if (i>9) delay = 400000 + (19-i) * 50000;
  else     delay = 400000 + (   i) * 50000;

  /* Wait for calculated time                                                 */
  while (delay--);

  /* Prepare picture (animation) to be displayed                              */
  PreparePicture (                                          buf_ani, 
                  (unsigned short *) (&animation[address_tbl[i++]]), 
                           (unsigned short *) (&screen[BACK_START]), 
                                                            IMAGE_W, 
                                                            IMAGE_H);

  /* Display prepared picture                                                 */
  DisplayPicture (buf_ani, 219, 164, IMAGE_W, IMAGE_H);

  if (i == 20) i = 0;
  }
}

⌨️ 快捷键说明

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