1、单片机与嵌入式系统课程设计 1课程设计的目的1、熟练掌握嵌入式系统的应用2、加强嵌入式的综合运用能力,提高嵌入式的软件编程和调试能力,为以后的学习和开发工作打好良好基础。3、掌握小系统开发设计的流程以及设计思路2.设计方案论证2.1播放器总体结构本文中的播放器采用MiniGUI作为底层图形库,用于生成用户界面以及读写FrameBuffer。基于MiniGUI的嵌入式系统总体架构如图1所示。图1 基于MiniGUI的嵌入式系统总体架构播放器软件总体结构如图2所示,它主要由三部分组成,分别是图形用户界面模块、系统管理主控模块和音/视频解码器。三部分功能设计如下面所述:图形用户界面模块通过事件/消息
2、机制和系统管理主控模块交互。音/视频解码器模块可以看作是系统管理主控模块的插件(plug-in),从系统管理主控模块获得编码的音/视频数据并对其解码后发送己解码的音/视频数据给系统管理主控模块。系统管理主控模块则负责网络数据的接收和解析、图形用户界面模块和音/视频解码器模块的工作协调和音/视频数据的输出。这个模块是播放器软件中非常重要的一个模块。图2 播放器应用程序结构图2.2用户图形界面设计MiniGUI提供了丰富的GUI元素,如常见的控件类、对话框与消息框以及菜单等,此外,MiniGUI支持界面皮肤。因此,利用MiniGUI可以非常方便地设计出漂亮的用户图形界面。播放器的人机交互界面主要包
3、括播放控制与文件列表管理两大部分。播放控制用来实现对所选择的媒体文件作播放/暂停、停止及进度控制等;文件列表管理则用来实现向播放列表添加、删除媒体文件以及对列表中文件排序等功能。3.设计的过程与分析#include time.h#include ; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #inc
4、lude #include #define IDL_DEL_DIR 818#define IDL_DEL_FILE 819#define IDC_DEL_PATH 820char fpath100;char path100;char mypath100;char files 1024 = 你选择要播放的文件是:n;static DLGTEMPLATE DlgDelFiles = WS_BORDER | WS_CAPTION, WS_EX_NONE, 0, 0,320, 213, 资源管理器, 0, 0, 7, NULL, 0;static CTRLDATA CtrlDelFiles = CTR
5、L_STATIC, WS_VISIBLE | SS_SIMPLE, 10, 10, 130, 15, IDC_STATIC, 目录列表, 0 , CTRL_LISTBOX, WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_NOTIFY, 10, 30, 130, 80, IDL_DEL_DIR, , 0 , CTRL_STATIC, WS_VISIBLE | SS_SIMPLE, 150, 10, 130, 15, IDC_STATIC, 文件列表, 0 , CTRL_LISTBOX, WS_VISIBLE | WS_VSCROLL |
6、 WS_BORDER | LBS_SORT | LBS_AUTOCHECKBOX, 150, 30, 130, 80, IDL_DEL_FILE, , 0 , CTRL_STATIC, WS_VISIBLE | SS_SIMPLE, 10, 130, 290, 15, IDC_DEL_PATH, 路径:, 0 , button, WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP, 10, 150, 130, 25, IDOK, 确定, 0 , button, WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP
7、, 150, 150, 130, 25, IDCANCEL, 取消, 0 ,;static void fill_boxes (HWND hDlg, const char* path)#ifdef _ECOS_ LISTBOXITEMINFO lbii; lbii.string = file.1; lbii.cmFlag = CMFLAG_BLANK; lbii.hIcon = 0; SendDlgItemMessage (hDlg, IDL_DEL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii); lbii.string = file.2; SendDlgItemM
8、essage (hDlg, IDL_DEL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii); lbii.string = file.3; SendDlgItemMessage (hDlg, IDL_DEL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii);#else struct dirent* dir_ent; DIR* dir; struct stat ftype; char fullpath PATH_MAX + 1; SendDlgItemMessage (hDlg, IDL_DEL_DIR, LB_RESETCONTENT, 0,
9、 (LPARAM)0); SendDlgItemMessage (hDlg, IDL_DEL_FILE, LB_RESETCONTENT, 0, (LPARAM)0); SetWindowText (GetDlgItem (hDlg, IDC_DEL_PATH), path); if (dir = opendir (path) = NULL) return; while ( (dir_ent = readdir ( dir ) != NULL ) /* Assemble full path name. */ strncpy (fullpath, path, PATH_MAX); strcat
10、(fullpath, /); strcat (fullpath, dir_ent-d_name); if (stat (fullpath, &ftype) d_name); else if (S_ISREG (ftype.st_mode) LISTBOXITEMINFO lbii;lbii.string = dir_ent-d_name; lbii.cmFlag = CMFLAG_BLANK; lbii.hIcon = 0; SendDlgItemMessage (hDlg, IDL_DEL_FILE, LB_ADDSTRING, 0, (LPARAM)&lbii); closedir (di
11、r);#endif void dir_notif_proc (HWND hwnd, int id, int nc, DWORD add_data) if (nc = LBN_CLICKED | nc = LBN_ENTER) int cur_sel = SendMessage (hwnd, LB_GETCURSEL, 0, 0L); if (cur_sel = 0) char cwd MAX_PATH + 1; char dir MAX_NAME + 1; GetWindowText (GetDlgItem (GetParent (hwnd), IDC_DEL_PATH), cwd, MAX_
12、PATH); SendMessage (hwnd, LB_GETTEXT, cur_sel, (LPARAM)dir);if (strcmp (dir, .) = 0) return; strcat (cwd, /); strcat (cwd, dir); fill_boxes (GetParent (hwnd), cwd); static void file_notif_proc (HWND hwnd, int id, int nc, DWORD add_data) /* Do nothing */static void prompt (HWND hDlg) int i; GetWindow
13、Text(GetDlgItem (hDlg, IDC_DEL_PATH),path,MAX_PATH); strcat(path,/); for (i = 0; i SendDlgItemMessage (hDlg, IDL_DEL_FILE, LB_GETCOUNT, 0, 0L); i+) char file MAX_NAME + 1; int status = SendDlgItemMessage (hDlg, IDL_DEL_FILE, LB_GETCHECKMARK, i, 0); if (status = CMFLAG_CHECKED) SendDlgItemMessage (hD
14、lg, IDL_DEL_FILE, LB_GETTEXT, i, (LPARAM)file); strcat(fpath,file); strcat(path,fpath); strcat (files, file); strcat (files, n); printf(%sn,path); /strcpy(path,); strcpy(fpath,); strcpy(file,); strcpy(fpath,); strcpy(file,); strcpy(mypath,path); MessageBox (hDlg, files, 提示, MB_OK); strcpy(files,你选择要
15、播放的文件是:n);static int DelFilesBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam) switch (message) case MSG_INITDIALOG: char cwd MAX_PATH + 1; SetNotificationCallback (GetDlgItem (hDlg, IDL_DEL_DIR), dir_notif_proc); SetNotificationCallback (GetDlgItem (hDlg, IDL_DEL_FILE), file_notif_proc
16、); fill_boxes (hDlg, getcwd (cwd, MAX_PATH); return 1; case MSG_COMMAND: switch (wParam) case IDOK: prompt (hDlg); /strcpy(path,); EndDialog (hDlg, wParam);break; case IDCANCEL: EndDialog (hDlg, wParam); break; break; return DefaultDialogProc (hDlg, message, wParam, lParam);int recorddelfile(HWND hW
17、nd)#ifdef _LITE_VERSION SetDesktopRect(0, 0, 1024, 768);#endif DlgDelFiles.controls = CtrlDelFiles; DialogBoxIndirectParam (&DlgDelFiles, hWnd, DelFilesBoxProc, 0L); return 0;#include #include #include #include #include #include #include #include #include #include #define IDC_PLAY_LIST310#define IDC
18、_PLAY_FILE320#define IDC_PLAY_PLAY330#define IDC_PLAY_KA340#define IDC_PLAY_STOP350#define IDC_PLAY_CAN360BITMAP bmp;extern mypath100;static DLGTEMPLATE DlgInitProgressMplayerMain = WS_BORDER | WS_CAPTION, WS_EX_NONE, 0,0,320,240, 媒体播放器, 0, 0, 6, NULL, 0;static CTRLDATA CtrlInitProgressMplayerMain =
19、CTRL_LISTBOX,WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_NOTIFY,5, 15, 240, 185,IDC_PLAY_LIST,0, button, WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON, 260,20,50,30, IDC_PLAY_FILE, 打开, 0 , button, WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON, 260,60,50,30, IDC_PLAY_PLAY, 播放, 0 , button, WS_TABST
20、OP | WS_VISIBLE | BS_DEFPUSHBUTTON, 260,100,50,30, IDC_PLAY_KA, 暂停, 0 , button, WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON, 260,140,50,30, IDC_PLAY_STOP, 停止, 0 , button, WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON, 260,180,50,30, IDC_PLAY_CAN, 返回, 0 ;static int InitDialogBoxProc (HWND hDlg, int messa
21、ge, WPARAM wParam, LPARAM lParam) static int flag=0; int choise=0; static FILEDLGDATA filepathdata = FALSE, ., , .; char command200; HDC hdc; RECT rc; RECT rcTemp; const RECT* clip = (const RECT*) lParam; BOOL fGetDC = FALSE; hdc = (HDC)wParam; switch(message) case MSG_CREATE: /* if(LoadBitmap(HDC_S
22、CREEN,&bmp,./bb4.jpg) return -1; break; case MSG_PAINT: hdc=BeginPaint(hDlg); EndPaint(hDlg,hdc); return 0; case MSG_ERASEBKGND:if (hdc = 0)hdc = GetClientDC (hDlg);fGetDC = TRUE; if (clip) rcTemp = *clip;ScreenToClient (hDlg, &rcTemp.left, &rcTemp.top);ScreenToClient (hDlg, &rcTemp.right, &rcTemp.b
23、ottom);IncludeClipRect (hdc, &rcTemp); FillBoxWithBitmap (hdc, 0, 0, 0, 0, &bmp);if (fGetDC)ReleaseDC (hdc);return 0; */ case MSG_INITDIALOG: break; case MSG_COMMAND: switch (wParam) case IDC_PLAY_FILE: recorddelfile(hDlg); break; case IDC_PLAY_PLAY: if(flag=0) printf(%sn,mypath); sprintf(command,./
24、mplayer %s &,mypath); flag=1; system(command); printf(singing MP3n); printf(%dn,flag); break; case IDC_PLAY_STOP: system(killall mplayer); flag=0; break; case IDC_PLAY_CAN: EndDialog (hDlg, wParam); break; case IDC_PLAY_KA: if(flag=0) sprintf(command,./mplayer %s &,mypath); flag=1; system(command);
25、printf(singing MP4n); break; break;case MSG_CLOSE:DestroyAllControls(hDlg);PostQuitMessage(hDlg);return 0; return DefaultDialogProc (hDlg, message, wParam, lParam);void InitDialogBoxMplayerMain(HWND hWnd) DlgInitProgressMplayerMain.controls = CtrlInitProgressMplayerMain; DialogBoxIndirectParam (&Dlg
26、InitProgressMplayerMain, hWnd, InitDialogBoxProc, 0L);int MiniGUIMain (int argc, const char* argv) InitDialogBoxMplayerMain(HWND_DESKTOP); return 0;4设计体会单片机与嵌入式系统这门课程很好地培养了我们综合运用所学知识,发现提出分析和解决实际问题,锻炼实践能力。仅学习书本上的知识是很难学好单片机与嵌入式系统这门课程的,我们必须还要有较强的实践能力,要多编写程序。在代码实现阶段运行自己设计的算法以后发现有错误,自己调试了半天还是不行,最终还是和同学一起
27、探讨才得以解决的。本次课程设计让我更感受到单片机与嵌入式系统这门课程所具有的特点,明白了单片机和嵌入式系统在将来的发展中占据着重要的作用,也明白了学好这门课的重要性。在实际操作中,我获得了很大的收获,首先这门课程让我对linux的操作更加熟练,让我的编程与调试的能力得到一个提升,再者这门课程让我对单片机与嵌入式系统这门课程有了一个不一样的认识,让我在编程与调试过程中感受到了这门课程所带来的魅力,也让我对此产生浓厚的兴趣。在课程设计过程中,一旦有自己难以解决的问题后,我们会虚心向自己的伙伴请教,这让我感受到了团结互助和良好的氛围的重要性。在设计过程中也了解了很多专业术语,使得自己的专业词汇不断充实。5参考文献1 吴士力,刘奇,朱兰. 嵌入式Linux应用开发全程解析与实战M.北京:机械工业出版社,2010.1:231-3002 李超,肖建. 嵌入Linux应用开发完全手册M.北京:电子工业出版社,2008.5:214-3563 郑峰等. 51单片机典型应用开发范例大全 M.北京:中国铁道出版社,2011.10:371-576