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

📄 main.c

📁 Demo HZ256 Cluster LCD2 CW31 SH v1 ICD
💻 C
📖 第 1 页 / 共 3 页
字号:
 	 
 	
 	  
 	 
 	  PORTT&=0xfd;
 	  PORTT|=0x02;
 	  PORTT&=0xfd;
 	  PORTT|=0x02;
 	  
 	  PORTT&=0xef;
 	  	motorMove(0,6700); 
 	  PORTT|=0x10;
 	  motorMove(0,5100);
 	  PORTT&=0xef;
 	  motorMove(0,5900);
 	  PORTT|=0x10;
 	
 	
 	
 	  for(j=0;j<20;j++)
 	    {
 	      ttemp[j]=readEEprom (0x05e8+j);
 	    }
 	     
 	   for(i=0;i<100 ;i++)
 	    {
 	      ttt[i]=0x55;
 	    }
 	    
 	    
 	    
 	    
 	    
 //	    j= eraseEEprom(0x400);
 	  
 //	    j= writeEEprom(0x400,200); 
 	    
 	    
 	    
 	    
 	    
 	    paddr=(unsigned int *)(0x400); 
 	      
 	 
 	 // INITEE= 0x00;   //0x09
 	  
 	  
 	  	 i=*paddr; 
 	     j=*(paddr+1) ;
 	  
 	    
 	   /*
     if((ECLKDIV&0x80)!=0x80)
     {
        ECLKDIV=0x28;
       }	   
 	  	 if(((ESTAT&0x20)==1)|| ((ESTAT&0x10)==1)) 
      {   
           ESTAT|=0x30;
          // return 1;
      }
      paddr=(unsigned int *)(0x400);
      while(!(ESTAT&0x80)) ; 
 	    *paddr=0xff; 
 	   ECMD=0x40;
      ESTAT|=0x80; 
       if(((ESTAT&0x20)==1)|| ((ESTAT&0x10)==1)) 
      {   
           ESTAT|=0x30;
          // return 1;
      }
 	    while(!(ESTAT&0x80)) ; //???????????????????
 	     while((ESTAT&0x40)==0);
 	   
 	   
 	   
 	 
 	  
 	  if((ECLKDIV&0x80)!=0x80)
     {
        ECLKDIV=0x28;
       }
 	 if(((ESTAT&0x20)==1)|| ((ESTAT&0x10)==1)) 
      {   
           ESTAT|=0x30;
          // return 1;
      }
      paddr=(unsigned int *)(0x400);
      while(!(ESTAT&0x80)) ;
      *paddr=6000;
      ECMD=0x20;
      ESTAT|=0x80; 
      if(((ESTAT&0x20)==1)|| ((ESTAT&0x10)==1)) 
      {   
           ESTAT|=0x30;
          // return 1;
      }
       while((ESTAT&0x40)==0);
      
 	  */
 	  
 	  	 i=*paddr; 
 	     j=*(paddr+1) ;
 	  
 	  j=(*((volatile unsigned char*)(0x400)));   
 	  j=(*((volatile unsigned char*)(0x401)));
 	     
 	// j= eraseEEprom(0x05f0);
 	  
 	// j= writeEEprom(0x05f0,0x33);
 	
 	 //   (*((volatile unsigned char*)(0x5f0))) =1; 
 	 //   (*((volatile unsigned char*)(0x5f1))) =0xaa;
 	 //   ECMD=0x20;
     //  ESTAT|=0x80; 
     //  while((ESTAT&0x40)==0);
    //   while(!(EPROT&0x80) );
 	   
 	  
 	
 	
 	
 	
 	
 	
 	
 	
 	
 
   {
            msg_send.id = CAN_MSG_ID;
            msg_send.data[0] = 0x66;
            msg_send.data[1] =0x77;
            msg_send.data[2] =0x77;
            msg_send.data[3] =0xee;
            msg_send.data[4] =0xff;
            msg_send.data[5] =0xaa;
            msg_send.data[6] =0x77;
            msg_send.data[7] =0x77;
            //msg_send.data[5] =0xaa;
            msg_send.len = 8;
            msg_send.RTR = FALSE;
            msg_send.prty = 0;
            (void)MSCANSendMsg(MSCAN_0, msg_send);
             
        }
 
      {
            msg_send.id = CAN_MSG_ID;
            msg_send.data[0] = 0x66;
            msg_send.data[1] =0x77;
            msg_send.data[2] =0x77;
            msg_send.data[3] =0xee;
            msg_send.data[4] =0xff;
            msg_send.data[5] =0xaa;
            msg_send.data[6] =0x77;
            msg_send.data[7] =0x77;
            //msg_send.data[5] =0xaa;
            msg_send.len = 8;
            msg_send.RTR = FALSE;
            msg_send.prty = 0;
            (void)MSCANSendMsg(MSCAN_1, msg_send);
             
        }
     }
     
 	
 	
 	   while(1)
      {
           if(!(ATDSTAT0 & 0x80))  
            {
               if(!(ATDSTAT1 & 0x01))  
                   j=0xcc;
            }
           
            while(!(ATDSTAT0 & 0x80))             
             ;

       j= ATDDR0H;                    
       
      	                   
        // Resets SCF flag
        ATDSTAT0 = 0x80;     
        //ATDCTL5 = 0x20;//left justified ,unsigned result      //0x32 
         
         
         
         if(MSCANCheckRcvdMsg(MSCAN_1))
        {
            if(MSCANGetMsg(MSCAN_1, &msg_get))
            {
                if(msg_get.id == CAN_MSG_ID && msg_get.RTR == FALSE)
                  {
                   // disp_light_pattern((unsigned char)(msg_get.data[0] * 9 / 256));
                    break;
                  }
                    
            }
        }
         if(MSCANCheckRcvdMsg(MSCAN_0))
        {
            if(MSCANGetMsg(MSCAN_0, &msg_get))
            {
                if(msg_get.id == CAN_MSG_ID && msg_get.RTR == FALSE)
                    break;
                  //  disp_light_pattern((unsigned char)(msg_get.data[0] * 9 / 256));
            }
        }
   
     }
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	motorMove(0,15001);
 	motorMove(0,11001);
 	motorMove(0,15002);
 	motorMove(0,11002);
 	motorMove(0,15003);
 	motorMove(0,11003);
 	motorMove(0,15004);
 	motorMove(0,11004);
 	motorMove(0,15005);
 	motorMove(0,11005);
    MotorFinalStep[0]=0;
    
  for(;;)  
    {
      if((PORTK&0x80)==0)
        {
          mainStatus=1;
        }
      if((PORTE&0x80)==0)
        {
          mainStatus=0;
        }
      if(mainStatus==0)
          {
            motorMove(0,15005);
          }
      if(mainStatus==1)
          {
            motorMove(0,11005);
          }
 	      
      
    }
    
  for(i=0;i<1000;i++)  
    {
      tt=mc33993read();
    }
     
    
    
  
  
for(;;)								// forever loop
  { 	
   check_motor_demo();	
  }
 	
  for(;;)								// forever loop
  {
    get_menu(NEW);    
	}
}


void initAdc(void)
  {
    // Configures the ATD peripheral
    // (7 conversions per sequence, 8 bit resolution, wrap around channel, continuous conversion)		 
    ATDCTL3 = 0x38;                                
    ATDCTL4 = 0x81;  //presaler                              
    ATDCTL0 = 0x01;    //wrap around      //0x03???????????????                      
    ATDCTL2 = 0x80;                                
    ATDCTL5 = 0x20;//left justified ,unsigned result      //0x32
  }
  
    
    
    
    	
/****************************************************************************
* init_system() -
*    
*    System initialisation subroutine
*****************************************************************************/
void init_system(void)
{	
	init_PLL();	          // PLL initialization
	init_timer();			    // internal timer initialization
	init_stepper1();		  // Speedometer initialization
	init_stepper2();		  // Tachometer initialization
	init_stepper3();		  // Fuel mter initialization
	init_stepper4();		  // Temperature meter initialization
	init_port();				  // port initialization
	initAdc();
	MSCANInit(MSCAN_0);
	MSCANInit(MSCAN_1);
	PORTP&=0x0f;
}

/****************************************************************************
* init_lcd2() -
*    
*    To initialize LCD2
*****************************************************************************/
void init_lcd2(void)
{  
	// lcd module initialization
	char			i;
	volatile unsigned int	*ptr;
		
	LCDCR0=0xa0;	//LCDEN LCLK(488) BIASW duty1/4     				
					      //10	100       0     00
	FPENR0=0xff;  // FPENR0=0xff
	FPENR1=0xff;  // FPENR1=0xff
	FPENR2=0xff;  // FPENR2=0xff
	FPENR3=0xff;  // FPENR3=0xff
	
	ptr = &LCDRAMW0;
	for(i=0;i<8;i++)
	  *ptr++=0xffff;	  

	LCD2_check();				  // LCD2 check
	init_lcd_var();			  // lcd variables initialization
}

/****************************************************************************
* init_var() -
*    
*    Internal variables initialisation subroutine
*****************************************************************************/
void init_var(void)
{
	byte temp[4],i;
  
	MotorStep=1;						    // motor step initialization
	Mileage=0;									// mileage initialization
	LCDTestFlag=DISABLE;				// disable LCD panel test flag
	MotorTest=N_A;				      
	HourData=12;								// HourData initialization
	PowerFlag=ON;               // power on

	for(i=0;i<4;i++){ 
    MotorMode[i]=NORMAL;      // MotorMode initialization
	  temp[i]=0;
	  DemoIndex[i]=0;
	}
}

/****************************************************************************
* init_port() -
*
*    To initialize the portAD for home search
*****************************************************************************/
void init_port(void)
{	
  //???????????????????
  //ATDDIEN = 0x0f; // enable PORTAD bit 0-3 as input motor home search
  
  PERAD = 0x0f;   // pull up PORTAD bit 0-3 are for input motor home search  	
  
  //PORTS = 0xF0;
  //DDRS  = 0xF0;	  // ports bit 4(R),5(N),6(D),7(L)
 // PORTP = 0x3A;
 // DDRP  = 0x3A;   // portp bit 1(right),3(left),4(low fuel), 5(brake)
  PORTB|=0x78;
  DDRB|=0x78;
  PUCR&=0xfd;
  PORTS=0x50;
  DDRS=0x50;
  
   PORTK|=0x80;   
   DDRK&=0x7f;
   PORTE|=0x80;
   DDRE&=0x80;
   
   PORTP|=0x30;
   DDRP|=0x30;
   RDRP|=0X30;
   
  
 
  
}


/****************************************************************************
* init_clock() -
*    
*   To initialise the LCD display clock 
*****************************************************************************/
void init_clock(void)
{	
	char	i,j;	            // clock initialziation
	for(i=1;i<7;i++)
		j=LCD_Disp(i, 0xff);
	for(i=7;i<10;i++)
		j=LCD_Disp(i, 0);	
	Digit10(OFF);	
}

/****************************************************************************
* clock_on() -
*
*   To turn on the clock to display on LCD panel
*****************************************************************************/
void clock_on(void)
{	
	char	i,j;
	
	LCD_hex_clk_dec(MinData);	    
	if(HourData<12)
	  HourData=12;
	  
	if(HourData>=24)
	{
	  for(i=7;i<10;i++)
	    j=LCD_Disp(i, 0);
	  HourData=12;		    //reset hr data
	  Digit10(ON);
	  j=LCD_Disp(9, HourData-10);
	}
	else if((HourData>=22)&&(HourData<24))
	{
	  Digit10(ON);			  // Digit10 no display
	  j=LCD_Disp(9, HourData-22);
	}
	else if(HourData==12)
	{
	  Digit10(ON);			  // Digit10 no display
	  j=LCD_Disp(9, HourData-10);
	}
	else 
	{
	  Digit10(OFF);			  // Digit10 no display
	  j=LCD_Disp(9, HourData-12);
	}
}

/****************************************************************************
* LCD_off() -
*
*   To display clock "On" subroutine
*****************************************************************************/
void LCD_on(void)
{	
	char	i,j;
	
	for(i=1;i<10;i++)
		j=LCD_Disp(i, 0xff);
	Digit10(OFF);
	DigitDP(OFF);
	DigitDot(OFF);
	DigitA(OFF);
	DigitB(OFF);
	DigitTrip(OFF);
	DigitODO(OFF);
	j=LCD_Disp(8, 0x0);
	j=LCD_Disp(7, 0xa);	
}

/****************************************************************************
* LCD_off() -
*
*   To display clock "Off" subroutine
*****************************************************************************/
void LCD_off(void)
{	
	char	i,j;
	
	for(i=1;i<10;i++)
		j=LCD_Disp(i, 0xff);
	Digit10(OFF);
	DigitDP(OFF);
	DigitDot(OFF);
	DigitA(OFF);
	DigitB(OFF);
	DigitTrip(OFF);
	DigitODO(OFF);
 	j=LCD_Disp(9, 0);
	j=LCD_Disp(8, 0xf);
	j=LCD_Disp(7, 0xf);	
}

/****************************************************************************
* init_PLL() -
*
*   To initialize the PLL for system use.
*****************************************************************************/
void init_PLL(void)
{
	REFDV = REFDVVal;		// set the REFDV register to give us a 1.0 MHz reference.
	SYNR = SYNRVal;			// set the SYNR register to give us a 8.0 MHz E-clock.
    asm	nop					  // nops required for PLL stability.
    asm	nop 
    asm	nop
    asm	nop
	while ((CRGFLG&LOCK)==0);	// wait here till the PLL is locked.	
	CLKSEL|= PLLSEL;			    // switch the bus clock to the PLL.
}


/****************************************************************************
* LCD2_check() -
*
*   To check the desire characters displaying in LCD2 panel
*****************************************************************************/
void LCD2_check()
{	    
	char			i,j,r,s;
	unsigned int data;
	
  r=0;  
  i=LCD_Seg_Disp(4,ON);		          // display "FSL"
  i=LCD_Seg_Disp(5,ON);
  i=LCD_Seg_Disp(6,ON);

	for(i=1;i<7;i++) {
	  for(j=0;j<10;j++) {
	    r=LCD_Disp(i, j);					// off col[6]
	    data=0xffff;          // data = 65535
	    while((data--)!=0);		// while loop
	  }
	  
	  s+=1;
	  s&=0x1;
	  DigitDot(s);

    if(s==1) 
    {
      DigitTrip(ON);
      DigitODO(ON);  
      DigitA(ON);
      DigitB(ON);	
    }
    else 
    {
      DigitODO(OFF);  
      DigitTrip(OFF);
      DigitA(OFF);
      DigitB(OFF);	
    }			
  }
}

/****************************************************************************
* init_lcd_var() -
*
*   To initialize LCD variables for system use.
*****************************************************************************/
void init_lcd_var(void)			  // lcd variables initialization
{
	LCDBlink=0;				   // init
	LCDPreTime=Time8ms;
	LCDRotTime=100;
	LCDBlinkTime=100;
	LCDLen=39;

	LCDStatus=MILEAGE;
	LCDMileage=TRIPA;
	
	
}

⌨️ 快捷键说明

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