新手入门
积分 12
金钱 12
注册时间 2017-6-12
在线时间 3 小时
1 金钱
我用原子哥的基础不带UCOS的例程写了一个显示曲线的程序,在调用GRAPH_DATA_YT_SetAlign后如果设置成RIGHT的话曲线刷新很慢,但如果设置成LEFT的话,曲线刷新变快,
如果数据达到GRAPH_DATA_YT_Create中设置MaxNumItems的最大的时候,刷新也会变慢
这是曲线的程序
#include <stdlib.h>
#include <string.h>
#include "DIALOG.h"
#include "GRAPH.h"
#include "adc.h"
#include "led.h"
static GRAPH_SCALE_Handle _hScaleV; // Handle of vertical scale
static GRAPH_SCALE_Handle _hScaleH; // Handle of horizontal scale
GRAPH_DATA_Handle ahdata;
static int _Stop = 1;
static GUI_COLOR _aColor[] = {GUI_RED, GUI_GREEN, GUI_LIGHTBLUE}; // Array of colors for the GRAPH_DATA objects
//
// Dialog ressource
//
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "Graph widget demo", 0 , 0, 0, 800, 480, FRAMEWIN_CF_MOVEABLE },
{ GRAPH_CreateIndirect, 0, GUI_ID_GRAPH0 , 12, 10, 700, 430 },
/**********************BUTTON---STOP***************/
{ BUTTON_CreateIndirect, "START", GUI_ID_BUTTON2, 722, 50, 65, 50, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "STOP", GUI_ID_BUTTON1, 722, 150, 65, 50, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Screen", GUI_ID_BUTTON0 , 722, 250, 65, 50 },
/******????******************************/
{ BUTTON_CreateIndirect, 0, GUI_ID_BUTTON3 , 50,440, 52, 20 },
{ BUTTON_CreateIndirect, 0, GUI_ID_BUTTON4 , 170, 440, 52, 20 },
{ BUTTON_CreateIndirect, 0, GUI_ID_BUTTON5 , 290, 440, 52, 20 },
{ BUTTON_CreateIndirect, 0, GUI_ID_BUTTON6 , 410, 440, 52, 20 },
{ BUTTON_CreateIndirect, 0, GUI_ID_BUTTON7 , 530, 440, 52, 20 },
{ BUTTON_CreateIndirect, 0, GUI_ID_BUTTON8 , 650, 440, 52, 20 },
/*******GUON ??****************/
{ CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK6 , 725, 350, 300, 0 ,0,0},
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _AddValues
*
* Function description
* This routine calculates new random values in dependence of the previous added values
* and adds them to the GRAPH_DATA objects
*/
/*********************************************************************
*
* _UserDraw
*
* Function description
* This routine is called by the GRAPH object before anything is drawn
* and after the last drawing operation.
*/
/*********************************************************************
*
* _ForEach
*
* Function description
* This routine hides/shows all windows except the button, graph and scroll bar widgets
*/
static void _ForEach(WM_HWIN hWin, void * pData) {
int Id;
int FullScreenMode;
FullScreenMode = *(int *)pData;
Id = WM_GetId(hWin);
if ((Id == GUI_ID_GRAPH0) || (Id == GUI_ID_BUTTON0) || (Id == GUI_ID_VSCROLL) || (Id == GUI_ID_HSCROLL)) {
return;
}
if (FullScreenMode) {
WM_HideWindow(hWin);
} else {
WM_ShowWindow(hWin);
}
}
/*********************************************************************
*
* _ToggleFullScreenMode
*
* Function description
* This routine switches between full screen mode and normal mode by hiding or showing the
* widgets of the dialog, enlarging/shrinking the graph widget and modifying some other
* attributes of the dialog widgets.
*/
static void _ToggleFullScreenMode(WM_HWIN hDlg) {
static int FullScreenMode;
static GUI_RECT Rect;
static unsigned ScalePos;
WM_HWIN hGraph;
WM_HWIN hButton;
WM_HWIN hClient;
GUI_RECT RectInside;
int xPos, yPos;
hGraph = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0);
hButton = WM_GetDialogItem(hDlg, GUI_ID_BUTTON0);
FullScreenMode ^= 1;
if (FullScreenMode) {
//
// Enter the full screen mode
//
hClient = WM_GetClientWindow(hDlg);
BUTTON_SetText(hButton, "Back");
WM_MoveWindow(hButton, 0, 11);
FRAMEWIN_SetTitleVis(hDlg, 0);
WM_GetInsideRectEx(hClient, &RectInside);
WM_GetWindowRectEx(hGraph, &Rect);
WM_ForEachDesc(hClient, _ForEach, &FullScreenMode); // Hide all descendants
xPos = WM_GetWindowOrgX(hClient);
yPos = WM_GetWindowOrgY(hClient);
WM_SetWindowPos(hGraph, xPos, yPos, RectInside.x1, RectInside.y1);
ScalePos = GRAPH_SCALE_SetPos(_hScaleH, RectInside.y1 - 20);
} else {
//
// Return to normal mode
//
BUTTON_SetText(hButton, "Screen");
WM_MoveWindow(hButton, 0, -11);
WM_ForEachDesc(WM_GetClientWindow(hDlg), _ForEach, &FullScreenMode); // Show all descendants
WM_SetWindowPos(hGraph, Rect.x0, Rect.y0, Rect.x1 - Rect.x0 + 1, Rect.y1 - Rect.y0 + 1);
FRAMEWIN_SetTitleVis(hDlg, 1);
GRAPH_SCALE_SetPos(_hScaleH, ScalePos);
}
}
/*********************************************************************
*
* _cbCallback
*
* Function description
* Callback function of the dialog
*/
static void _cbCallback(WM_MESSAGE * pMsg) {
int NCode;
int Id;
WM_HWIN hDlg;
WM_HWIN hItem;
hDlg = pMsg->hWin;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
hItem = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0);
//
// Add graphs
GRAPH_SetGridDistY(hItem, 25);
GRAPH_SetGridVis(hItem, 1);
GRAPH_SetGridFixedX(hItem, 1);
//
// Create and add vertical scale
//
_hScaleV = GRAPH_SCALE_Create( 35, GUI_TA_RIGHT, GRAPH_SCALE_CF_VERTICAL, 25);
GRAPH_SCALE_SetTextColor(_hScaleV, GUI_YELLOW);
GRAPH_AttachScale(hItem, _hScaleV);
//
// Create and add horizontal scale
//
_hScaleH = GRAPH_SCALE_Create(400, GUI_TA_HCENTER, GRAPH_SCALE_CF_HORIZONTAL, 50);
GRAPH_SCALE_SetTextColor(_hScaleH, GUI_DARKGREEN);
GRAPH_AttachScale(hItem, _hScaleH);
ahdata=GRAPH_DATA_YT_Create(GUI_RED,1000,0,0);
GRAPH_AttachData(hItem, ahdata);
GRAPH_DATA_YT_MirrorX(ahdata, 1);
GRAPH_DATA_YT_SetAlign(ahdata, GRAPH_ALIGN_LEFT);
GRAPH_SetVSizeX(hItem, 1000);
hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK6);
CHECKBOX_SetText(hItem, "HScroll");
CHECKBOX_SetState(hItem, 1);
// hObj = BUTTON_Create(725,370, 52, 20 ,GUI_ID_BUTTON3 ,WM_CF_SHOW);
hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_BUTTON3);
BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
BUTTON_SetTextColor(hItem,BUTTON_CI_UNPRESSED,GUI_RED);
BUTTON_SetText(hItem, "LED1");
hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_BUTTON4);
BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
BUTTON_SetTextColor(hItem,BUTTON_CI_UNPRESSED,GUI_RED);
BUTTON_SetText(hItem, "LED1");
hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_BUTTON5);
BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
BUTTON_SetTextColor(hItem,BUTTON_CI_UNPRESSED,GUI_RED);
BUTTON_SetText(hItem, "LED1");
hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_BUTTON6);
BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
BUTTON_SetTextColor(hItem,BUTTON_CI_UNPRESSED,GUI_RED);
BUTTON_SetText(hItem, "LED1");
hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_BUTTON7);
BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
BUTTON_SetTextColor(hItem,BUTTON_CI_UNPRESSED,GUI_RED);
BUTTON_SetText(hItem, "LED1");
hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_BUTTON8);
BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
BUTTON_SetTextColor(hItem,BUTTON_CI_UNPRESSED,GUI_RED);
BUTTON_SetText(hItem, "LED1");
// BUTTON_SetBkColor(hObj, BUTTON_CI_UNPRESSED,GUI_RED);
/************GUI_RECT rClient;
GUI_GetClientRect(&rClient);
GUI_DispStringInRect("Text", &rClient, GUI_TA_HCENTER | GUI_TA_VCENTER);*/
break;
/************************************************************************/
/************************************************************************
***********************************************************************/
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc); // Id of widget
NCode = pMsg->Data.v;
/***************************************BUTTON********************************/
/***************************************BUTTON********************************/
/***************************************BUTTON********************************/
/***************************************BUTTON********************************/
/***************************************BUTTON********************************/
switch(Id)
{
case GUI_ID_BUTTON1: // Notifications sent by 'Button'
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
_Stop = 1;
break;
}
break;
case GUI_ID_BUTTON2: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
_Stop = 0;
break;
}
break;
}
/***************************************BUTTON----OVER********************************/
/***************************************BUTTON----OVER********************************/
/***************************************BUTTON----OVER********************************/
/***************************************BUTTON----OVER********************************/
/***************************************BUTTON----OVER********************************/
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
switch (Id) {
case GUI_ID_BUTTON0:
_ToggleFullScreenMode(hDlg);
break;
}
break;
case WM_NOTIFICATION_VALUE_CHANGED:
switch (Id) {
case GUI_ID_CHECK6:
hItem = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0);
if (CHECKBOX_IsChecked(WM_GetDialogItem(hDlg, GUI_ID_CHECK6))) {
GRAPH_SetVSizeX(hItem, 2500);
} else {
GRAPH_SetVSizeX(hItem, 0);
}
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
//u16 i;
//u16 adcx;
//float temp;
//void disp()
//{
// adcx=Get_Adc_Average(ADC_Channel_1,2);
// temp=(float)adcx*(3.3/4096);
// adcx=temp*100;
//
//
// GRAPH_DATA_YT_AddValue(ahdata,adcx);
//
//}
extern u16 flag;
u16 ss;
void inTask(void) {
WM_HWIN hDlg;
WM_HWIN hGraph;
hGraph = 0;
LED1 = 0;
GUI_Init();
// GUI_CURSOR_Show();
WM_SetDesktopColor(GUI_GRAY);
#if GUI_SUPPORT_MEMDEV
WM_SetCreateFlags(WM_CF_MEMDEV);
#endif
hDlg = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbCallback, 0, 0, 0);
LED1 = ~LED1;
while (1) {
GRAPH_DATA_YT_AddValue(ahdata,flag);
LED1 = ~LED1;
//
GUI_Delay(1);
LED0 = ~LED0;
//
// if (!_Stop) {
// if (!hGraph) {
// hGraph = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0);
// }
// }
// GUI_Exec();
// disp();
}
}
/*************************** End of file ****************************/
这是定时器读取AD的值的程序
void TIM4_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);//¿aÆôTIM3ê±Öó
TIM_TimeBaseInitStructure.TIM_Prescaler=psc; //·ÖÆμÖμ
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //¼ÆêyÄ£ê½
TIM_TimeBaseInitStructure.TIM_Period=arr; //×Ô¶ˉÖØ×°êyÖμ
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1; //éèÖÃê±Öó·Ö¸î
TIM_TimeBaseInit(TIM4,&TIM_TimeBaseInitStructure);
TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);//ÔêDí¸üDÂÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannel=TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM4,ENABLE); //ê1ÄüTIM3
}
u16 i;
u16 adcx;
float temp;
u16 flag;
u8 a;
void TIM4_IRQHandler(void)
{
if(TIM_GetITStatus(TIM4,TIM_IT_Update)!=RESET)
{
adcx=Get_Adc_Average(ADC_Channel_1,2);
temp=(float)adcx*(3.3/4096);
flag=temp*100;
// GRAPH_DATA_YT_AddValue(ahdata,adcx);
// if(a)
// flag--;
// else
// flag++;
// if(flag >= 450)
// a = 1;
// if(flag <= 1)
// a = 0;
}
TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
}
各位大神们帮我看看吧,这个程序搞了一个多星期了,最后卡到这里来了
实正是没办法了
我来回答