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

📄 mcu.c

📁 车载SCALER模块源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*==========================================
==========================================*/
#include "include.h"
/*==========================================
==========================================*/
extern WarmUp();
void InitMCU(void)
{
	Byte xdata *Addr;
	Byte i;
	Addr = 0xf000;
	for(i=0; i<0x23; i++){
		*Addr = McuRegTab[i];
		Addr++;
	}
//	DrivePowOff();
	INTEXT_EN   = 0x02;
// set timer 0
 	SCON = 0x52;
 	TMOD = 0x22;	//timer0 /timer1 8 bits auto reload
// 	TMOD = 0x21;	//timer0 16 bits/timer1 8 bits auto reload
 	PCON = 0x80;
// timer0 8 bits auto reload
	TL0 = -200;
	TH0 =-200;
//	TL0 = 256-(CPU_CLK/1000*100/12000); //time base 100us
//	TH0 = 256-(CPU_CLK/1000*100/12000);

// timer0 16 bits
//	TL0 = (65536-CPU_CLK/1200)%256;	//time base 10ms
//	TH0 = (65536-CPU_CLK/1200)/256;

// For 12.000 MHz 
 	TL1 = 256-(2*CPU_CLK/384/9600);
 	TH1 = 256-(2*CPU_CLK/384/9600);
// For 14.318 MHz 
 	//TL1 = 256-(2*CPU_CLK/384/4800);
 	//TH1 = 256-(2*CPU_CLK/384/4800);
	TR0 = 1;		//start timer0
 	TR1 = 1;		//start timer1
// set interrupt
	EX1 = 1;		//enable External interrupt1
	ET0 = 1;		//enable timer0 interrupt
	EA = 1;			//enable all interrupt
	T0_INT_CNT = 0;
	T0_10ms_Cnt = 0;
	Sleep(50);	
}
/*==========================================
==========================================*/
void Timer0(void) interrupt 1 using 2
{
	if(++T0_INT_CNT >= 10){
		T0_INT_CNT = 0;
//		if(Timer1 != 0)			// 1ms
//			Timer1--;
		if(++T0_1ms_Cnt >= 10){	// 10ms
			CLRWDT = 0x55;
			T0_1ms_Cnt = 0;
			if(++T0_10ms_Cnt >= 100){//--1s
				T0_10ms_Cnt = 0;
			}
			if(OsdTimer > 0)
				OsdTimer--;
			if(LocalTimer > 0)
				LocalTimer--;
			if(PowerTimer > 0)
				PowerTimer--;
			if(LedTimer > 0)
				LedTimer--;
			if(RepeatTimer > 0)
				RepeatTimer--;
			if(DDCTimer > 0)
				DDCTimer--;
			if(SaveTimer > 0)
				SaveTimer--;
			if(VideoTimer > 0)
				VideoTimer--;
			if(BurnInTimer > 0)
				BurnInTimer--;
			if(MuteTimer > 0)
				MuteTimer--;		
		}
	}	
}
void Counter1(void) interrupt 3 using 3
{
    ScrnCount = 0;
	INTEXT_FLG = 0x02;
   	SCON = 0x52;
 	TMOD = 0x22;	//timer0 /timer1 8 bits auto reload
// 	TMOD = 0x21;	//timer0 16 bits/timer1 8 bits auto reload
 	PCON = 0x80;
// timer0 8 bits auto reload
	TL0 = -200;
	TH0 =-200;
//	TL0 = 256-(CPU_CLK/1000*100/12000); //time base 100us
//	TH0 = 256-(CPU_CLK/1000*100/12000);

// timer0 16 bits
//	TL0 = (65536-CPU_CLK/1200)%256;	//time base 10ms
//	TH0 = (65536-CPU_CLK/1200)/256;

// For 12.000 MHz 
 	TL1 = 256-(2*CPU_CLK/384/9600);
 	TH1 = 256-(2*CPU_CLK/384/9600);
// For 14.318 MHz 
 	//TL1 = 256-(2*CPU_CLK/384/4800);
 	//TH1 = 256-(2*CPU_CLK/384/4800);
	TR0 = 1;		//start timer0
 	TR1 = 1;		//start timer1
// set interrupt
	EX1 = 0;		//enable External interrupt1
	ET0 = 1;		//enable timer0 interrupt
	EA = 1;			//enable all interrupt
	T0_INT_CNT = 0;
	T0_10ms_Cnt = 0;

}
//+++++++++++++++++++++++++++++++++++++++++++
void KeyProsec()
{
    unsigned char KeyBuf;
//	 LED_RedOn();
	KeyBuf = ScanKey();
	if(KeyBuf == 14)
	   {
	     KeyBuffer = KeyBuf;
	   }
	printf("KeyBuff=%d\r\n",KeyBuf);
	if(KeyBuf == 0x11)
	   {
	     Sleep(800);
		 KeyBuf = ScanKey();

		 if(KeyBuf == 11)
		    {
			  KeyBuf = 0x00;
			  if(PowStart == 0xff)
			   {
 			     PowStart = 0x00;
                 PowNavOn();
               }
			   else 
			    {
				  PowStart = 0xff;
 				  PowNavOff();
				}
			}
	   }
    if(KeyBuf == 12)
       {
	      LED_RedOn();
	     PreCount++;
         if(PreCount == 0x00)
		   {
		     SyncMode = 3;
    
			 Pow3Off();
             Pow5Off();
			 Pow9Off();
	//		 SetCount = 0;
             FLG_Change_SyncMode = 1;
		   }
		else if(PreCount == 0x01)
		   {
//	
			    Pow3On();
                Pow5On();
                Pow9On();
             SyncMode = 0x00;
      
			 Sleep(200);  
		//		SetCount = 0;
				ChangeMode = 1;
                FLG_Change_SyncMode = 1;
		   }
        else if(PreCount == 0x02)
 		   {
		   //  PreCount =0x00;
             SyncMode = 0x01;
     
			   Pow3Off();
               Pow5Off();
               Pow9Off();
	
               FLG_Change_SyncMode = 1;
		   }
		 else if(PreCount == 0x03)
		   {
		      SyncMode = 0x03;
			  PreCount = 0;
	
			  Pow3Off();
              Pow5Off();
              Pow9Off();
       
		//
        //      FLG_Change_SyncMode = 1;
		   }
	   }
   if(KeyBuf == 13)
      {
	     CarDirecte +=1;
		 if(CarDirecte >=4)
		    {
			  CarDirecte = 2;
			}
	     driver2();
	
   	  }
}

//************************************************************
/*
void driver1()
{
  unsigned char temp;
 //    LED_GrnOn();
     if(CarDirecte == 2)
       {
	      DrivePowOn();
	      while((ParTest(temp, 0x78)) >6) //0x6E
		    {
			  temp = AdcCont();
			  temp &=0x7f;
			  printf("SCRET = %d\r\n",temp);
			  ScreenDown();
			  CLRWDT = 0x55;
			  
			}   
			
			ScreenStop();
          while(ReadCarStart() != 0)
           {
             CarBack();
             CLRWDT = 0x55;
             LED_GrnOn();
           }
           CarStop(); 
	     while(ReadCarend() != 0)
          {
            CarFront();
            CLRWDT = 0x55;
            
          }
          CarStop();
  	   
//	      ScreenUp();
      while((ParTest(temp,0x18))>6 || (temp == 0))  //0x2A  45
         {
           
		   temp = AdcCont();
  		   temp &=0x7f;
		   ScreenUp();
		   CLRWDT = 0x55;
//		   LED_GrnOn();
          }       
//		  LED_GrnOff();  
		  ScrnCount = 0;
		
       ScreenStop();
       CarDirecte=CarDirecte+1;
  //	   if(CarDirecte == 3)
  //      LED_GrnOff();
  	   temp = 0;
       }
     else if(CarDirecte == 3)
      { 
	  
	//    i = Read24C16(ep_Seven_Page);
        ScreenDown();
	    while((ParTest(temp,0x78))>6)
         {
           ScreenDown();
           temp = AdcCont();
		   temp &=0x7f;
           CLRWDT = 0x55;
          }    
	       ScreenStop();
//		Write24C16(ep_Seven_Page,0x00);
        ScrnCount = 0;
    
	    while((ReadCarStart())!=0)
         {
          CarBack();
          CLRWDT = 0x55;
		 }
        CarStop();
        CarDirecte=CarDirecte-1;
        temp = 0;
 //       if(CarDirecte == 2)
//		 LED_GrnOn(); 
        DrivePowOff();
	   return;	 
       }
	   
  // }  
}
unsigned char AdcCont()
 {
 //  unsingned int cycl;
   unsigned char  vel1;
   ADC_CON=STRT_ADC|EN_ADC0;//|EN_ADC3;
 //  Sleep(1);
   while(ADC3_REG&CMP_ADC ==0)
    {
      CLRWDT = 0x55;
          
    }
    vel1=ADC0_REG;
    printf("ADC0_REG=%c\n",vel1);
    Sleep(10);
 //   while(vel1 !=46)  //(abs(vel1-vel2) >3 )
 //   {
  //    if(CMP_ADC==1)
  //     {
   //      ScreenDown();
   //    	 vel1=ADC0_REG;
   //      CLRWDT = 0x55;
//		 LED_GrnOff();
    //   }	
   // }
 //    CLRWDT = 0x55;
    ScrnCount= vel1;
//	if((vel1 ==46) || (vel1==66) || (vel1==83) || (vel1==71) || (vel1==76) || (vel1==81) || (vel1==5)|| (vel1==10) || 
//	            (vel1==15) || (vel1==20) || (vel1==25) || (vel1==30) || (vel1==35) || (vel1==40)) 
//       Write24C16(ep_SevenPage,ScrnCount);
//	   Sleep(20);
       
    return vel1;
}*/
void driver2(void)
{  
   TCON = 0x44;
   TMOD = 0x60;
   TL1 = 0x243;
   TH1 = 0x243;
   EX1 = 1;
   INTEXT_EN = 0x02;
   ScrnCount = 1;
     if(CarDirecte == 2)
      {
	    while(ScrnCount == 1)
 	       {
             ScreenDown();
           }            
      } 
     if(CarDirecte == 3)
	  {  
	    while(ScrnCount  == 1)
		   {
	         ScreenUp();
		   }
	  }
}

unsigned char ParTest(unsigned char k, unsigned m)
{
    unsigned char valu;
    if(k < m)
      {
        valu= m-k;
      }
    else
     {
       valu= k-m;
     }
   return valu;
}  
/*
void ResetCar()
{  
   while((ReadCarStart())!=0)
    {
      CarBack();
      CLRWDT = 0x55;
    }
    CarStop();
}

bit ReadCarStart()
{
    bit m;
   Byte Port;
   RDPA_REG |=PA6; 
   Port = PTA_REG;
   if((Port & PA6)!=0)
      {
	    m=1;
	   }
	else
	  {
	    m=0;
	   }
   return m; 
}
bit ReadCarend()
{
    bit m;
   Byte Port;
   RDPA_REG |=PA4; 
   Port = PTA_REG;
   if((Port & PA4)!=0)
      {
	    m=1;
	   }
	else
	  {
	    m=0;
	   }
   return m;
}

void CarBack()
{
    Byte Port;
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port |= PA2;
	PTA_REG = Port;
  
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port &= ~PA0;
	PTA_REG = Port;
}
void CarStop()
{
    Byte Port;
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port &= ~PA2;
	PTA_REG = Port;
  
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port &= ~PA0;
	PTA_REG = Port;
}
void CarFront()
{
    Byte Port;
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port &= ~PA2;
	PTA_REG = Port;
 //   
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port |= PA0;
	PTA_REG = Port;
}
*/
void ScreenUp()
{
  Byte Port;
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port |= PA1;
	PTA_REG = Port;
  
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port &= ~PA0;
	PTA_REG = Port;
}
void ScreenStop()
{
    Byte Port;
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port &= ~PA1;
	PTA_REG = Port;
  
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port &= ~PA0;
	PTA_REG = Port;
}
void ScreenDown()
{
    Byte Port;
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port &= ~PA1;
	PTA_REG = Port;
  
	Port = PTA_REG;		
	Port |= RDPA_REG;
	Port |= PA0;
	PTA_REG = Port;
}
//********************************************************
//********************************************************
//==========================================
unsigned char ScanKey()
{
 unsigned char  i,k=0,j,h,m=0;
 line1h();
 line2h();
 line3h();
 line4h();

 for(i=4;i<8;i++)
  {//p2.i=0;
     CLRWDT = 0x55; 
    switch(i)
     {
     	case 4:{
     		    line1l();
     	    	break;
     	       }
     	case 5:{
     	    	line2l();
     	    	break;
     	        }
     	case 6:{
     		    line3l();
     		    break;
     	       }      
     	case 7:{
     		    line4l();
     		    break;
     	       }  
       } 
       
 //  }
     
   for(j=1;j<4;j++)
    {
    if((Row1()==0))
	   {
	         k=i;
             i=8;
             h=1;
             j=5;
//		 LED_GrnOff();
       }
	else if(Row2()==0)
	   {
	    k=i;
	    i=8;
	    h=2;
	    j=6;
//	LED_GrnOff();
	   }
	else if(Row3()==0)
	   {
	    k=i;
	    i=9;
	    h=3;

⌨️ 快捷键说明

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