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

📄 timer.c

📁 dz3000_51.0.0.4.rar
💻 C
📖 第 1 页 / 共 3 页
字号:
/*++

Copyright (c) 2001 Sunplus Technology Co., Ltd.

Module Name:

        timer.c

Abstract:

        Module related to timer

Environment:

        Keil C51 Compiler

Note:

        Since in-line assembly code is included, pre-compile C51 file
        to A51 file. Then assemble A51 file.

Revision History:

        08/28/2001      Chi-Yeh Tsai    created

--*/

//=============================================================================
//Header file
//=============================================================================
#include "general.h"
#include "timer.h"
#include "ui.h"
#include "cardlink.h"
#include "audio.h"

//ada@0415 test ui
#include "main.h"
#include "uiflow.h"

//Joe@2003.3.4 20:31 add begin
#include "JoeToEvb.h"
xdata UCHAR G_KeepPushKeyCount;
extern xdata UCHAR old_Audeokey;
//Joe@2003.3.4 20:32 add end
//=============================================================================
//Symbol
//=============================================================================
//-----------------------------------------------------------------------------
//Constant
//-----------------------------------------------------------------------------
#if (SIMULATE) // WWWW0409
sbit Key_Column1;
sbit Key_Column2;
#else
sbit Key_Column1 = P3^4;
sbit Key_Column2 = P3^5;
//Joe@2003.3.5 11:12 add begin
sbit Key_Column3 = P3^3;
//Joe@2003.3.5 11:12 add end
#endif

//Joe@2003.3.5 9:20 add begin
void	TIMER0_LowPowerCount(void);
//Joe@2003.3.5 9:20 add end
//patch5.03@Joe@2003.4.7 19:23 add begin
xdata UCHAR G_Timer0Count;
xdata USHORT  G_Timer0Count1;//wendy@2004/9/8
//patch5.03@Joe@2003.4.7 19:23 add end
//-----------------------------------------------------------------------------
//Variable
//-----------------------------------------------------------------------------
xdata ULONG G_TimeStamp;
xdata UCHAR G_KeyScan;

xdata UCHAR G_Timer0Stop;
//=============================================================================
//Program
//=============================================================================
//-----------------------------------------------------------------------------
//                               TIMER0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//TIMER0
//-----------------------------------------------------------------------------
void TIMER0_Routine(void) INTERRUPT_1 USING_2
{
     EX0 = 0;
     TIMER0_Handler();     //TIMER0 handler
     EX0 = 1;
}

//-----------------------------------------------------------------------------
//TIMER0_Handler
//-----------------------------------------------------------------------------
void TIMER0_Handler(void) USING_2
{
#if ( SIMULATE == 0 )
#pragma asm
     CLR     TR0
     MOV     A,#K_Timer0IntervalCompLo       ; 2 Instr. Cycles
     ADD     A,TL0                           ; 2 Instr. Cycles
     MOV     TL0,A                           ; 2 Instr. Cycles
     MOV     A,#K_Timer0IntervalCompHi       ; 2 Instr. Cycles
     ADDC    A,TH0                           ; 2 Instr. Cycles
     MOV     TH0,A                           ; 2 Instr. Cycles
     NOP                                     ; 1 Instr. Cycles
     NOP                                     ; 1 Instr. Cycles
     NOP                                     ; 1 Instr. Cycles
     NOP                                     ; 1 Instr. Cycles
     SETB    TR0                             ; 2 Instr. Cycles
                                             ;-----------------------------
                                             ; 14 Instr. Cycles Total =
                                             ; 18 * (4 / 24M) us =
                                             ; 3 us
#pragma endasm
#endif

/*     G_TimeStamp += K_TIMER_PERIOD;  //increase time stamp

//ada@0415 test ui
     if (G_TimeStamp >= 100)
     {
          TIMER0_Keypad_Scan();
          G_TimeStamp = 0;
          //Joe@2003.2.24 9:50 add begin
          TIMER0_LowPowerCount();
          G_AutoPowerOffCount++;
          //Joe@2003.2.24 9:51 add end

		//Joe@2003.3.3 19:56 add begin
		if ( (G_FlashCharging == 1) || (G_FlashCharging == 2) )
		{
		    if(G_FlashChargingCount < 200)
			G_FlashChargingCount++;
		}
		if (G_StayInMenu)
		{
			G_StayInMenuCount++;
		}
		//Joe@2003.3.3 19:56 add end
     }
     */
     
     //patch5.03@Joe@2003.4.7 19:23 modify begin
     //G_TimeStamp += K_TIMER_PERIOD;  //increase time stamp
     G_Timer0Count ++;
     G_Timer0Count1 ++;
     //patch5.03@Joe@2003.4.7 19:24 modify end

//ada@0415 test ui
          //TIMER0_Keypad_Scan();

     //patch5.03@Joe@2003.4.7 19:11 modify begin
     //if (G_TimeStamp >= 100)
     if( (G_Timer0Count % 2) == 0)	//20ms
     //patch5.03@Joe@2003.4.7 19:11 modify end
     {
          TIMER0_Keypad_Scan();

	  //patch5.03@Joe@2003.4.7 19:13 add begin
	  if(G_Timer0Count >= 10)		//100ms
	  //patch5.03@Joe@2003.4.7 19:14 add end
	  {
		//patch5.03@Joe@2003.4.7 19:24 modify begin
		//G_TimeStamp = 0;
		G_Timer0Count = 0;
		//patch5.03@Joe@2003.4.7 19:25 modify end

		//Joe@2003.2.24 9:50 add begin
		if(G_UI_USBConnect == K_UI_USB_DISCONNECT)
       	{
			TIMER0_LowPowerCount();
			//Joe@2003.2.24 9:51 add end

			//Joe@2003.3.3 19:56 add begin
			if ( (G_FlashCharging == 1) || (G_FlashCharging == 2) )
			{
			    if(G_FlashChargingCount <= 150)	//davis2004/11/26 modify
				G_FlashChargingCount++;
			}
			if (G_StayInMenu)
			{
				G_StayInMenuCount++;
			}
			//Joe@2003.3.3 19:56 add end
			}
	  }
     }
//wendy@2004/9/8	 
if(G_Timer0Count1>=25)
{
	if(G_CameraOptions.Timeout==1)
		G_AutoPowerOffCount++;
	else
		G_AutoPowerOffCount=0;

	G_Timer0Count1=0;

	if(G_FlashChargeFlag==1)
	{

	 	XBYTE[0x2033]= XBYTE[0x2033]^0x40;	//gpio 30
 //UI_Buzzer();
	}	
	

	if(G_FlashChargeFlag==2)
		G_FlashChargeCount++;
	
	
}

//wendy@2004/9/8

}

//-----------------------------------------------------------------------------
//TIMER0_Start
//-----------------------------------------------------------------------------
//ada@0415 test ui
//patch4.2@ada@0527 for key scan
void TIMER0_Start(void) USING_0
{
     G_TimeStamp = 0;        //clear time stamp
     G_KeyScan = 0;
     G_Timer0Stop = 0;

     //start timer
     ET0 = 1;                //IE:    TIMER0 interrupt enable
     TR0 = 1;                //TCON:  TIMER0 enable
}

//-----------------------------------------------------------------------------
//TIMER0_Stop
//-----------------------------------------------------------------------------
//ada@0415 test ui
//patch4.2@ada@0527 for key scan
void TIMER0_Stop(void) USING_0
{
     G_Timer0Stop = 1;

     //stop timer
     TR0 = 0;                //TCON:  TIMER0 disable
     ET0 = 0;                //IE:    TIMER0 interrupt disable
}

//=============================================================================
//TIMER0_Keypad_Scan
//=============================================================================
//ada@0415 test ui
//patch4.2@ada@0527 for key scan
void TIMER0_Keypad_Scan(void) USING_2
{

     //Joe@2003.3.7 15:45 add begin
     UCHAR mode;
     //Joe@2003.3.7 15:45 add end

    // G_KeyState =  K_UI_BUTTON_NULL; //yichang
     G_KeyScan = 1;
     if(G_KeyState !=  K_UI_BUTTON_NULL)
         return;

     //Joe@2003.3.5 11:09 add begin
     #if(ROTARY_KEY == 1)
     //Joe@2003.3.5 11:09 add end
     switch(TIMER0_Get_Hardware_Keypad2())
     {
          case K_RotarySwitchMode0:
               mode = (UCHAR)(((G_UIStatusH& UI_Status_Level2_Mask) >> 8) - 1);

               if(mode != K_UI_MODE_DSC_PREVIEW)
               {
                    G_KeyState = K_UI_BUTTON_PREVIEW_SWITCH;
               }

               break;

          case K_RotarySwitchMode1:
               mode = (UCHAR)(((G_UIStatusH& UI_Status_Level2_Mask) >> 8) - 1);

               if(mode != K_UI_MODE_DSC_PLAY)
               {
	       	     G_KeyState = K_UI_BUTTON_PLAY_SWITCH;
               }

               break;

          case K_RotarySwitchMode2:
               mode = (UCHAR)(((G_UIStatusH& UI_Status_Level2_Mask) >> 8) - 1);

               if(mode != K_UI_MODE_DSC_VIDEO)
               {
	       	     G_KeyState = K_UI_BUTTON_VIDEO_SWITCH;
               }

               break;

          case K_RotarySwitchMode3:
	  mode = (UCHAR)(((G_UIStatusH& UI_Status_Level2_Mask) >> 8) - 1);
			  
	  if(mode != K_UI_MODE_USB_PCCAM)
	  {
		G_KeyState = K_UI_BUTTON_PCCAM_SWITCH;
	  }
			  
	  break;
	 case K_RotarySwitchMode4:
	 mode = (UCHAR)(((G_UIStatusH& UI_Status_Level2_Mask) >> 8) - 1);
 
	if(mode != K_UI_MODE_DSC_AUDIO){
		G_KeyState = K_UI_BUTTON_AUDIO_SWITCH;
	 }					 
               break;
          case K_RotarySwitchPreviousMode:
               break;

          default:  //unknown mode for future use
               break;
     }

     //Joe@2003.3.7 13:21 add begin
     #else
     mode = (UCHAR)(((G_UIStatus & UI_Status_Level2_Mask) >> 8) - 1);
     if (G_IsKeyRelease == 0)
     {
	    if ((mode == K_UI_MODE_USB_PCCAM) || (mode == K_UI_MODE_DSC_PREVIEW))
            {
                    G_KeyState = K_UI_BUTTON_PREVIEW_SWITCH;
            }
            else if((mode == K_UI_MODE_USB_MASS_STORAGE) || (mode == K_UI_MODE_DSC_PLAY))
            {
                     G_KeyState = K_UI_BUTTON_PLAY_SWITCH;
            }
     }
     #endif
     //Joe@2003.3.7 13:21 add end
    TIMER0_Get_Hardware_Keypad1();
     switch(pressing_key)
     {
          case K_LeftKey:
		if (G_IsKeyRelease == 0)
		{
			G_KeyState = K_UI_BUTTON_LEFT;
			G_IsKeyRelease = 1;

			//Joe@2003.3.5 9:06 add begin
			G_KeepPushKeyCount = 0;
			//Joe@2003.3.5 9:06 add end
		}

		//Joe@2003.3.4 20:30 add begin
		else
		{
			if (G_KeepPushKeyCount < 10)
			{
				G_KeepPushKeyCount++;
			}
			else
			{
				G_KeepPushKeyCount = 10;
				G_KeyState  = K_UI_BUTTON_LEFT;
			}
		}
		//Joe@2003.3.4 20:30 mask end

               break;

          case K_UpKey:
		if (G_IsKeyRelease == 0)
		{
                 	 G_KeyState  = K_UI_BUTTON_UP;
			 G_IsKeyRelease = 1;

			//Joe@2003.3.5 9:06 add begin
			G_KeepPushKeyCount = 0;
			//Joe@2003.3.5 9:06 add end
		}

		//Joe@2003.3.4 20:30 add begin
		else
		{
			if (G_KeepPushKeyCount < 10)
			{
				G_KeepPushKeyCount++;
			}
			else
			{
				G_KeepPushKeyCount = 10;
				G_KeyState  = K_UI_BUTTON_UP;
			}
		}
		//Joe@2003.3.4 20:30 mask end
               break;

          case K_RightKey:
			if (G_IsKeyRelease == 0)
			{
			  G_KeyState  = K_UI_BUTTON_RIGHT;
			  G_IsKeyRelease = 1;

			//Joe@2003.3.5 9:06 add begin
			G_KeepPushKeyCount = 0;
			//Joe@2003.3.5 9:06 add end
			}

		//Joe@2003.3.4 20:30 add begin
		else
		{
			if (G_KeepPushKeyCount < 10)
			{
				G_KeepPushKeyCount++;
			}
			else
			{
				G_KeepPushKeyCount = 10;
				G_KeyState  = K_UI_BUTTON_RIGHT;
			}
		}
		//Joe@2003.3.4 20:30 mask end

               break;

          case K_DownKey:
			if (G_IsKeyRelease == 0)
			{
			  G_KeyState = K_UI_BUTTON_DOWN;
			  G_IsKeyRelease = 1;

			//Joe@2003.3.5 9:06 add begin
			G_KeepPushKeyCount = 0;
			//Joe@2003.3.5 9:06 add end
			}

		//Joe@2003.3.4 20:30 add begin
		else
		{
			if (G_KeepPushKeyCount < 10)
			{
				G_KeepPushKeyCount++;
			}
			else
			{
				G_KeepPushKeyCount = 10;
				G_KeyState  = K_UI_BUTTON_DOWN;
			}
		}
		//Joe@2003.3.4 20:30 mask end

               break;

          case K_MenuKey:
			if (G_IsKeyRelease == 0)
			{
			  G_KeyState = K_UI_BUTTON_MENU;
			  G_IsKeyRelease = 1;
			}
               break;

          case K_SelectKey:
			if (G_IsKeyRelease == 0)
			{
			  G_KeyState  = K_UI_BUTTON_SELECT;
			  G_IsKeyRelease = 1;
			}
               break;

          case K_Snap1Key:
			if (G_IsKeyRelease == 0)
			{
			  G_KeyState  = K_UI_BUTTON_SNAP1;
		       //G_IsKeyRelease = 1;

			}
               break;

          case K_Snap2Key:
               if (G_IsKeyRelease == 0)
			{
			  G_KeyState  = K_UI_BUTTON_SNAP2;
			  G_IsKeyRelease = 1;
               }

              break;

          //Joe@2003.3.5 12:49 add begin
/*	  case K_ModeKey:              
	  //case K_MenuKey:
               if (G_IsKeyRelease == 0)
	       {
	       	    if (((G_UIStatus & 0xff00) == K_UISTATUS_DSC_PREVIEW)||((G_UIStatus & 0xff00)==K_UISTATUS_USBMODE_PCCAM))//WENDY
                    {
                        G_KeyState = K_UI_BUTTON_PLAY_SWITCH;
                    }
                    else if(((G_UIStatus & 0xff00) == K_UISTATUS_DSC_PLAY)||((G_UIStatus & 0xff00)==K_UISTATUS_USBMODE_MASS))//WENDY
                    {
                         G_KeyState = K_UI_BUTTON_PREVIEW_SWITCH;
                    }
		    G_IsKeyRelease = 1;
               }

               break;

          case K_FlashKey:
               if (G_IsKeyRelease == 0)
	       {
			  G_KeyState  = K_UI_BUTTON_FLASH;
			  G_IsKeyRelease = 1;
               }

               break;
     */
          //Joe@2003.3.5 12:50 add end

	  case K_ReleaseKey:

		//Joe@2003.3.5 9:06 add begin
		G_KeepPushKeyCount = 0;
		//Joe@2003.3.5 9:06 add end

		G_IsKeyRelease = 0;
		break;

          default:

               break;
     }
}

//=============================================================================
//TIMER0_Get_Hardware_Keypad1
//=============================================================================
//ada@0415 test ui
//patch4.2@ada@0527 for key scan
void TIMER0_Get_Hardware_Keypad1(void) USING_2
	{
		 UCHAR temp_key;
	
     #if (TURNKEY_OPTION)
			  if (pressing_key == K_ReleaseKey)
			  {
				   //SCAN_A
				   TIMER0_SetGPIOBit(19,1);
				   TIMER0_SetGPIOBit(20,0);
				   TIMER0_SetGPIOBit(21,0);
		 
				   //DET_A

⌨️ 快捷键说明

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