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

📄 main.c

📁 在proteus仿真arm处理器
💻 C
📖 第 1 页 / 共 5 页
字号:
		GUI_PutString(20, 60, "Tip:");
		GUI_PutString(20, 70, "Measure the AD Value"); 
		GUI_PutString(20, 80, "Press The Q Button To Quit"); 
	}  
	F_flag = 0x01;
	//Function   
	ADC_Data = ADDR;
	ADCR = (ADCR&0x00FFFF00)|0x01|(1 << 24);	// 设置通道1,并进行第一次转换
	while( (ADDR&0x80000000)==0 );  	        // 等待转换结束
	ADCR = ADCR | (1 << 24);					// 再次启运转换
	while( (ADDR&0x80000000)==0 );  	        // 等待转换结束
	ADC_Data = ADDR;							// 读取ADC结果
	ADC_Data = (ADC_Data>>6) & 0x3FF;           // 提取AD转换值
	ADC_Data = ADC_Data * 3300/1024;            // 数值转换
	
	sprintf(str, "VIN0=%dmV \r", ADC_Data);		// 显示
	GUI_PutString(20,45,str);
}
/*********************************************************************************************************
** 函数名称: Function_2_I2C()
** 功能描述: I2C功能测试
** 输 入: 无 
** 输 出: 无       
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by    Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#define	CAT24WC01 0xA0
#define	CAT24WC02 0xA2
void	Function_2_I2C(void)
{
	uint8  i;
	uint8	x,y,num;
	uint8  data_buf[30];
	x=15;
	y=23;
	num = 16;
	if((F_flag&0x02)==0)
	{
		//I2C_Init(300000);
		GUI_PutString(x, y,      "Write Data To  CAT24C01,Address 0x00"); 
		GUI_PutString(x, y+12*2, "Read Data from CAT24C01,Address 0x00"); 
		GUI_PutString(x, y+12*4, "Write Data To  CAT24C02,Address 0x20");  
		GUI_PutString(x, y+12*6, "Read Data from CAT24C02,Address 0x20");	
	//Write data to CAT24WC01
	x = x + 40;
	for (i=0;i<num;i++)data_buf[i]=i+'0';
	I2CSendString(CAT24WC01,0x00,data_buf,num);
	for(i=0;i<num;i++)GUI_PutChar(x+i*8,y+12,data_buf[i]);
	//Read data from CAT24WC01
	for (i=0;i<num;i++)data_buf[i]=0x00;
	I2CRcvString(CAT24WC01,0x00,data_buf,num);
	for(i=0;i<num;i++)GUI_PutChar(x+i*8,y+12*3,data_buf[i]);
	 
	//Write data to CAT24WC02
	for (i=0;i<num;i++)data_buf[i]=i+'a';
	I2CSendString(CAT24WC02,0x20,data_buf,num);
	for(i=0;i<num;i++)GUI_PutChar(x+i*8,y+12*5,data_buf[i]);
	//Read data from CAT24WC02
	for (i=0;i<num;i++)data_buf[i]=0x00;
	I2CRcvString(CAT24WC02,0x20,data_buf,num);
	for(i=0;i<num;i++)GUI_PutChar(x+i*8,y+12*7,data_buf[i]);
	}
	F_flag = 0x02; 
}
/*********************************************************************************************************
** 函数名称: Function_3_Win()
** 功能描述: ZLG/GUI测试
** 输 入: 无 
** 输 出: 无       
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by    Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
// 样条曲线的4个端点
PointXY log_pin[] = { 
                      {135, 25},
                      {75,  46},
                      {135, 60},
                      {75,  75},
                      {135, 95}
                    };
// 封闭多边形的各个顶点                    
uint32  const poly6[] = {150,100, 170,30, 180,75, 200,45, 230,90, 150,100};                    
void  Function_3_Win(void)
{  
   WINDOWS  message;
   uint8	keycode;
   static uint8	select;
   uint8	i;
   extern uint8	*title1[15];
   if((F_flag&0x04)==0)
   {
   message.x = 20;       					// 设置窗口位置和大小
   message.y = 30;
   message.with = 120;
   message.hight = 85;
   message.title = (uint8 *) "Demo Message"; // 窗口标题
   message.state = (uint8 *) "Status Bar";
   GUI_WindowsDraw(&message);       		// 显示对话框窗口
   GUI_PutString(28, 45, "Hello,World!");   // 显示对话框的消息
   GUI_PutString(28, 60, "Press The Button");
   for(i=0;i<7;i++)
   GUI_PutHZ(145+10*i, 30, (uint8 *)title1[i],8, 16);	 // 0-6
   for(i=0;i<=3;i++)
   GUI_PutHZ(145+18*i, 50, (uint8 *)title1[i+7],16, 16); // 7-10
   for(i=0;i<=3;i++)
   GUI_PutHZ(145+18*i, 70, (uint8 *)title1[i+11],16, 16);// 11-14
   GUI_Button_OK1(23,80);     					// 选中"OK"按钮
   GUI_Button_Cancle(85,80);  					// 取消"CANSEL"按钮的选中状态
   select= 0x00;			  				    // 选中"OK"按钮
   }
   F_flag = 0x04;
   		keycode = Keyboard_Scan();
   		switch(keycode)
   		{
   			case	0x0e:
   			case	0x0f:
   				select = (~select)&0x01;
   				if(select)
				{
					GUI_Button_OK(23,80);      // 取消"OK"按钮
   					GUI_Button_Cancle1(85,80); // 选中"CANSEL"按钮的选中状态
				}
				else
				{
					GUI_Button_OK1(23,80);     // 选中"OK"按钮的选中状态
   					GUI_Button_Cancle(85,80);  // 取消"CANSEL"按钮的选中状态
				}
			break;		
			case	0x0a:
				if(!select){
				   GUI_Spline(log_pin, 5, 1);  // 画样条曲线
				   GUI_LineS(poly6, 6, 1);     // 画封闭的多边形
				}
				else{
				   keycode = 0x0b;
				}
			break;
			default:
				break;
   		}
   		KeyDecode(keycode);
   }
/*********************************************************************************************************
** 函数名称: Function_4_UART0()
** 功能描述: UART0功能测试
** 输 入: 无 
** 输 出: 无       
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by    Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#define CMD_FLAG   0x00
#define DATA_FLAG  0x01
#define SPACE_FLAG 0x02
#define WRONG_FLAG 0x03
void	Function_4_UART(void)
{
	uint8 rcvdata,i;
	uint8	x=15,y=23;
	static uint8 buffer_index;
	static uint8 flag ;
	if((F_flag&0x08)==0)
    {
	    GUI_PutString(x, y,     "Testing the UART0"); 
	    GUI_PutString(x, y+12,  "Send and Receive Data.");
	    GUI_PutString(x, y+12*2,"Please Open the Virtual Terminal.");
	    GUI_PutString(x, y+12*3,"Press Enter to Execute.");
	    UartSendChar(0x0d);
	    UartSendString("Ready\r\n\\> ");
	    buffer_index = 0;
	    flag = CMD_FLAG;
	}
	F_flag  = 0x08; 
	rcvdata = UART0Getch();
	//UartSendChar(rcvdata);
	switch(rcvdata)
	{
	  case 0x08://(BackSpace键);
           if(buffer_index != 0 ){
              buffer_index--;
              UartSendChar(rcvdata);
           }
           //Uart0_Buffer[buffer_index] = '\0';
	  break;
	  case 0x0d://(Enter键);
	       UartSendChar(rcvdata);
	       //Uart0_Buffer[buffer_index] = '\0';
	       Uart_Data_Decode(flag,buffer_index);
	       flag = CMD_FLAG;
	       buffer_index = 0;
	       for(i=0;i<CmdBufLengh;i++)
	          Cmd_Buf[i] = '\0'; 
	       for(i=0;i<DatBufLengh;i++)
	          Data_Buf[i] = '\0';          
	  break;
	  case 0x20://空格键
	       UartSendChar(rcvdata);
	       if(buffer_index == 0)break;
	       Cmd_Buf[buffer_index] = '\0';
	       buffer_index = 0;
	       flag = SPACE_FLAG; 
	  break;     
	  default://(其他键盘有效键);
	       UartSendChar(rcvdata);
	       if((rcvdata>='A')&&(rcvdata<='Z'))rcvdata =rcvdata + 32;//大写字母变成小写
	       if(flag == CMD_FLAG){//命令输入
	       /*
             if((rcvdata<'a')||(rcvdata>'z')){
               flag =WRONG_FLAG;
               break;
             }
           */  
             Cmd_Buf[buffer_index] = rcvdata;
             buffer_index++;
           }
           if((flag == SPACE_FLAG)||(flag == DATA_FLAG)){//命令的参数输入
            if((buffer_index == 0)&&(rcvdata=='0')){//第一个数据输入不能为0
               break;
             }
           /*  
             if((rcvdata<'0')||(rcvdata>'9')){
                flag =WRONG_FLAG;
                break;   
             }
           */  
             Data_Buf[buffer_index] = rcvdata;
             flag = DATA_FLAG;
             buffer_index++;
           }
	  break;  
	}
}
/*********************************************************************************************************
** 函数名称: Function_5_SPI()
** 功能描述: SPI数据发送功能测试
** 输 入: 无 
** 输 出: 无       
** 全局变量: 无
** 调用模块: 无
**------------------------------------------------------------------------------------------------------
** Created by    Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 const SPI_DISP_TAB[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,
                          0x88,0x83,0xC6,0xA1,0x86,0x8E}; 
void	Function_5_SPI(void)
{
	uint8 keycode;
	uint8	x,y;
	uint8 bak;
	x=15;
	y=23;
	if((F_flag&0x10)==0)
	{
	MSpiIni();
	MSendData(SPI_DISP_TAB[0]);
	GUI_PutString(x, y, "Testing the SPI Function"); 
	GUI_PutString(x, y+12*2,"  No Key Is Pressed.");
	GUI_PutString(x, y+12*7,"Press The Q Button To Quit");	
	}
	F_flag = 0x10;
	keycode = Keyboard_Scan();
	if(keycode != 0xff)
	{
		MSendData(SPI_DISP_TAB[keycode]);
		if(keycode <0x0a)
			bak = keycode + 0x30;
		else
			bak = keycode + 0x37;
		GUI_PutString(x, y+12*2,"0x0 ");

⌨️ 快捷键说明

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