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

📄 main.c

📁 it is a sample code for s3c2410 board.
💻 C
字号:
// --------------------------------------------------------------------
//
//   Title     :  MAIN
//             :
//   Library   :
//             :
//   Developers:  MICROTIME MDS group
//             :
//   Purpose   :  Main Program for Creator Board
//             :
//   Limitation:
//             :
//   Note      :
//             :
// --------------------------------------------------------------------
//   modification history :
// --------------------------------------------------------------------
//   Version| mod. date: |
//   V1.0   | 03/31/2003 | First release
// --------------------------------------------------------------------
//
// Note:
//
//       MICROTIME COMPUTER INC.
//
//


/*************************************************************************
Include files
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <inarm.h>
#include "driver.h"


/*************************************************************************
Function prototypes
*************************************************************************/
void 	WaitChar(void);
void    print_date(void);
UC 	Edit_RTC(void);


/*************************************************************************
Variables
*************************************************************************/
UC num;
UI  i;
UC buf[14];
UC key=0xff;
UC yy, mm, ww, dd, hh, ii, ss;
UC *week[7]={"Sun.","Mon.","Tues.","Wed.","Thu.","Fri.","Sat."};	

/*************************************************************************
System Initialize
*************************************************************************/
void Initial_Creator(void)
{
	
		//S3C4510 Peripherals Initialization
		Initial_TIMER0();		//Generate 1ms interrupt
		IOPMOD = 0x00030000;	//for testing purposes
		IOPCON = 0x40000000;	//for testing purposes

		//Initial IO_REG0
		io_reg0 = 0xc000;
		IO_REG0 = io_reg0;
        Delay(1);

        //Initial CPLD_CTRL
        cpld_ctrl = 0x3C;
        CPLD_CTRL = cpld_ctrl;
        Delay(500);
        cpld_ctrl |= 0x01;    //Release IO reset
        CPLD_CTRL = cpld_ctrl;

        Delay(500);
        
        Initial_LCD();
        LCD_EnableCursor(TRUE);
        Initial_7SEG();
        Initial_KEYPAD();
}



/*************************************************************************
MAIN Program 
*************************************************************************/
int main(void)
{
        __enable_interrupt();
	Initial_Creator();
	EnableInterrupt(BIT_GMASK);
        RTC_get_time(&ss, &ii, &hh, &dd, &ww, &mm, &yy);
        print_date();
        while (1)
        {
          while (KEYPAD_get_key(&key)!=OK)
          {
           RTC_get_time(&ss, &ii, &hh, &dd, &ww, &mm, &yy);
           _7SEG_put_led(3,ss%16);
           _7SEG_put_led(2,ss/16);
           _7SEG_put_led(1,ii%16);
           _7SEG_put_led(0,ii/16);
           if (ii==0) print_date();
          }
          LCD_ClearScreen();
          Edit_RTC();
          LCD_printf("\nAny Key To Ret:");
          WaitChar();
          print_date();
        }
        DisableInterrupt(BIT_GMASK);
        return(0);
}


/*************************************************************************
Wait key 
*************************************************************************/
void WaitChar(void)
{
		UC key;
		while(KEYPAD_get_key(&key) != OK);
}


/*************************************************************************
Get Key 
*************************************************************************/
UC GetIntNumRange (UC MinNum, UC MaxNum)
{
		UC ch;
		KEYPAD_get_key(&ch);
		if(ch >= MinNum && ch <= MaxNum) return(ch);
		return (0xff);
}


/*************************************************************************
Edit RTC 
*************************************************************************/
void print_date(void)
{
          LCD_ClearScreen();
          LCD_printf("Test Prog V1.0\n\n\n\n\n\n");
          LCD_printf("20%2.2x/%2.2x/%2.2x %s\n\n  %2x o'clock",yy,mm,dd,week[ww],hh);
          LCD_printf("\n\n\n\n\nAny key to edit\n");
}


/*************************************************************************
Edit RTC 
*************************************************************************/
UC Edit_RTC(void)
{
		while(1) 
		{
			RTC_get_time(&ss, &ii, &hh, &dd, &ww, &mm, &yy);
			do {
				LCD_ClearScreen();
				LCD_printf("(YY)Years  = %2x\n", yy);
				LCD_printf("(MM)Months = %2x\n", mm);
				LCD_printf("(WW)WeekDay= %2x\n", ww);
				LCD_printf("(DD)Date   = %2x\n", dd);
				LCD_printf("(HH)Hours  = %2x\n", hh);
				LCD_printf("(mm)Minutes= %2x\n", ii);
				LCD_printf("(SS)Seconds= %2x\n", ss);
				LCD_printf("\nTo Abort :\n");
				LCD_printf("Press Key 'A'\n");
				LCD_printf("\nEnter New Date:\n");
				LCD_printf("YYMMWWDDHHmmSS#\n");
	
				for(i=0; i<14; i++)
				{
					while((num=GetIntNumRange (0, 10)) == 0xff);
					if(num == 10)
					{
						LCD_printf("\nUser Abort.\n");
						return(OK);
					}
					LCD_printf("%x", num);
					buf[i] = num;
				}
				while(KEYPAD_get_key(&key) != OK);
			}while(key != KEY_P) ;
			RTC_set_time(	buf[13]|(buf[12]<<4),	//SS
							buf[11]|(buf[10]<<4),	//mm
							buf[9]|(buf[8]<<4),		//HH
							buf[7]|(buf[6]<<4),		//DD
							buf[5]|(buf[4]<<4),		//WW
							buf[3]|(buf[2]<<4),		//MM
							buf[1]|(buf[0]<<4));	//YY
		}
		return (0);
}

⌨️ 快捷键说明

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