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

📄 xtest10_5k.c

📁 AT91sam7s 256 B/D example
💻 C
字号:
/* ========================================================================== */
/*     Xtest10_5.c : GLCD Digital Clock with Time Adjust by RTT Interrupt     */
/* ========================================================================== */
/*			  Designed and programmed by Duck-Yong Yoon in 2007.  */

#include "AT91SAM7S256.h"
#include "lib_AT91SAM7S256.h"
#include "OK7S256ads.h"
#include "OK7S256Korean.h"

volatile unsigned int RTT_flag=0;		// RTT interrupt flag
volatile unsigned int cursor, second, minute, hour, ampm; // time variable

void GLCD_2d(unsigned int number)		/* display 2-digit decimal number */
{
  GLCD_English(0,number/10 + '0');		// 10^1
  GLCD_English(0,number%10 + '0');		// 10^0
}

void Cursor_left(void)			        /* go cursor left */
{
  if(cursor != 3) cursor -= 3;
  else            cursor = 15;
  ycursor = cursor;				// set cursor position
  GLCD_xy(2,cursor);
}

void Increment(void)	               		/* increment time */
{
  switch(cursor)
    { case  3 : if(hour != 12) hour++;		// in case of hour
                else           hour = 1;
                GLCD_xy(2,2); GLCD_2d(hour);
                GLCD_xy(2,cursor);
                break;
      case  6 : if(minute != 59) minute++;	// in case of minute
                else             minute = 0;
                GLCD_xy(2,5); GLCD_2d(minute);
                GLCD_xy(2,cursor);
                break;
      case  9 : if(second != 59) second++;	// in case of second
                else             second = 0;
                GLCD_xy(2,8); GLCD_2d(second);
                GLCD_xy(2,cursor);
                break;
      case 12 : if(ampm == 'A') ampm = 'P';	// in case of AM/PM
                else            ampm = 'A';
                GLCD_xy(2,11); GLCD_English(0,ampm);
                GLCD_xy(2,cursor);
                break;
      default : break;
    }
}

void RTT_ISR(void)				/* RTT interrupt service routine */
{
  AT91F_RTTGetStatus(AT91C_BASE_RTTC);		// clear RTTINC

  RTT_flag ^= 0x01;				// toggle RTT_flag(2Hz/2 = 1Hz)

  if(RTT_flag == 0)				// blink semicolon
    { GLCD_xy(2,4); GLCD_English(0,':');
      GLCD_xy(2,7); GLCD_English(0,':');
    }
  else
    { GLCD_xy(2,4); GLCD_English(0,' ');
      GLCD_xy(2,7); GLCD_English(0,' ');
    }
  GLCD_xy(2,cursor);				// go cursor position

  if(RTT_flag == 0) second++;			// display time 2 times per second

  if(second == 60)                              // if second = 60, second = 0
    { second = 0;
      minute++;                                 // increment minute
      if(minute == 60)                          // if minute = 60, minute = 0
        { minute = 0;
          hour++;                               // increment hour
          if(hour == 13)                        // if hour = 13, hour = 1
            hour = 1;
          if(hour == 12)                        // if hour = 12, adjust AM/PM
            { if(ampm == 'A') ampm = 'P';
              else            ampm = 'A';
            }
        }
     }

  GLCD_xy(2,2);	GLCD_2d(hour);			// display hour
  GLCD_xy(2,5);	GLCD_2d(minute);		// display minute
  GLCD_xy(2,8);	GLCD_2d(second);		// display second
  GLCD_xy(2,11); GLCD_English(0,ampm);		// display AM/PM
  GLCD_English(0,'M');
  GLCD_xy(2,15); GLCD_English(0,' ');		// clear cursor at x=2, y=15
  GLCD_xy(2,cursor);				// go cursor position
}

int main(void)
{
  MCU_initialize();				// initialize AT91SAM7S256 & kit
  Delay_ms(50);					// wait for system stabilization
  LCD_initialize();				// initialize text LCD module
  GLCD_clear();		               		// initialize GLCD screen

  cursor = 15;					// initial cursor position
  xcursor = 2;
  ycursor = cursor;
  cursor_flag = 1;				// cursor ON

  hour = 12;					// initial time
  minute = 0;
  second = 0;
  ampm = 'A';

  LCD_string(0x80," Digital Clock  ");		// display title on text LCD
  LCD_string(0xC0,"    on GLCD     ");

  GLCD_string(0,0,0,"****************");	// display title on graphic LCD
  GLCD_string(1,0,0,"  棥弧乳 

⌨️ 快捷键说明

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