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

📄 rtc.c

📁 OMAP1030 处理器的ARM 侧硬件测试代码 OMAP1030 是TI的双核处理器
💻 C
字号:
//===================================
// FILE NAME: RTC.c
// AUTHOR:    Li Junjie
//===================================

#include "RTC.h"
#include "UART_IrDA.h"


//====================================
// NAME:          SetRTC
// Description:   Set the RTC time
// Parameters:
// Return Value:
// Limitations:
//====================================

 void SetRTC(void)
 {
  int hour,minute,second,temp1,temp2;

  UART_Printf(UART2,"Input the hour value:\r\n");
  hour=UART_GetNum(UART2);
  UART_Printf(UART2,"Input the minute value:\r\n");
  minute=UART_GetNum(UART2);
  UART_Printf(UART2,"Input the second value:\r\n");
  second=UART_GetNum(UART2);
  
  MSI2C_AccessPage(RTC_page);
 //set RTC time
  temp1 = hour/10;
  temp2 = hour - temp1*10;
  MSI2C_MasterPollingSendAbb(RTC_HOURS_REG,(temp1<<4)|temp2);

  temp1 = minute/10;
  temp2 = minute - temp1*10;
  MSI2C_MasterPollingSendAbb(RTC_MINUTES_REG,(temp1<<4)|temp2);

  
  temp1 = second/10;
  temp2 = second - temp1*10;
  MSI2C_MasterPollingSendAbb(RTC_SECOND_REG,(temp1<<4)|temp2);

 __asm("nop");

  //enable RTC clock
  MSI2C_MasterPollingSendAbb(RTC_RTC_CTRL_REG,0x7);


   //enable RTC clock


 

  }

//====================================
// NAME:        ClearRTC
//DESCROPTION:  Clear the RTC time
//PARAMETERS:   
//RETURN VALUE:
//LIMITAITONS:
//====================================

 void ClearRTC(void)
 {
  MSI2C_AccessPage(RTC_page);
  MSI2C_MasterPollingSendAbb(RTC_RTC_CTRL_REG,0);
  MSI2C_MasterPollingSendAbb(RTC_HOURS_REG,0);
  MSI2C_MasterPollingSendAbb(RTC_MINUTES_REG,0);
  MSI2C_MasterPollingSendAbb(RTC_SECOND_REG,0);
  }




//====================================
// NAME:           ReadRTC
// DESPRIPTION:    Read the RTC time
// PARAMETERS:     
// RETURN VALUE:
// LIMITATIONS:
//====================================

 void ReadRTC(void)
 {
  int temp,hour,minute,second;
  
  MSI2C_AccessPage(RTC_page);
  
  hour = MSI2C_MasterPollingReceiveAbb(RTC_HOURS_REG);
  minute = MSI2C_MasterPollingReceiveAbb(RTC_MINUTES_REG);
  second = MSI2C_MasterPollingReceiveAbb(RTC_SECOND_REG);

  //temp = hour & 0xF;

  //RTC Time
  hour = (((hour>>4) & 0x3) * 10) + (hour & 0xF);
  temp = (((minute>>4) & 0x7) * 10) + (minute & 0xF);
  //minute= minute & 0xF;
  second = (((second>>4) & 0x7) * 10) + (second & 0xF);

  UART_Printf(UART2,"The RTC time is: %d:%d:%d\n\r",hour,temp,second);

  }

//====================================
// NAME:           Alarm_Test
// DESPRIPTION:    Test RTC alarm
// PARAMETERS:     
// RETURN VALUE:
// LIMITATIONS:
//====================================
 void Alarm_Test(void)
 {
  int hour,minute,second,temp1,temp2,previous;
  
  UART_Printf(UART2,"Set Alarm Time\r\n");

  UART_Printf(UART2,"Input the hour value:\r\n");
  hour=UART_GetNum(UART2);
  UART_Printf(UART2,"Input the minute value:\r\n");
  minute=UART_GetNum(UART2);
  UART_Printf(UART2,"Input the second value:\r\n");
  second=UART_GetNum(UART2);

  MSI2C_AccessPage(RTC_page);
 
 //set Alarm time
  temp1 = hour/10;
  temp2 = hour - temp1*10;
  MSI2C_MasterPollingSendAbb(RTC_ALARM_HOURS_REG,(temp1<<4)|temp2);

  temp1 = minute/10;
  temp2 = minute - temp1*10;
  MSI2C_MasterPollingSendAbb(RTC_ALARM_MINUTES_REG,(temp1<<4)|temp2);

  temp1 = second/10;
  temp2 = second - temp1*10;
  MSI2C_MasterPollingSendAbb(RTC_ALARM_SECONDS_REG,(temp1<<4)|temp2);

  
  //enable Alarm interrupt
  previous = MSI2C_MasterPollingReceiveAbb(RTC_RTC_INTERRUPTS_REG);
  MSI2C_MasterPollingSendAbb(RTC_RTC_INTERRUPTS_REG,(previous | 0xd));//enable Alarm interrupt

  previous = MSI2C_MasterPollingReceiveAbb(RTC_RTC_INTERRUPTS_REG);
  
  //UART_Printf(UART2,"\nAlarm enabled! 0x%x\r\n",previous);
  
  if((previous>>3) & 0x1)
   {
    UART_Printf(UART2,"\nAlarm interrupt enabled!\r\n");
    }
	
	
 }

//====================================
// NAME:           Read_Register
// DESPRIPTION:    Read target register
// PARAMETERS:     
// RETURN VALUE:
// LIMITATIONS:
//====================================
 void Read_Register(void)
 {
  int page,address,content,i;
  int temp[8];
  
  // Get the register page 
  UART_Printf(UART2,"Enter the register page:\r\n");
  page = UART_GetNum(UART2);

  // Get the register address
  UART_Printf(UART2,"Enter the register address:\r\n");
  UART_Printf(UART2,"Dec");
  address = UART_GetNum(UART2);
  
  // Access target register
  MSI2C_AccessPage(page);
  content = MSI2C_MasterPollingReceiveAbb(address);

  UART_Printf(UART2,"\r\n");
  UART_Printf(UART2,"The register address is Page %d, 0x%x\r\n",page,address);

  UART_Printf(UART2,"The content is ");
  
  //temp[0] = content & 0x1

  for(i=7;i>=0;i--)
  {
   temp[i] = ((content >> i) & 0x1);
   
   UART_Printf(UART2,"%d",temp[i]);
   }

  UART_Printf(UART2,"\r\n");
 }


//====================================
// NAME:           Write_Register
// DESPRIPTION:    Read target register
// PARAMETERS:     
// RETURN VALUE:
// LIMITATIONS:
//====================================
 void Write_Register(void)
 {
  int page,address,content,i;
  
  // Get the register page 
  UART_Printf(UART2,"Enter the register page:\r\n");
  page = UART_GetNum(UART2);

  // Get the register address
  UART_Printf(UART2,"Enter the register address:\r\n");
  UART_Printf(UART2,"Dec");
  address = UART_GetNum(UART2);

  //Get the register content
  UART_Printf(UART2,"Enter the register content:\r\n");
  UART_Printf(UART2,"Dec");
  content = UART_GetNum(UART2);

  // Access target register
  MSI2C_AccessPage(page);
  MSI2C_MasterPollingSendAbb(address,content);

  UART_Printf(UART2,"The register address is Page %d, 0x%x\r\n",page,address);
  UART_Printf(UART2,"The content is 0x%x",content);
 }

//====================================

 void RTC_TestMenu(void)
 {
   int choice=1;
   while(choice)
   {
     UART_Printf(UART2,"\n\r");
     UART_Printf(UART2,"\t=================================\r\n");
     UART_Printf(UART2,"\t         RTC test menu\r\n");
     UART_Printf(UART2,"\t=================================\r\n");
     UART_Printf(UART2,"\t 0:EXIT\r\n");
     UART_Printf(UART2,"\t 1:Set RTC time\r\n");
	 UART_Printf(UART2,"\t 2:Clear RTC time\r\n");
	 UART_Printf(UART2,"\t 3:Read RTC time\r\n");
     UART_Printf(UART2,"\t 4:Alarm test\r\n");
     UART_Printf(UART2,"\t 5:Read Register\r\n");
     UART_Printf(UART2,"\t 6:Write Register\r\n");

     choice = UART_GetNum(UART2);
     UART_Printf(UART2,"\n\r");

     switch(choice)
	  {
	   case 0:
	    break;

       case 1:
	   {
	    SetRTC();
	    break;
	    }

        case 2:
		{
		 ClearRTC();
		 break;
		 }

        case 3:
		{
		 ReadRTC();
		 break;
		 }

        case 4:
		{
		 Alarm_Test();
		 break;
		}
        
		case 5:
		{
		 Read_Register();
		 break;
		}

        case 6:
		{
		 Write_Register();
		 break;
		}

        default:
		 break;
	   }//end switch
    }//end while
  }

⌨️ 快捷键说明

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