Beispiel #1
0
int main()
{
    unsigned char i=0;

    HalLcd_HW_Init();                //oled 初始化
    LCD_Fill(0xff);                  //屏全亮

    while(1)
    {
        for(i=0; i<8; i++)
        {
            LCD_P16x16Ch(i*16,0,i);  //点阵显示
            LCD_P16x16Ch(i*16,2,i+8);
            LCD_P16x16Ch(i*16,4,i+16);
            LCD_P16x16Ch(i*16,6,i+24);
        }
        HalHW_WaitMS(1000);
        LCD_CLS();
        LCD_P8x16Str(44,0,"saler");
        LCD_P8x16Str(20,2,"OLED DISPLAY");

        LCD_P8x16Str(8,4,"TEL:18588220515");
        LCD_P6x8Str(20,6,"*****@*****.**");
        LCD_P6x8Str(20,7,"2013-10-6 18:18");
        HalHW_WaitMS(1000);

        //LCD_CLS();
        //Draw_BMP(0,0,128,8,BMP);     //图片显示
        //DelayMS(1000);
    }
}
/*******************************************************************************
* Function Name  : VCOMHelp
* Description    : Prints hint to the screen.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void VCOMHelp(void)
{
  sFONT *OldFont = CurrentFont;
  LCD_Method OldMethod = CurrentMethod;

  LCD_CLS();
  CurrentMethod = MET_AND;
  CurrentFont = &Font_6x8;
  DisplayMenuTitle("MDR_USB. Virtual COM");
  WAIT_UNTIL_KEY_RELEASED(SEL);
  LCD_PUTS(0, CurrentFont->Height * 2 + 2,     "  To stop Press SEL");

  CurrentMethod = OldMethod;
  CurrentFont = OldFont;
}
Beispiel #3
0
void para_display(void)
{
	LCD_CLS();
	LCD_P8x16Str(8,0,"jz");
	LCD_P8x16Str(8,2,"K_m");
	LCD_P8x16Str(8,4,"KD");
	  para1=jiaozhengkey;
	  if(para1<0)  {LCD_P8x16Str(48,0,"-");para=(-1)*para1;}
	  else  {LCD_P8x16Str(48,0," ");para=para1;}
	  display_num(56,0,(int)para%1000/100);
	  display_num(64,0,((int)para%100)/10);
	  display_num(72,0,((int)para%10));
	  LCD_P8x16Str(80,0,".");
	  display_num(88,0,(int)(para*10)%10);
	  
	  para1=K_middle;
	  if(para1<0)  {LCD_P8x16Str(48,0,"-");para=(-1)*para1;}
	  else  {LCD_P8x16Str(48,0," ");para=para1;}
	  display_num(56,2,(int)para%1000/100);
	  display_num(64,2,((int)para%100)/10);
	  display_num(72,2,((int)para%10));
	  LCD_P8x16Str(80,2,".");
	  display_num(88,2,(int)(para*10)%10);
	  if(key_sel2==0)      LCD_P8x16Str(56,4,"    -");
	  else if(key_sel2==1) LCD_P8x16Str(56,4,"  -  ");
	  else if(key_sel2==2) LCD_P8x16Str(56,4," -   ");
	  else if(key_sel2==3) LCD_P8x16Str(56,4,"-    ");  
	  
	  para1=Key_KD;
	  if(para1<0)  {LCD_P8x16Str(48,0,"-");para=(-1)*para1;}
	  else  {LCD_P8x16Str(48,0," ");para=para1;}
	  display_num(56,4,(int)para%1000/100);
	  display_num(64,4,((int)para%100)/10);
	  display_num(72,4,((int)para%10));
	  LCD_P8x16Str(80,4,".");
	  display_num(88,4,(int)(para*10)%10);
	  if(key_sel2==0)      LCD_P8x16Str(56,6,"    -");
	  else if(key_sel2==1) LCD_P8x16Str(56,6,"  -  ");
	  else if(key_sel2==2) LCD_P8x16Str(56,6," -   ");
	  else if(key_sel2==3) LCD_P8x16Str(56,6,"-    ");  
}
/*******************************************************************************
* Function Name  : DisplayMenu
* Description    : Displays the current menu
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void DisplayMenu(void)
{
  uint32_t y, index;
  tMenuItem psMenuItem2;

  LCD_CLS();
  CurrentMethod = MET_AND;

  /* Display menu header */
  DisplayMenuTitle(psCurrentMenu->psTitle);
  /* Display menu items */
  for (index = 0, y = CurrentFont->Height + 4;
       index < psCurrentMenu->nItems;
       index++, y += CurrentFont->Height + 2)
  {
    psMenuItem2 = &(psCurrentMenu->psItems[index]);
    DisplayMenuItemString(y, psMenuItem2->psTitle);
  }

  /* Determine current item */
  psMenuItem = &(psCurrentMenu->psItems[MenuItemIndex]);
  CurrentMethod = MET_NOT_XOR;
  LCD_PUTS(0, (MenuItemIndex * (CurrentFont->Height + 2) + CurrentFont->Height + 4), "                                        ");
}
Beispiel #5
0
 void main()
{  
 DisableInterrupts;
      
   volatile u8 i;
   u32 bianliang;  
 
  flash_init();
  gpio_init (PORTA, 24, GPI_UP_PF,1);///////拨码
  gpio_init (PORTA, 25, GPI_UP_PF,1);
  gpio_init (PORTA, 6, GPI_UP_PF,1);
  gpio_init (PORTA, 10, GPI_UP_PF,1);///////按键
  gpio_init (PORTA, 12, GPI_UP_PF,1);
  gpio_init (PORTA, 8, GPI_UP_PF,1);
  
  if(gpio_get(PORTA,24)==1&&gpio_get(PORTA,25)==1&&gpio_get(PORTA,6)==0)
   {    
     
      LCD_Init();
   //flash_erase_sector(255);
 //  flash_write(255,0x004,0x03e8);/////////////////////////////需要给定初值时
     while(1&&tx==0)
     {
       if(gpio_get(PORTA,10)==0)
       {
         delayms(100);
         if(gpio_get(PORTA,10)==0)/////////确定按下加计数
         { 
           bianliang=flash_read(255,0x004,u32);
           delayms(50);
           bianliang+=5;
           flash_erase_sector(255);
           delayms(50);
           flash_write(255,0x004, (u32)bianliang);
           delayms(50);
           LCD_CLS();
           LCD_PrintValueI(8, 4, bianliang);
         } 
       }

     if(gpio_get(PORTA,12)==0)
     {
        delayms(100);
         if(gpio_get(PORTA,12)==0)
         {
        
             bianliang=flash_read(255,0x004,u32);
             delayms(50);
             bianliang-=5;
             flash_erase_sector(255);
             delayms(50);
             flash_write(255,0x004,(u32)bianliang); 
             delayms(50);
             LCD_CLS();//清屏
             LCD_PrintValueI(8, 4,bianliang);
         }
      }
      
     if(gpio_get(PORTA,8)==0)
     {
        delayms(100);
        if(gpio_get(PORTA,8)==0)
        {          
            tx=1;   
        }
        else
          tx=0;
     }

  
     }
   }
  /////////////////////////////////////////////////////////////////////////////////////////单道设置档
  if(gpio_get(PORTA,24)==0&&gpio_get(PORTA,25)==1&&gpio_get(PORTA,6)==0)//////////////右转正值
  {
    LCD_Init();
    while(1)
   {
    if(gpio_get(PORTA,10)==0)
       {
         delayms(100);
         if(gpio_get(PORTA,10)==0)/////////单道右转
         {
           delayms(50);
           flash_erase_sector(254);
           delayms(50);
           flash_write(254,0x004, (u32)6);
           delayms(50);
           LCD_Char( 10,3,'R');
           LCD_Char(26 ,3,'+') ;
           LCD_Char(32 ,3,'6') ;
         }
       }
    if(gpio_get(PORTA,12)==0)
       {
         delayms(100);
         if(gpio_get(PORTA,12)==0)/////////单道左转
         {
           delayms(50);
           flash_erase_sector(254);
           delayms(50);
           flash_write(254,0x004, (u32)(-6));
           delayms(50);
           LCD_CLS();
           LCD_Char( 10,3,'L');
           LCD_Char(26 ,3,'-') ;
           LCD_Char(32 ,3,'6') ;
         }
       }  
    if(gpio_get(PORTA,8)==0)
       {
         delayms(100);
         if(gpio_get(PORTA,8)==0)/////////单道直道
         {
           delayms(50);
           flash_erase_sector(254);
           delayms(50);
           flash_write(254,0x004, (u32)0);
           delayms(50);
           LCD_CLS();
           LCD_Char(32 ,3,'0');
         }
       }  
   }
  }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////速度档位  
  
  if(gpio_get(PORTA,24)==1&&gpio_get(PORTA,25)==1&&gpio_get(PORTA,6)==1)/////////////////////
   {    
       yz=10,yz1=6,yz2=3;///定义搜线阈值
      buxianL=25,buxianR=27;//左右补线值
      dandao=(int)flash_read(254,0x004,u32);
      zhijiao=8;//直角延时场数
      quanheiMAX=60;//全黑最大值
      quanbaiMIN=80;//全白最小值
      dandaoBDD=9.455;////////////////////////////////////////////////////////////
      dandaoHDD=9.455;////////////////////////////////////////////////////////////
      zhijiaoBDpwmmax=500.0;
      zhijiaoBS_Kp=10.0;
      zhijiaoBD_Kp=378.25;
      zhijiaoHDpwmmax=300.0;
      zhijiaoHS_Kp=42.0;//50轻微振荡
      zhijiaoHD_Kp=305.25;//299.25

      zkp=2200;//清华PD:2053   卡尔曼PD:2200
      zkd=47;//44/////////////50 
      
      S_Kpstart=10.0;//  1.3
      S_Kistart=33.91;//11.8
      S_Kpend=42.0;///////////////29.0
      S_Kiend=32.01;//11.8
      Sqiwang =1400;//  1.3
      Sjishu =7;//11.8
        
      D_Kp =305.25;   //299.25
      D_Kd =300.0;//
      D_Kdd=9.455;//12.05
      zhangaiDmax=300.0;
      direction_pwmmax=300.0;
   }
  
  if(gpio_get(PORTA,24)==0&&gpio_get(PORTA,25)==1&&gpio_get(PORTA,6)==1)/////////////////////
  {
        yz=10,yz1=6,yz2=3;///定义搜线阈值
      buxianL=25,buxianR=27;//左右补线值
      dandao=(int)flash_read(254,0x004,u32);
      zhijiao=10;//直角延时场数
      quanheiMAX=60;//全黑最大值
      quanbaiMIN=80;//全白最小值
      dandaoBDD=9.455;////////////////////////////////////////////////////////////
      dandaoHDD=9.455;////////////////////////////////////////////////////////////
      zhijiaoBDpwmmax=500.0;
      zhijiaoBS_Kp=10.0;
      zhijiaoBD_Kp=378.25;
      zhijiaoHDpwmmax=300.0;
      zhijiaoHS_Kp=42.0;//50轻微振荡
      zhijiaoHD_Kp=305.25;//299.25

      zkp=2200;//清华PD:2053   卡尔曼PD:2200
      zkd=47;//44/////////////50 
      
      S_Kpstart=10.0;//  1.3
      S_Kistart=33.91;//11.8
      S_Kpend=42.0;///////////////29.0
      S_Kiend=32.01;//11.8
      Sqiwang =1400;//  1.3
      Sjishu =7;//11.8
        
      D_Kp =305.25;   //299.25
      D_Kd =300.0;//
      D_Kdd=9.455;//12.05
      zhangaiDmax=300.0;
      direction_pwmmax=300.0;
  }
  
  
  
   if(gpio_get(PORTA,24)==1&&gpio_get(PORTA,25)==0&&gpio_get(PORTA,6)==1)/////////////////////
   {     
       yz=10,yz1=6,yz2=3;///定义搜线阈值
      buxianL=25,buxianR=27;//左右补线值
      dandao=(int)flash_read(254,0x004,u32);
      zhijiao=12;//直角延时场数
      quanheiMAX=60;//全黑最大值
      quanbaiMIN=80;//全白最小值
      dandaoBDD=9.455;////////////////////////////////////////////////////////////
      dandaoHDD=9.455;////////////////////////////////////////////////////////////
      zhijiaoBDpwmmax=500.0;
      zhijiaoBS_Kp=10.0;
      zhijiaoBD_Kp=378.25;
      zhijiaoHDpwmmax=300.0;
      zhijiaoHS_Kp=42.0;//50轻微振荡
      zhijiaoHD_Kp=305.25;//299.25

      zkp=2200;//清华PD:2053   卡尔曼PD:2200
      zkd=47;//44/////////////50 
      
      S_Kpstart=10.0;//  1.3
      S_Kistart=33.91;//11.8
      S_Kpend=42.0;///////////////29.0
      S_Kiend=32.01;//11.8
      Sqiwang =1400;//  1.3
      Sjishu =7;//11.8
        
      D_Kp =305.25;   //299.25
      D_Kd =300.0;//
      D_Kdd=9.455;//12.05
      zhangaiDmax=300.0;
      direction_pwmmax=300.0;
   }
  
  if(gpio_get(PORTA,24)==0&&gpio_get(PORTA,25)==0&&gpio_get(PORTA,6)==1)//////////////////////最低速     1400
  {
       yz=10,yz1=6,yz2=3;///定义搜线阈值
      buxianL=25,buxianR=27;//左右补线值
      dandao=(int)flash_read(254,0x004,u32);
      zhijiao=14;//直角延时场数
      quanheiMAX=60;//全黑最大值
      quanbaiMIN=80;//全白最小值
      dandaoBDD=9.455;////////////////////////////////////////////////////////////
      dandaoHDD=9.455;////////////////////////////////////////////////////////////
      zhijiaoBDpwmmax=500.0;
      zhijiaoBS_Kp=10.0;
      zhijiaoBD_Kp=378.25;
      zhijiaoHDpwmmax=300.0;
      zhijiaoHS_Kp=42.0;//50轻微振荡
      zhijiaoHD_Kp=305.25;//299.25

      zkp=2200;//清华PD:2053   卡尔曼PD:2200
      zkd=47;//44/////////////50 
      
      S_Kpstart=10.0;//  1.3
      S_Kistart=33.91;//11.8
      S_Kpend=42.0;///////////////29.0
      S_Kiend=32.01;//11.8
      Sqiwang =1400;//  1.3
      Sjishu =7;//11.8
        
      D_Kp =305.25;   //299.25
      D_Kd =300.0;//
      D_Kdd=9.455;//12.05
      zhangaiDmax=300.0;
      direction_pwmmax=300.0; 
  }
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////特殊速度档
      if(gpio_get(PORTA,24)==0&&gpio_get(PORTA,25)==0&&gpio_get(PORTA,6)==0)
  {
      yz=10,yz1=6,yz2=3;///定义搜线阈值
      buxianL=25,buxianR=27;//左右补线值
      dandao=(int)flash_read(254,0x004,u32);
      zhijiao=14;//直角延时场数
      quanheiMAX=60;//全黑最大值
      quanbaiMIN=80;//全白最小值
      dandaoBDD=9.455;////////////////////////////////////////////////////////////
      dandaoHDD=9.455;////////////////////////////////////////////////////////////
      
      zhijiaoBDpwmmax=500.0;
      zhijiaoBS_Kp=10.0;
      zhijiaoBD_Kp=378.25;
      zhijiaoHDpwmmax=300.0;
      zhijiaoHS_Kp=42.0;//50轻微振荡
      zhijiaoHD_Kp=305.25;//299.25

      zkp=2400;//清华PD:2053   卡尔曼PD:2200
      zkd=47;//44/////////////50 
      
      S_Kpstart=10.0;//  1.3
      S_Kistart=31.91;//11.8
      S_Kpend=42.0;///////////////29.0
      S_Kiend=30.01;//11.8
      Sqiwang =1400;//  1.3
      Sjishu =7;//11.8
        
      D_Kp =305.25;   //299.25
      D_Kd =300.0;//
      D_Kdd=9.455;//12.05
      zhangaiDmax=300.0;
      direction_pwmmax=300.0;
  }
  
    if(gpio_get(PORTA,24)==1&&gpio_get(PORTA,25)==0&&gpio_get(PORTA,6)==0)//////////////////////////有值太大
  {
   
      yz=10,yz1=6,yz2=3;///定义搜线阈值
      buxianL=25,buxianR=27;//左右补线值
      dandao=(int)flash_read(254,0x004,u32);
      zhijiao=16;//直角延时场数
      quanheiMAX=60;//全黑最大值
      quanbaiMIN=80;//全白最小值
      dandaoBDD=9.455;////////////////////////////////////////////////////////////
      dandaoHDD=9.455;////////////////////////////////////////////////////////////
      
      zhijiaoBDpwmmax=500.0;
      zhijiaoBS_Kp=10.0;
      zhijiaoBD_Kp=378.25;
      zhijiaoHDpwmmax=300.0;
      zhijiaoHS_Kp=42.0;//50轻微振荡
      zhijiaoHD_Kp=305.25;//299.25

      zkp=2400;//清华PD:2053   卡尔曼PD:2200
      zkd=47;//44/////////////50 
      
      S_Kpstart=10.0;//  1.3
      S_Kistart=31.91;//11.8
      S_Kpend=42.0;///////////////29.0
      S_Kiend=30.01;//11.8
      Sqiwang =1400;//  1.3
      Sjishu =7;//11.8
        
      D_Kp =305.25;   //299.25
      D_Kd =300.0;//
      D_Kdd=9.455;//12.05
      zhangaiDmax=300.0;
      direction_pwmmax=300.0;
  }

   /**/
  
     //串口初始化
 asm("nop");
  asm("nop");
asm("nop");
  asm("nop");
asm("nop");
  asm("nop");


asm("nop");
  asm("nop");

  if(tx==1)
     uart_init(UART5,115200);
  else
  uart_init(UART5,9600); 
 asm("nop");
  asm("nop");

   //CCD及其各引脚初始化
   CCD1_init() ;
   CCD2_init() ;
asm("nop");
  asm("nop");



   //PWM输出初始化
    FTM_PWM_init(FTM0, CH0, 10000, 0);  //R后退        
    FTM_PWM_init(FTM0, CH1, 10000, 0);   //R前进         
    FTM_PWM_init(FTM0, CH2, 10000, 0);   //L后退        
    FTM_PWM_init(FTM0, CH3, 10000, 0); //L前进
   //拨码初始化
   // gpio_init (PORTA, 7, GPI_UP_PF,1);
    
asm("nop");
asm("nop");

    gpio_init (PORTE, 1, GPI,0);
    gpio_init (PORTD, 15, GPI,0); 
    gpio_init (PORTD, 14, GPI,0);
    gpio_init (PORTD, 12,GPI,0);
    
asm("nop");
asm("nop");
asm("nop");
  asm("nop");
    //正交解码初始化
    FTM1_QUAD_Iint();
    FTM2_QUAD_Iint();
asm("nop");
asm("nop");    
asm("nop");
asm("nop");
    //各种中断初始化
 pit_init_ms(PIT0, 1);
   asm("nop");
asm("nop");
asm("nop");
asm("nop");

    // 陀螺仪及加速度计初始化
    adc_init(ADC0, AD12);      //////  PTB2    ENC      
    adc_init(ADC0, AD12);      ///PTB3      Z
    adc_init(ADC0, AD17);       ///PTE24     DIR_ENC

    /////////////////////////////////////////////////陀螺仪开机自检
  
        delayms(1000);
        gpio_init (PORTA, 17, GPO, 0);
         MMA7361level=flash_read(255,0x004,u32);
        rectifyT = ad_ave(ADC0,SE12,ADC_12bit,10);
    gyro_DIR=ad_ave(ADC0,SE17,ADC_12bit,10);
   // gyro_DIR=gyro_DIR/20;
      /////////////////////////////////////////////////        
//  gpio_init (PORTC, 0, GPI,0);不知道要用否
        delayms(1500); 
        EnableInterrupts;
        
    while(1)
     
    {  
       if((gpio_get(PORTD,12)==0)&&(gpio_get(PORTD,14)==0))//||(gpio_get(PORTE,1)==1)
         {b=1;d=0;}
    if(fs>=1)
     {
          DisableInterrupts;
         fs=0;js=0;
        ImageCapture1(Pixel1);
        ImageCapture2(Pixel2);
       EnableInterrupts;
       Analyze_CCD_Data();      
    }
     
    if(tx==1)
    {
   sendDataToCCDViewer(0,Pixel1);//////////////////////////////////////
        sendDataToCCDViewer(1,Pixel2); 
        sendDataToScope();
    }
  
    else
    {
OutData[0]=Min_Data1;//L_Max_Data_Place3
OutData[1]=Max_Data1;//R_Max_Data_Place1
OutData[2]=L_Max_Data_Place1; //L_Max_Data_Place1
OutData[3]=R_Max_Data_Place1;//
OutPut_Data();
    }//
//sb[0]=FTM1_CNT; 
//sb[1]=MMA7361; 
// tongxun();
    }     
    }
Beispiel #6
0
void para_set(void)
{    
	PORTB_PCR4|=PORT_PCR_PE_MASK|PORT_PCR_PFE_MASK;
	PORTB_PCR5|=PORT_PCR_PE_MASK|PORT_PCR_PFE_MASK;
	PORTB_PCR6|=PORT_PCR_PE_MASK|PORT_PCR_PFE_MASK;
	PORTB_PCR16|=PORT_PCR_PE_MASK|PORT_PCR_PFE_MASK;
	PORTB_PCR17|=PORT_PCR_PE_MASK|PORT_PCR_PFE_MASK;
	PORTE_PCR10|=PORT_PCR_PE_MASK|PORT_PCR_PFE_MASK;
	PORTE_PCR11|=PORT_PCR_PE_MASK|PORT_PCR_PFE_MASK;
	PORTE_PCR12|=PORT_PCR_PE_MASK|PORT_PCR_PFE_MASK;
//	if(!boma2_GetBit(3))
    {
    	LCD_P8x16Str(8,0,"jz");
    	LCD_P8x16Str(8,2,"K_m");
    	LCD_P8x16Str(8,4,"KD");
    	LCD_P8x16Str(8,6,"done");
    	while(1)
    	{
    		if(key_sel==0)
    		{
    		  LCD_P8x16Str(0,0,"*");
    		  LCD_P8x16Str(0,2," ");
    		  LCD_P8x16Str(0,4," ");
    		  LCD_P8x16Str(0,6," ");
    		  if(key_sel3==1)
    		  {
    			  jiaozhengkey=para1;
    			  if(para1<0)  {LCD_P8x16Str(48,0,"-");para=(-1)*para1;}
    			  else  {LCD_P8x16Str(48,0," ");para=para1;}
    			  display_num(56,0,(int)para%1000/100);
    			  display_num(64,0,((int)para%100)/10);
    			  display_num(72,0,((int)para%10));
    			  LCD_P8x16Str(80,0,".");
    			  display_num(88,0,(int)(para*10)%10);
    			  if(key_sel2==0)      LCD_P8x16Str(56,2,"    -");
    			  else if(key_sel2==1) LCD_P8x16Str(56,2,"  -  ");
    			  else if(key_sel2==2) LCD_P8x16Str(56,2," -   ");
    			  else if(key_sel2==3) LCD_P8x16Str(56,2,"-    ");    				  
    		  }
    		  else para1=jiaozhengkey;
    		}
    		else if(key_sel==1)
    		{
      		  LCD_P8x16Str(0,0," ");
      		  LCD_P8x16Str(0,2,"*");
      		  LCD_P8x16Str(0,4," ");
      		  LCD_P8x16Str(0,6," ");
    		  if(key_sel3==1)
    		  {
    			  K_middle=para1;
    			  if(para1<0)  {LCD_P8x16Str(48,2,"-");para=(-1)*para1;}
    			  else  {LCD_P8x16Str(48,2," ");para=para1;}
    			  display_num(56,2,(int)para%1000/100);
    			  display_num(64,2,((int)para%100)/10);
    			  display_num(72,2,((int)para%10));
    			  LCD_P8x16Str(80,2,".");
    			  display_num(88,2,(int)(para*10)%10);
    			  if(key_sel2==0)      LCD_P8x16Str(56,4,"    -");
    			  else if(key_sel2==1) LCD_P8x16Str(56,4,"  -  ");
    			  else if(key_sel2==2) LCD_P8x16Str(56,4," -   ");
    			  else if(key_sel2==3) LCD_P8x16Str(56,4,"-    ");  
    		  }
    		  else  para1=K_middle;;
    		}
    		else if(key_sel==2)
    		{
      		  LCD_P8x16Str(0,0," ");
      		  LCD_P8x16Str(0,2," ");
      		  LCD_P8x16Str(0,4,"*");
      		  LCD_P8x16Str(0,6," ");
    		  if(key_sel3==1)
    		  {
    			  Key_KD=para1;
    			  if(para1<0)  {LCD_P8x16Str(48,4,"-");para=(-1)*para1;}
    			  else  {LCD_P8x16Str(48,4," ");para=para1;}
    			  display_num(56,4,(int)para%1000/100);
    			  display_num(64,4,((int)para%100)/10);
    			  display_num(72,4,((int)para%10));
    			  LCD_P8x16Str(80,4,".");
    			  display_num(88,4,(int)(para*10)%10);
    			  if(key_sel2==0)      LCD_P8x16Str(56,6,"    -");
    			  else if(key_sel2==1) LCD_P8x16Str(56,6,"  -  ");
    			  else if(key_sel2==2) LCD_P8x16Str(56,6," -   ");
    			  else if(key_sel2==3) LCD_P8x16Str(56,6,"-    ");  
    		  }
    		  else para1=Key_KD;
    		}
    		else if(key_sel==3)
    		{
      		  LCD_P8x16Str(0,0," ");
      		  LCD_P8x16Str(0,2," ");
      		  LCD_P8x16Str(0,4," ");
      		  LCD_P8x16Str(0,6,"*");
      		  if(key_sel3==1) 
      		  { LCD_P8x16Str(56,6,"done...");key_sel3=0; break;}
    		}
    	}
    /***************************************************************************************************/
    	LCD_CLS();
    	LCD_P8x16Str(8,0,"length");
    	LCD_P8x16Str(8,2,"pwml");
    	LCD_P8x16Str(8,4,"R yu");
    	LCD_P8x16Str(8,6,"done");
    	while(1)
    	{
    	    		if(key_sel==0)
    	    		{
    	    		  LCD_P8x16Str(0,0,"*");
    	    		  LCD_P8x16Str(0,2," ");
    	    		  LCD_P8x16Str(0,4," ");
    	    		  LCD_P8x16Str(0,6," ");
    	    		  if(key_sel3==1)
    	    		  {
    	    			  ren_para_length=para1;
    	    			  if(para1<0)  {LCD_P8x16Str(48,0,"-");para=(-1)*para1;}
    	    			  else  {LCD_P8x16Str(48,0," ");para=para1;}
    	    			  display_num(56,0,(int)para%10000/1000);
    	    			  display_num(64,0,(int)para%1000/100);
    	    			  display_num(72,0,((int)para%100)/10);
    	    			  display_num(80,0,((int)para%10));
    	    			  LCD_P8x16Str(88,0,".");
    	    			  display_num(92,0,(int)(para*10)%10);
    	    			  if(key_sel2==0)      LCD_P8x16Str(56,2,"     -");
    	    			  else if(key_sel2==1) LCD_P8x16Str(56,2,"   -  ");
    	    			  else if(key_sel2==2) LCD_P8x16Str(56,2,"  -   ");
    	    			  else if(key_sel2==3) LCD_P8x16Str(56,2," -    ");    				  
    	    		  }
    	    		  else para1=ren_para_length;
    	    		}
    	    		else if(key_sel==1)
    	    		{
    	      		  LCD_P8x16Str(0,0," ");
    	      		  LCD_P8x16Str(0,2,"*");
    	      		  LCD_P8x16Str(0,4," ");
    	      		  LCD_P8x16Str(0,6," ");
    	    		  if(key_sel3==1)
    	    		  {
    	    			  ren_para_pwm_l=para1;
    	    			  if(para1<0)  {LCD_P8x16Str(48,0,"-");para=(-1)*para1;}
    	    			  else  {LCD_P8x16Str(48,0," ");para=para1;}
    	    			  display_num(56,2,(int)para%10000/1000);
    	    			  display_num(64,2,(int)para%1000/100);
    	    			  display_num(72,2,((int)para%100)/10);
    	    			  display_num(80,2,((int)para%10));
    	    			  LCD_P8x16Str(88,2,".");
    	    			  display_num(92,2,(int)(para*10)%10);
    	    			  if(key_sel2==0)      LCD_P8x16Str(56,4,"     -");
    	    			  else if(key_sel2==1) LCD_P8x16Str(56,4,"   -  ");
    	    			  else if(key_sel2==2) LCD_P8x16Str(56,4,"  -   ");
    	    			  else if(key_sel2==3) LCD_P8x16Str(56,4," -    ");    
    	    		  }
    	    		  else  para1=ren_para_pwm_l;
    	    		}
    	    		else if(key_sel==2)
    	    		{
    	      		  LCD_P8x16Str(0,0," ");
    	      		  LCD_P8x16Str(0,2," ");
    	      		  LCD_P8x16Str(0,4,"*");
    	      		  LCD_P8x16Str(0,6," ");
    	    		  if(key_sel3==1)
    	    		  {
    	    			  ren_length=para1;
    	    			  if(para1<0)  {LCD_P8x16Str(48,4,"-");para=(-1)*para1;}
    	    			  else  {LCD_P8x16Str(48,4," ");para=para1;}
    	    			  display_num(56,4,(int)para%1000/100);
    	    			  display_num(64,4,((int)para%100)/10);
    	    			  display_num(72,4,((int)para%10));
    	    			  LCD_P8x16Str(80,4,".");
    	    			  display_num(88,4,(int)(para*10)%10);
    	    			  if(key_sel2==0)      LCD_P8x16Str(56,6,"    -");
    	    			  else if(key_sel2==1) LCD_P8x16Str(56,6,"  -  ");
    	    			  else if(key_sel2==2) LCD_P8x16Str(56,6," -   ");
    	    			  else if(key_sel2==3) LCD_P8x16Str(56,6,"-    ");  
    	    		  }
    	    		  else para1=ren_length;
    	    		}
    	    		else if(key_sel==3)
    	    		{
    	      		  LCD_P8x16Str(0,0," ");
    	      		  LCD_P8x16Str(0,2," ");
    	      		  LCD_P8x16Str(0,4," ");
    	      		  LCD_P8x16Str(0,6,"*");
    	      		  if(key_sel3==1) 
    	      		  { LCD_P8x16Str(56,6,"done...");key_sel3=0; break;}
    	    		}
    	}
    	/********************************************************************************/
    	LCD_CLS();
    	LCD_P8x16Str(8,0,"pwmr");
    	LCD_P8x16Str(8,2,"zhi_s");
    	LCD_P8x16Str(8,4,"ren_num");
    	LCD_P8x16Str(8,6,"done");
    	while(1)
    	{
    	    		if(key_sel==0)
    	    		{
    	    		  LCD_P8x16Str(0,0,"*");
    	    		  LCD_P8x16Str(0,2," ");
    	    		  LCD_P8x16Str(0,4," ");
    	    		  LCD_P8x16Str(0,6," ");
    	    		  if(key_sel3==1)
    	    		  {
    	    			  ren_para_pwm_r=para1;
    	    			  if(para1<0)  {LCD_P8x16Str(48,0,"-");para=(-1)*para1;}
    	    			  else  {LCD_P8x16Str(48,0," ");para=para1;}
    	    			  display_num(56,0,(int)para%10000/1000);
    	    			  display_num(64,0,(int)para%1000/100);
    	    			  display_num(72,0,((int)para%100)/10);
    	    			  display_num(80,0,((int)para%10));
    	    			  LCD_P8x16Str(88,0,".");
    	    			  display_num(92,0,(int)(para*10)%10);
    	    			  if(key_sel2==0)      LCD_P8x16Str(56,2,"     -");
    	    			  else if(key_sel2==1) LCD_P8x16Str(56,2,"   -  ");
    	    			  else if(key_sel2==2) LCD_P8x16Str(56,2,"  -   ");
    	    			  else if(key_sel2==3) LCD_P8x16Str(56,2," -    ");    				  
    	    		  }
    	    		  else para1=ren_para_pwm_r;
    	    		}
    	    		else if(key_sel==1)
    	    		{
    	      		  LCD_P8x16Str(0,0," ");
    	      		  LCD_P8x16Str(0,2,"*");
    	      		  LCD_P8x16Str(0,4," ");
    	      		  LCD_P8x16Str(0,6," ");
    	    		  if(key_sel3==1)
    	    		  {
    	    			  zhidao_speed=para1;
    	    			  if(para1<0)  {LCD_P8x16Str(48,0,"-");para=(-1)*para1;}
    	    			  else  {LCD_P8x16Str(48,0," ");para=para1;}
    	    			  display_num(56,2,(int)para%10000/1000);
    	    			  display_num(64,2,(int)para%1000/100);
    	    			  display_num(72,2,((int)para%100)/10);
    	    			  display_num(80,2,((int)para%10));
    	    			  LCD_P8x16Str(88,2,".");
    	    			  display_num(92,2,(int)(para*10)%10);
    	    			  if(key_sel2==0)      LCD_P8x16Str(56,4,"     -");
    	    			  else if(key_sel2==1) LCD_P8x16Str(56,4,"   -  ");
    	    			  else if(key_sel2==2) LCD_P8x16Str(56,4,"  -   ");
    	    			  else if(key_sel2==3) LCD_P8x16Str(56,4," -    ");    
    	    		  }
    	    		  else  para1=zhidao_speed;
    	    		}
    	    		else if(key_sel==2)
    	    		{
    	      		  LCD_P8x16Str(0,0," ");
    	      		  LCD_P8x16Str(0,2," ");
    	      		  LCD_P8x16Str(0,4,"*");
    	      		  LCD_P8x16Str(0,6," ");
    	    		  if(key_sel3==1)
    	    		  {
    	    			  ren_num=para1;
    	    			  if(para1<0)  {LCD_P8x16Str(48,4,"-");para=(-1)*para1;}
    	    			  else  {LCD_P8x16Str(48,4," ");para=para1;}
    	    			  display_num(56,4,(int)para%1000/100);
    	    			  display_num(64,4,((int)para%100)/10);
    	    			  display_num(72,4,((int)para%10));
    	    			  LCD_P8x16Str(80,4,".");
    	    			  display_num(88,4,(int)(para*10)%10);
    	    			  if(key_sel2==0)      LCD_P8x16Str(56,6,"    -");
    	    			  else if(key_sel2==1) LCD_P8x16Str(56,6,"  -  ");
    	    			  else if(key_sel2==2) LCD_P8x16Str(56,6," -   ");
    	    			  else if(key_sel2==3) LCD_P8x16Str(56,6,"-    ");  
    	    		  }
    	    		  else para1=ren_num;
    	    		}
    	    		else if(key_sel==3)
    	    		{
    	      		  LCD_P8x16Str(0,0," ");
    	      		  LCD_P8x16Str(0,2," ");
    	      		  LCD_P8x16Str(0,4," ");
    	      		  LCD_P8x16Str(0,6,"*");
    	      		  if(key_sel3==1) 
    	      		  { LCD_P8x16Str(56,6,"done...");key_sel3=0; break;}
    	    		}
    	}
    }
}
int main(int argc, char *argv[])
{
	int i, j, len;
	char buf[17];
	redisContext *ctx;
	redisReply   *reply;

	wiringPiSetup();
	LCD_Init();

	// banner
	LCD_Str(0,0,"================");
	LCD_Str(0,2,"  Redis->OLED   ");
	LCD_Str(0,4,"  Display       ");
	LCD_Str(0,6,"================");

	delay(3000);

	// clear
	LCD_CLS();
	delay(1000);

	// connect to redis
	ctx = redisConnect("127.0.0.1", 6379);
	if (ctx->err) {
		LCD_Err("cannot connect to Redis...");
		delay(2000);
		LCD_Err(ctx->errstr);
		return -1;
	}

	while(1) {
		for (i = 0; i < 4; ++i) {
			// clear buffer
			memset(buf, 0x20, 16);
			buf[16] = 0;

			// get string from Redis...(oled:0-3)
			reply = redisCommand(ctx, "GET oled:%d", i);
			if (reply == NULL) {
				LCD_Err("redisCommand() failed...");
				continue;
			}
			if (reply->type == REDIS_REPLY_ERROR) {
				LCD_Str(0, 2 * i, "                ");
				freeReplyObject(reply);
				continue;
			}
			printf("oled:%d -> %s\n", i, reply->str);
			if (reply->str == NULL) {
				LCD_Str(0, 2 * i, "                ");
				freeReplyObject(reply);
				continue;
			}

			// copy string to buffer
			len = strlen(reply->str);
			if (len > 16) len = 16;
			for (j = 0; j < len; ++j) {
				buf[j] = reply->str[j];
			}

			// set string to OLED
			LCD_Str(0, 2 * i, buf);

			freeReplyObject(reply);
		}

		delay(200);
	}

	return 0;
}
Beispiel #8
0
void Terminal(void)
{
    const char str1[] = {'k',0x00,'e',0x00,'y',0x00,'.',0x00,'b',0x00,'m',0x00,'p',0x00,'\0',0x00};
    const char str2[] = {'\\',0x00,'s',0x00,'y',0x00,'s',0x00,'\0',0x00};
    char KeyBuffer[31]={'Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M',',',' ',' ',' ','.'};
    char SpecialKeyBuffer[31]={'1','2','3','4','5','6','7','8','9','0','!','@','#','$','%','&','*','?','/','Z','"',' ','(',')','-','+',';',' ',' ',' ',':'};
     
    const unsigned short int LetterPosX[4]={93,62,32,1};
    const unsigned short int SpecialCharPosY[6]={1,284,1,39,245,284};
     
    const unsigned short int LetterPosY[31]={1,33,65,97,129,161,193,225,257,289,
                                             17,49,81,113,145,177,209,241,273,
                                                49,81,113,145,177,209,241,
                                                   81,113,145,177,209};
    _Bool NumSp=0,UppLow=0,ReadCmd=0,ErrorSyntax=0,HighApp=0,LowApp=0,SyntaxError=0,ExitApp=0,InitRfApp=0,SendApp=0,StatusRfApp=0,ReadApp=0,SetTime=0,SetDate=0;
    char c[2]={'A',0x00};
    char TextBuffer[10],i=0,b=0,Parametri=0,StringBuffer[50],Nchar=0,Param3[10],Param2[10],Param1[10],Param4[10],Param5[10];
    unsigned short int clu=0, dat=0,DelCount=0,a=0x0000;

    TRFData rfData;

    char  Minuti[3]={0x30,0x30,0x00};///minuti
    char  Ore[3]={0x30,0x31,0x00};///Ore

    
    SSD1289_writeResgiter( 0x0049, 0x000A );///fine della finestra a 10 px
    LCD_CLS(AZZURRO);
    sprintf(TextBuffer,"Loading..");
    LCD_Text57(2,1,TextBuffer,1,BLACK,NONE);
    Xcursor=238;
    Ycursor=2;
    wFSchdir ((unsigned short int *)&str2[0]);
    DrawBmp(0,319,(unsigned short int * )&str1[0],0);

    SSD1289_writeResgiter( 0x0049, 0x013F );
    while(TRUE)
    {
        if(PORTDbits.RD14==0)
        {
            read();
            clu=getX();
            dat=getY();
            clu=(unsigned short int)((((float)6.01/(float)233.01)*(float)clu)+(float)clu);
            dat=(unsigned short int)((((float)10.01/(float)313.01)*(float)dat)+(float)dat);
            b=0;
            for(i=0; i<31; i++)
            {
                ///lettere
                if((LetterPosX[b]<=clu)&&(clu<=(LetterPosX[b]+29))&&((LetterPosY[i]<=dat)&&(dat<=(LetterPosY[i]+29))))//la Q
                {
                    ///se attivo caratteri speciali
                    if(NumSp) c[0]=SpecialKeyBuffer[i];
                    else c[0]=KeyBuffer[i];
                    if((UppLow==1)&&(NumSp==0))
                    {
                        switch(c[0])
                        {
                            case ',':
                                break;
                            case' ':
                                break;
                            case'.':
                                break;
                            default:
                                c[0]+=0x20;
                                break;
                        }
                    }
                     
                    LCD_FastRect(Xcursor-6,Ycursor,Xcursor,Ycursor+5,WHITE);
                    strcpy(TextBuffer,c);
                    StringBuffer[Nchar]=c[0];
                    LCD_Text57Land(Xcursor,Ycursor,TextBuffer,1,BLACK,NONE);
                    Nchar++;
                    //Ycursor+=6;
                    if(Ycursor>=319)
                    {
                        Ycursor=2;
                        Xcursor-=8;
                        Nchar=0;
                    }
                    DelayMs(50);
                }
                if(i==9) b++;
                if(i==18) b++;
                if(i==25) b++;
            }

            ///comandi speciali
            b=2;
            for(i=0; i<6; i++)
            {
                if((LetterPosX[b]<=clu)&&(clu<=(LetterPosX[b]+29))&&((SpecialCharPosY[i]<=dat)&&(dat<=(SpecialCharPosY[i]+34))))//la Q
                {
                    switch(i)
                    {
                        case 0:
                            ///da implementare Upper/lower letter
                            if(UppLow==0)
                            {
                                UppLow=1;
                                LCD_Cercle(53,29,3,1,GRAY);
                            }
                            else
                            {
                                UppLow=0;
                                LCD_Cercle(53,29,3,1,BLUE);
                            }
                            break;
                        case 1:
                            LCD_FastRect(Xcursor-6,Ycursor,Xcursor,Ycursor+5,AZZURRO);
                            Ycursor-=6;
                            Nchar--;
                            if(Ycursor>350) 
                            {
                                Ycursor=314;
                                Xcursor+=8;
                                Nchar=0;
                               if(Xcursor>241) Xcursor=238;
                            }
                            break;
                         case 2:
                            ///da implementare
                            break;
                         case 3:
                            ///da implementare
                            break;
                         case 4:
                            ///da implementare attiva/disattiva numeri+caratteri speciali
                             if(NumSp==0)
                             {
                                 NumSp=1;
                                 LCD_Cercle(22,274,3,1,BLUE);
                             }
                             else
                             {
                                 NumSp=0;
                                 LCD_Cercle(22,274,3,1,GRAY);
                             }
                             break;
                        case 5:
                            ///torna a capo riga (invio)
                            LCD_FastRect(Xcursor-6,Ycursor,Xcursor,Ycursor+5,AZZURRO);
                            NumSp=0;
                            LCD_Cercle(22,274,3,1,GRAY);
                            UppLow=0;
                            LCD_Cercle(53,29,3,1,BLUE);
                            
                            Ycursor=2;
                            Xcursor-=8;
                            if(Xcursor<=136)
                            {
                                LCD_FastRect(121,0,239,319,AZZURRO);
                                Xcursor=238;
                            }
                            ReadCmd=1;
                            StringBuffer[Nchar]=0x00;
                            Nchar=0;
                            break;
                    }
                    DelayMs(50);
                }
                if(i==1) b=3;
            }
        }


        ///Lampeggio cursore
        DelayMs(1);
        DelCount++;
        if(DelCount==200)
        {
            DelCount=0;
            if(a==0x00000) a=0xffff;
            else a=0x0000;
            LCD_FastRect(Xcursor-6,Ycursor,Xcursor,Ycursor+5,a);
         }

        ///Se premuto invio..
        if(ReadCmd==1)
        {
            ReadCmd=0;
            ErrorSyntax=0;
            Parametri=0;
            b=0;

            ///Ciclo per verificare la stringa passata
            ///carica in Param1, Param2, Param3, ogni parola separata da uno spazio
            for(i=0; i<20; i++)
            {
                if(StringBuffer[i]==0x20) {Parametri=1; Param1[i]=0x00; break;}
                if(StringBuffer[i]==0x00) {Parametri=1; Param1[i]=0x00; break;}
                Param1[i]=StringBuffer[i];
            }

            if(StringBuffer[i]!=0x00)
            {
                b=0;
                for(i<20; i++;)
                {
                    if(StringBuffer[i]==0x20) {Parametri=2; Param2[b]=0x00; break;}
                    if(StringBuffer[i]==0x00) {Parametri=2; Param2[b]=0x00; break;}
                    Param2[b]=StringBuffer[i];
                    b++;
                }
            }

            if(StringBuffer[i]!=0x00)
            {
                b=0;
                for(i<20; i++;)
                {
                    if(StringBuffer[i]==0x20) {Parametri=3; Param3[b]=0x00;   break;}
                    if(StringBuffer[i]==0x00) {Parametri=3; Param3[b]=0x00; break;}
                    Param3[b]=StringBuffer[i];
                    b++;
                }
            }

            if(StringBuffer[i]!=0x00)
            {
                b=0;
                for(i<20; i++;)
                {
                    if(StringBuffer[i]==0x20) {Parametri=4; Param4[b]=0x00;   break;}
                    if(StringBuffer[i]==0x00) {Parametri=4; Param4[b]=0x00; break;}
                    Param4[b]=StringBuffer[i];
                    b++;
                }
            }

            if(StringBuffer[i]!=0x00)
            {
                b=0;
                for(i<20; i++;)
                {
                    if(StringBuffer[i]==0x20) {Parametri=5; Param5[b]=0x00;   break;}
                    if(StringBuffer[i]==0x00) {Parametri=5; Param5[b]=0x00; break;}
                    Param5[b]=StringBuffer[i];
                    b++;
                }
            }
            ///Fine ciclo

            //Verifica le stringhe
            //da completare salta al programma...
            if(strcmp(Param1,"HIGH")==FALSE) HighApp=1;
            if(strcmp(Param1,"LOW")==FALSE) LowApp=1;
            if(strcmp(Param1,"EXIT")==FALSE) ExitApp=1;
            if(strcmp(Param1,"REBOOT")==FALSE) SoftReset();
            if(strcmp(Param1,"SEND")==FALSE) SendApp=1;
            if(strcmp(Param1,"INITRF")==FALSE) InitRfApp=1;
            if(strcmp(Param1,"STATUSRF")==FALSE) StatusRfApp=1;
            if(strcmp(Param1,"READRF")==FALSE) ReadApp=1;
            if(strcmp(Param1,"SETTIME")==FALSE) SetTime=1;
            if(strcmp(Param1,"SETDATE")==FALSE) SetDate=1;


            if((HighApp==0)&&(LowApp==0)&&(ExitApp==0)&&(SendApp==0)&&(InitRfApp==0)&&(StatusRfApp==0)&&(ReadApp==0)&&(SetTime==0)&&(SetDate==0)) SyntaxError=1;

            if(SetTime)
            {
                SetTime=0;
                Ore[0]=Param2[0];
                Ore[1]=Param2[1];
                Minuti[0]=Param3[0];
                Minuti[1]=Param3[1];
                
                if((Ore[0]>=0x32)&&(Ore[1]>=0x34))
                {
                    sprintf(StringBuffer,"Ore invalide!");
                    LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,RED,NONE);
                }
                else if(Minuti[0]>=0x36)
                {
                    sprintf(StringBuffer,"Minuti  invalidi!");
                    LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,RED,NONE);
                }
                else{
                    
                    lastTime.hour=atobcd(&Ore[0]);
                    lastTime.min=atobcd(&Minuti[0]);               
                    RtccSetTimeDate(lastTime.l, lastDate.l);
                    sprintf(StringBuffer,"Time updated!");
                    LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                }
            }

            if(StatusRfApp)
            {
                StatusRfApp=0;
                StatusRead();
                sprintf(StringBuffer,"%02x ",TransceiverStatus.bits.RG_FF_IT);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                Ycursor+=16;
                sprintf(StringBuffer,"%02x ",TransceiverStatus.bits.POR);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                Ycursor+=16;
                sprintf(StringBuffer,"%02x ",TransceiverStatus.bits.RGUR_FFOV);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                Ycursor+=16;
                sprintf(StringBuffer,"%02x ",TransceiverStatus.bits.WKUP);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                Ycursor+=16;
                sprintf(StringBuffer,"%02x ",TransceiverStatus.bits.EXT);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                Ycursor+=16;
                sprintf(StringBuffer,"%02x ",TransceiverStatus.bits.LBD);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                Ycursor+=16;
                sprintf(StringBuffer,"%02x ",TransceiverStatus.bits.FFEM);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                Ycursor+=16;
                sprintf(StringBuffer,"%02x ",TransceiverStatus.bits.RSSI_ATS);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                Ycursor+=16;
                sprintf(StringBuffer,"%02x ",TransceiverStatus.bits.DQD);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                Ycursor+=16;
                sprintf(StringBuffer,"%02x ",TransceiverStatus.bits.CRL);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                Ycursor+=16;
                sprintf(StringBuffer,"%02x ",TransceiverStatus.bits.ATGL);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                Ycursor=2;
            }

            if(InitRfApp)
            {
                InitRfApp=0;

                if(strcmp(Param2,"OFF")==FALSE)
                {
                    MRF49XA_Power_Down();
                    sprintf(StringBuffer,"RF Stopped!");
                    LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,RED,NONE);
                }

                else{
                    initRFPorts();
                    MRF49XA_Init();
                    InitRFData(&rfData);
                    sprintf(StringBuffer,"RF Initialized! %x",RF_IRQ);
                    LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);

                }
            }

            if(ReadApp)///Test sniff pacchetti
            {
                WORD GENCREG2    = (0x8000|XTAL_LD_CAP_125);
                WORD CFSREG2                             ;
                WORD DRVSREG2                            ;
                WORD RXCREG2                             ;
                WORD PMCREG2 = 0x8201;
                WORD TXCREG2 = 0x9850;
                volatile BOOL RxPacketValid[BANK_SIZE];
                BYTE RxPacket[BANK_SIZE][80];
                volatile BYTE RxPacketLen[BANK_SIZE];
                WORD totalReceived = 0;
                unsigned char FreqBand=0,DataRate=0,Nop=0;
                ReadApp=0;
                sprintf(StringBuffer,"Reading..");
                  LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,AZZURRO);
                //Setta le porte
                mPORTFSetPinsDigitalOut(BIT_5);//SDO
                mPORTFSetPinsDigitalOut(BIT_13);//SCK
                mPORTBSetPinsDigitalOut(BIT_14);//CS
                mPORTBSetPinsDigitalOut(BIT_13);//FSEL
                mPORTESetPinsDigitalIn(BIT_9);//FINT
                mPORTESetPinsDigitalIn(BIT_8);//IRQ
                mPORTFSetPinsDigitalIn(BIT_4);//SDI
                mPORTFSetPinsDigitalIn(BIT_12);//INT

                SPI4CON = 0x0120;
                //SPI1BRG = 0x001F; // 64:1 prescale (slow display update)
                SPI4BRG = 0x0001; // 4:1 prescale (fast display update) 16Mhz spi clock at 72Mhz sys clock
                SPI4CONSET = 0x8000; // enables the spi

                RF_RSCLR;
                DelayUs(10);
                RF_RSSET;
                DelayMs(125);
                RF_CSSET;
                RF_FSELSET;
                //RF_SCKCLR;
                //RF_SDOCLR;
                ///Fine init porte

                i=Param2[0];

                //i=1;
                switch(i)
                {
                    case '1':
                        FreqBand = 1;
                        break;
                    case '2':
                        FreqBand = 2;
                        break;
                    case '3':
                        FreqBand = 3;
                        break;
                }
                GENCREG2 |= ((WORD)FreqBand << 4);

                i=Param3[0];
                //i=1;
                switch(i)
                {
                    case '1':
                        DataRate = 1;
                        DRVSREG2 = 0xC623;
                        break;
                    case '2':
                        DataRate = 2;
                        DRVSREG2 = 0xC611;
                        break;
                    case '3':
                        DataRate = 3;
                        DRVSREG2 = 0xC608;
                        break;
                    case '4':
                        DataRate = 4;
                        DRVSREG2 = 0xC605;
                        break;
                    case '5':
                        DataRate = 5;
                        DRVSREG2 = 0xC602;
                        break;
                }

                i=Param4[0];
                //i=4;
                switch(i)
                {
                    case '1':
                        RXCREG2 = 0x9421;
                        break;

                    case '2':
                        RXCREG2 = 0x9441;
                        break;

                    case '3':
                        RXCREG2 = 0x9461;
                        break;

                    case '4':
                        RXCREG2 = 0x9481;
                        break;

                    case '5':
                        RXCREG2 = 0x94A1;
                        break;

                    case '6':
                        RXCREG2 = 0x94C1;
                        break;
                }

                switch(FreqBand)
                {
                    case 1:
                        CFSREG2 = 0xA640;
                        break;

                    case 2:
                        CFSREG2 = 0xA640;
                        break;

                    case 3:
                        CFSREG2 = 0xA7D0;
                        break;

                    default:
                        break;
                }

                
                
                //Init RF
                SPI_Command(FIFORSTREG);
                SPI_Command( FIFORSTREG | 0x0002);
                SPI_Command(GENCREG2);
                SPI_Command(0xC4F7);
                SPI_Command(CFSREG2);
                SPI_Command(DRVSREG2);
                SPI_Command(PMCREG2);
                SPI_Command(RXCREG2);
                SPI_Command(TXCREG2);
                SPI_Command(PMCREG2 | 0x0020);
                DelayMs(5);
                SPI_Command(PMCREG2 | 0x0080);
                SPI_Command(GENCREG2 | 0x0040);
                SPI_Command(FIFORSTREG);
                SPI_Command( FIFORSTREG | 0x0002);
                SPI_Command(0x0000);

                //InitRFData(&rfData);
                sprintf(StringBuffer,"%x, %x, %x",Param2[0],Param3[0],Param4[0]);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,AZZURRO);
                sprintf(StringBuffer,"%x,%x",RF_IRQ,RF_INT);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,AZZURRO);
                while(TRUE)
                {
                    if((RF_IRQ==0)||(RF_INT==1))
                    {
                        
                        //nCS = 0;
                        RF_CSCLR;
                        Nop++;
                        if( SPI_SDI == 1 )
                        {
                            BYTE RxPacketPtr;
                            BYTE tmpPacketLen;
                            BYTE bIndex;
                            WORD counter;

                            // There is data in RX FIFO
                            //nCS = 1;
                            //nFSEL = 0;                   // FIFO selected
                            RF_CSSET;
                            RF_FSELCLR;

                            tmpPacketLen = SPI_Read();

                            for(bIndex = 0; bIndex < BANK_SIZE; bIndex++)
                            {
                                if( RxPacketValid[bIndex] == FALSE )
                                {
                                    break;
                                }
                            }

                            if( tmpPacketLen >= 80 || tmpPacketLen == 0 || bIndex >= BANK_SIZE )
                            {
                                IGNORE_HERE:
                                //nFSEL = 1;                          // bad packet len received
                                RF_FSELSET;
                                SPI_Command(PMCREG2);                // turn off the transmitter and receiver
                                SPI_Command(FIFORSTREG);            // reset FIFO
                                SPI_Command(GENCREG2);               // disable FIFO, TX_latch
                                SPI_Command(GENCREG2 | 0x0040);      // enable FIFO
                                SPI_Command(PMCREG2 | 0x0080);       // turn on receiver
                                SPI_Command(FIFORSTREG | 0x0002);   // FIFO synchron latch re-enabled
                                goto RETURN_HERE;
                            }

                            RxPacketLen[bIndex] = tmpPacketLen;
                            //RLED = 1;
                            //nFSEL = 1;
                            mPORTDSetBits(BIT_2);
                            RF_FSELSET;

                            RxPacketPtr = 0;
                            counter = 0;

                            while(1)
                            {
                                if( counter++ == 0xFFFF )
                                {
                                    goto IGNORE_HERE;
                                }
                                else if( RF_FINT == 1)
                                    {
                                    //nFSEL = 0;
                                    RF_FSELCLR;
                                    counter = 0;
                                    RxPacket[bIndex][RxPacketPtr++] = SPI_Read();

                                    if( RxPacketPtr >= RxPacketLen[bIndex] )
                                    {
                                        BYTE i;

                                        //nFSEL = 1;
                                        //nCS = 0;
                                        RF_FSELSET;
                                        RF_CSCLR;

                                        //SPI_SDO = 0;
                                        RF_SDOCLR;
                                        Nop++;
                                        for(i = 0; i < 8; i++)
                                        {
                                            //SPI_SCK = 1;
                                            //SPI_SCK = 0;                                       
                                            RF_SCKSET;
                                            Nop++;
                                            RF_SCKCLR;
                                            Nop++;
                                        }


                                        if( SPI_SDI == 0 )
                                        {
                                            goto IGNORE_HERE;
                                        }
                                        //nCS = 1;
                                        RF_CSSET;


                                        SPI_Command(FIFORSTREG);
                                        //RLED = 0;
                                        mPORTDClearBits(BIT_2);
                                        RxPacketValid[bIndex] = TRUE;
                                        SPI_Command(FIFORSTREG | 0x0002);            // FIFO synchron latch re-enable

                                        goto RETURN_HERE;
                                    }
                                    //nFSEL = 1;
                                    RF_FSELSET;
                                    }
                                }
                            }
                            else            // read the rest of the interrupts
                            {
                                SPI_Read();

                                //nCS = 1;
                                RF_CSSET;
                            }

                            RETURN_HERE:
                        Nop++;
                    }
                    
                    for(i = 0; i < BANK_SIZE; i++)
                    {
                        if( RxPacketValid[i] == TRUE )
                        {
                            BYTE j;
                            WORD received_crc;
                            WORD calculated_crc;
                
                            totalReceived++;  
                            //Printf("\r\n");
                            Xcursor-=8;
                            Ycursor=2;

                            sprintf(StringBuffer,"%04x | %04x |",totalReceived,RxPacketLen[i]);
                            LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                            //PrintChar(totalReceived>>8);
                            //PrintChar(totalReceived);

                            //Printf(" | ");
                            //PrintChar(RxPacketLen[i]);
                            //Printf(" | ");

                            for(j = 0; j < RxPacketLen[i]; j++)
                            {
                                sprintf(StringBuffer,"%02x ",RxPacket[i][j]);
                                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                                Ycursor+=12;
                                //PrintChar(RxPacket[i][j]);
                                //Printf(" ");
                            }
                            received_crc = ((WORD)RxPacket[i][RxPacketLen[i]-1]) + (((WORD)RxPacket[i][RxPacketLen[i]-2]) << 8);
                            calculated_crc = CRC16(RxPacket[i], RxPacketLen[i]-2);
                            if( received_crc != calculated_crc )
                            {
                                //Printf(" * CRC");
                                sprintf(StringBuffer," * CRC");
                                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
                            }
                            RxPacketValid[i] = FALSE;
                
                        }
                    }





















                    //i=MRF49XA_Receive_Packet(&rfData);
                    //DelayUs(50);
                    //if(i==3) break;
                    //if(i==2) break;
                    //if(i==1) break;
                    //sprintf(StringBuffer,"%x,%x,%x",RF_IRQ,RF_FINT,SPI_SDI);
                    //LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,AZZURRO);
                    if(PORTDbits.RD14==0) break;
                }
                Xcursor-=8;

                sprintf(StringBuffer,"Ricevuto! %d, 0x%02x, 0x%02x, 0x%02x, 0x%02x",i,rfData.buffer[0],rfData.buffer[1],rfData.buffer[2],rfData.buffer[3]);
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);


}
            if(SendApp)
            {
                SendApp=0;
                //LCD_FastRect(121,0,239,319,AZZURRO);
                AddRFData(&rfData,Param2[0]);
                MRF49XA_Send_Packet(&rfData);
		InitRFData(&rfData);

                sprintf(StringBuffer,"Dato inviato..");
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,BLACK,NONE);
            }
            if(HighApp)
            {
                HighApp=0;
                if(strcmp(Param2,"D2")==FALSE)
                {
                    sprintf(StringBuffer,"D2 Actived! 1");
                    LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,GREEN,NONE);
                    mPORTDSetPinsDigitalOut(BIT_2);
                    mPORTDSetBits(BIT_2);
                 }
                 else
                 {
                    sprintf(StringBuffer,"Port Not Found!");
                    LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,RED,NONE);
                 }
            }
            if(LowApp)
            {
                LowApp=0;
                if(strcmp(Param2,"D2")==FALSE)
                {
                    sprintf(StringBuffer,"D2 Deactived! 0");
                    LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,GREEN,NONE);
                    mPORTDSetPinsDigitalOut(BIT_2);
                    mPORTDClearBits(BIT_2);
                }
                else
                {
                    sprintf(StringBuffer,"Port Not Found!");
                    LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,RED,NONE);
                }
            }

            if(SyntaxError)
            {
                SyntaxError=0;
                sprintf(StringBuffer,"Syntax Error!");
                LCD_Text57Land(Xcursor,Ycursor,StringBuffer,1,RED,NONE);
            }

            if(ExitApp==1) break;
            
            Xcursor-=8;
            Ycursor=2;
            
            for(i=0; i<10; i++)
            {
                StringBuffer[i]=0x00;
                Param1[i]=0x00;
                Param2[i]=0x00;
                Param3[i]=0x00;
            }
        }
        if(PORTDbits.RD3==0) break;
    }
}