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

📄 main.c

📁 基于ARM的温度显示程序
💻 C
📖 第 1 页 / 共 2 页
字号:
      
      key = OSMboxPend(KeyMbox, 0, &err);
           
      if( ((int)key==KEY_LEFT)||
          ((int)key==KEY_RIGHT) ) 
      { select = 1- select;
      }
      
      if(((int)key==KEY_OK)&(select==0))    // 进入显示菜单
      {
         display_time();
         DrawMainWindow();
         GUI_WindowsDraw(&message_0);       // 显示对话框窗口
         GUI_PutString(8, 35, "welcome:");  // 显示对话框的消息"Hello,ZLG/GUI"
         GUI_PutString(8, 45, "time !");         
      }
      
      if(((int)key==KEY_OK)&(select==1))
      {  GUI_WindowsHide(&message_0); // 清除窗口显示
         return;
      }
   }
}


/************************************************************************/  
  void ADC_Init(void)                                           // ADC初始化及设置
    {PINSEL1 = (PINSEL1 & (~(0x03 << 28))) | (0x01 << 28);		// P0.30连接到AD0.3
	
	
	/* 进行ADC模块设置 */
	AD0CR = (1 << 3)						|	// SEL=8,选择通道3
			((Fpclk / 1000000 - 1) << 8)	|	// CLKDIV=Fpclk/1000000-1,转换时钟为1MHz
			(0 << 16)						|	// BURST=0,软件控制转换操作
			(0 << 17)						|	// CLKS=0, 使用11clock转换
			(1 << 21)						|  	// PDN=1,正常工作模式
			(0 << 22)						|  	// TEST1:0=00,正常工作模式
			(1 << 24)						|	// START=1,直接启动ADC转换
			(0 << 27);						 	// 直接启动ADC转换时,此位无效
	}
	
	
	
	
  void 	ADC_Start(void)                     // ADC转化开始
	{
	    ADC_Data = AD0DR;		            // 读取ADC结果,并清除DONE标志位
		AD0CR |= 1 << 24;					// 进行第一次转换
		while ((ADDR & 0x80000000) == 0);	// 等待转换结束
		AD0CR |= 1 << 24;					// 再次启动转换
		while ((AD0DR & 0x80000000) == 0);	// 等待转换结束
		ADC_Data = AD0DR;					// 读取ADC结果
		ADC_Data = (ADC_Data >> 6) & 0x3ff;
		ADC_Data = ADC_Data * 2480;			// 参考电压经过3/4分压
		ADC_Data = ADC_Data / 1024;
		
	}
	

/************************************************************************************/
  void GUI_Data(uint32 x,uint32 y,uint32 ADC_Data)
    {
      uint32 j,k;
      uint8  i;
      i=ADC_Data/1000;
      j=ADC_Data%1000;
      k=x;
      Sent_Num(k,y,i);
      
      i=j/100;
      j=j%100;
      k+=6;
      Sent_Num(k,y,i);
      
      i=j/10;
      j=j%10;
      k+=6;
      Sent_Num(k,y,i);
      
      k+=6;
      Sent_Num(k,y,i);
      
      return;
    }

/****************************************************************************
* 函数 display_ADC_bx()
* 功能 实现ADC及其波形和值的显示
****************************************************************************/
 void display_ADC_bx(void)
   { 
        
     uint32  i;
     uint32  j;
            
     for(i=5; i<76; i++)
      { 
       ADC_Start();                     // 采样程序
       
        j=ADC_Data*45;
        j=j/3300;
        j=60-j;
        bx[i]=j;
        
       GUI_Data(91,17,ADC_Data);
    
       GUI_Point(i,j,1);
     
       OSTimeDlyHMSM(0 , 0, 0, 80);     // 延时,设置采样频率
      }
      
     
   }

/****************************************************************************
* 函数 display_ADC_bx()
* 功能 显示ADC后的波形及数值的窗口
****************************************************************************/
 void display_ADC(void)
   {
    uint8  select;
    uint8  *key;
    uint8  err;
    uint8  i,j;
   
    WINDOWS  message_a;

   message_a.x = 0;                   // 设置窗口位置和大小
   message_a.y = 0;
   message_a.with = 128;
   message_a.hight = 64;
   message_a.title = (uint8 *) "the value of ADC"; // 窗口标题
   message_a.state = (uint8 *) 0;
   GUI_WindowsDraw(&message_a);       // 显示对话框窗口
   
   GUI_PutString(2,14,"^y/mV");
   GUI_PutString(60,53,"x/t");
       
   GUI_Line(4,14,4,62,1);                   // 坐标,纵轴
   GUI_Line(2,60,76,60,1);                 // 坐标,横轴
   
   select = 0;
   while(1)
   {  
      
      if(select==0)
      {  GUI_Button_OK1(78,29);     // 选中"OK"按钮
         GUI_Button_Cancle(78,46);  // 取消"CANSEL"按钮的选中状态
      }
      else
      {  GUI_Button_OK(78,29);
         GUI_Button_Cancle1(78,46);
      }
      
      key = OSMboxPend(KeyMbox, 0x03ff, &err);
           
      if( ((int)key==KEY_LEFT)||
          ((int)key==KEY_RIGHT) ) 
      { select = 1- select;
      }
      
      if(((int)key==KEY_OK)&(select==0))
      {          
        for(i=5;i<76;i++)
         {  
          j=bx[i];
          GUI_Point(i,j,0);
         }
        display_ADC_bx();                  // 显示波形及数值
      }
      
      if(((int)key==KEY_OK)&(select==1))                              
      {
         GUI_WindowsHide(&message_a); // 清除窗口显示
         return;
      }
   }
   }

/****************************************************************************
* 名称: DemoMessage_1()
* 功能: ADC数据采集及显示
****************************************************************************/
void  DemoMessage_1(void)
{  uint8  select;
   uint8  *key;
   uint8  err;
   
   WINDOWS  message_1;

   message_1.x = 5;       // 设置窗口位置和大小
   message_1.y = 14;
   message_1.with = 120;
   message_1.hight = 48;
   message_1.title = (uint8 *) "Message for Demo"; // 窗口标题
   message_1.state = (uint8 *) 0;
   GUI_WindowsDraw(&message_1);       // 显示对话框窗口
   GUI_PutString(8, 35, "welcome:");  // 显示对话框的消息"Hello,ZLG/GUI"
   GUI_PutString(8, 45, "ADC !");
   
   select = 0;
   while(1)
   {  if(select==0)
      {  GUI_Button_OK1(72,29);     // 选中"OK"按钮
         GUI_Button_Cancle(72,45);  // 取消"CANSEL"按钮的选中状态
      }
      else
      {  GUI_Button_OK(72,29);
         GUI_Button_Cancle1(72,45);
      }
      
      key = OSMboxPend(KeyMbox, 0, &err);
           
      if( ((int)key==KEY_LEFT)||
          ((int)key==KEY_RIGHT) ) 
      { select = 1- select;
      }
      
      if(((int)key==KEY_OK)&(select==0))    // 进入显示菜单
      {
         display_ADC();                     //ADC数据采集显示及波形显示
         DrawMainWindow();
         GUI_WindowsDraw(&message_1);       // 显示对话框窗口
         GUI_PutString(8, 35, "welcome:");  // 显示对话框的消息"Hello,ZLG/GUI"
         GUI_PutString(8, 45, "ADC !");         
      }
      
      if(((int)key==KEY_OK)&(select==1))
      {  GUI_WindowsHide(&message_1);       // 清除窗口显示
         return;
      }
   }
}
/****************************************************************************
* 名称: DemoMessage()
* 功能: 显示一个消息框(包含OK和CANCEL两个命令按钮),显示消息
*       为"Hello,ZLG/GUI",然后等待按键输入。
* 入口参数: 无
* 出口参数: 无
****************************************************************************/
void  DemoMessage(void)
{  uint8  select;
   uint8  *key;
   uint8  err;
   
   WINDOWS  message;

   message.x = 5;                    // 设置窗口位置和大小
   message.y = 14;
   message.with = 120;
   message.hight = 48;
   message.title = (uint8 *) "Message for Demo"; // 窗口标题
   message.state = (uint8 *) 0;
   GUI_WindowsDraw(&message);       // 显示对话框窗口
   GUI_PutString(8, 35, "Hello,");  // 显示对话框的消息"Hello,ZLG/GUI"
   GUI_PutString(8, 45, "ZLG/GUI!");
   
   select = 0;
   while(1)
   {  if(select==0)
      {  GUI_Button_OK1(72,29);     // 选中"OK"按钮
         GUI_Button_Cancle(72,45);  // 取消"CANSEL"按钮的选中状态
      }
      else
      {  GUI_Button_OK(72,29);
         GUI_Button_Cancle1(72,45);
      }
      
      key = OSMboxPend(KeyMbox, 0, &err);
           
      if( ((int)key==KEY_LEFT)||
          ((int)key==KEY_RIGHT) ) 
      { select = 1- select;
      }
      
      if((int)key==KEY_OK)
      {  GUI_WindowsHide(&message); // 清除窗口显示
         return;
      }
   }
}


/***************************************************************************
* 名称: MenuIcoInit()
* 功能: 初始化mainmenu结构数组。即初始化各图标变量的成员,如图标
*       图形点阵数据指针,图标标题点阵数据指针,相应的功能函数等等。
* 入口参数: 无
* 出口参数: 无
****************************************************************************/
void  MenuIcoInit(void)
{   int  i;
    extern uint8 *pic_all[][2];	// 图标资源(pic1--pic8)
        
    for(i=0; i<8; i++)
    {   /* 初始化为末选中状态 */
        mainmenu[i].state = 0;	
        
        /* 连接相应的图标数据 */
        mainmenu[i].icodat = (uint8 *) pic_all[i][0];
        mainmenu[i].title = (uint8 *) pic_all[i][1];
        
    }
        /* 连接菜单功能函数 */
        mainmenu[0].Function = ( void(*) (void) ) DemoMessage_0; 
        mainmenu[1].Function = ( void(*) (void) ) DemoMessage_1;
        mainmenu[2].Function = ( void(*) (void) ) DemoMessage;
        mainmenu[3].Function = ( void(*) (void) ) DemoMessage; 
        mainmenu[4].Function = ( void(*) (void) ) DemoMessage;
        mainmenu[5].Function = ( void(*) (void) ) DemoMessage;
        mainmenu[6].Function = ( void(*) (void) ) DemoMessage;
        mainmenu[7].Function = ( void(*) (void) ) DemoMessage;
       
       
}

/*****************************************************************************************************
**                            Task0 任务0
** 功能:使用ZLG/GUI实现图标菜单演示。在LCD屏幕上显示图标菜单,
**       通过KEY2、KEY3按键选择菜单,通过KEY4按键确定选择。
** 说明:请将EasyARM2131开发板上的P0.17、P0.18、P0.19跳线器短
**       接到"KEY2"、"KEY3"、"KEY4"端。
*****************************************************************************************************/
void  Task0(void *pdata)
{   uint8  select;

	pdata = pdata;
	TargetInit ();
	OSTaskCreate (Task1,(void *)0, &TaskStk1[TaskStkLengh - 1], 2);
	    
    /* 初始化ZLG/GUI */
    GUI_Initialize();
    GUI_SetColor(1, 0);
    
    /* 采样程序(及ADC转化)初始化 */
    ADC_Init();                          
    
    /* 实时时钟初始化 */
    RTCInit();

    /* 图标菜单初始化 */
    MenuIcoInit();
    
    /* 显示窗口 */
    DrawMainWindow();
    
    /* 循环调用图标菜单操作,并执行相应功能 */
    while(1)
    {  
       DrawMainWindow();
       select = SelectMenuIco();   // 选择菜单
    
       if(select<8) 
       {    (*mainmenu[select].Function)();     // 执行功能
       }
       OSTimeDly(1);
    }
}


/* 按键对应的I/O定义(P0口) */
#define  IO_KEY2        (1<<17)
#define  IO_KEY3        (1<<18)
#define  IO_KEY4        (1<<19)
#define  IO_KEYALL      (IO_KEY2 | IO_KEY3 | IO_KEY4)
/*********************************************************************************************************
**                            Task1 任务1
** 功能: 等待一个按键,然后发送按键消息。具有去抖动功能和按键超时退出功能。
** 说明:按键和键值的对应关系如下
**       KEY2   --------   KEY_LEFT
**       KEY3   --------   KEY_RIGHT
**       KEY3   --------   KEY_OK
********************************************************************************************************/
void  Task1(void *pdata)
{   uint32  i;
    uint32  io_dat;
    uint8   key;
    
    pdata = pdata;
    
    while(1)
    {   if((IO0PIN&IO_KEYALL) != IO_KEYALL) // 判断是否有按键
        {   OSTimeDly(2);                   // 检测到有按键,延时去抖动
        
            io_dat = IO0PIN;
            if((io_dat&IO_KEYALL) != IO_KEYALL)     // 真的有按键
            {   if((io_dat&IO_KEY2) == 0) key = KEY_LEFT;
                if((io_dat&IO_KEY3) == 0) key = KEY_RIGHT;
                if((io_dat&IO_KEY4) == 0) key = KEY_OK;
                
                /* 等待按键放开(具有超时退出功能) */
                for(i=0; i<10000000; i++)
                {   if((IO0PIN&IO_KEYALL) == IO_KEYALL) break; 
                }
                                
                OSMboxPost(KeyMbox, (void *)key);   // 发送按键消息
            }// end of if((io_dat&IO_KEYALL) != IO_KEYALL)...
        } // end of if((IO0PIN&IO_KEYALL) != IO_KEYALL)... 
        
        /* 无按键,短延时 */
        OSTimeDly(10);
        
    } // end of while(1)...
} 



/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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