發表文章

目前顯示的是 10月, 2009的文章

C8051F340 UART0/1 用法!

UART 的 RX 如果不用 interrupt 收資料,等於沒用。 要如何使用呢??有兩種方法。 1)Flag volatile bit TI0_proxy = 1; void UART0_ISR( void ) interrupt 4 { if ( TI0 == 1 ) { // set the proxy when TI0 is set TI0 = 0; TI0_proxy = 1; } if ( RI0 == 1 ) { RI0 = 0; ... } } unsigned char putchar( unsigned char ch ) { while ( TI0_proxy == 0 ); TI0_proxy = 0; return (SBUF0 = ch); } 真是簡單的方法!當然效能差。重點是簡單。 2)Ring Buffer 效能好。 相對麻煩。不過也沒那麼複雜。 Sample code 比較多。上網參考囉。 http://www.cygnal.org/ubb/Forum5/HTML/000497.html http://www.8052.com/codelib

在 Win32 下 Serial Port 的通訊

在 Win32 下 Serial Port 的通訊 以下的東西是我在閱讀 "Communications Programming for Windows 95" 時做的一點 筆記, 所以在 topic 上大致上都和這書上的第三章一樣. 一些 structure 和 API 的 宣告都是 copy from VC 5.0 的 on-line help. 這些東西主要談的是如何在 Win32 的平台下對 serial port 的通訊. 可能可以帶來 幫助的是那些了解 serial port 的通訊, 但是不清楚在 Win32 平台究竟有那些 API 可用的 programer (就像我? :p) 我只是做做整理罷了, 更清楚的內容可能要再翻翻 on-line help 或是書本. 如果你要嘗試在 Win32 下做像是對 modem 做控制(例如撥 號, 通訊)的程式, 但是對於 serial port 並不了解, 那你應該再去找一本有講到這 些東西的書看看. 開啟一個 Serial Port 利用一般開啟檔案的 CreatFile() 即可開啟 serial port device HANDLE CreateFile( LPCTSTR lpFileName, // pointer to name of the file DWORD dwDesiredAccess, // access (read-write) mode TES lpSecurityAttributes, // poin DWORD dwShareMode, // share mode LPSECURITY_ATTRIB Uter to security attributes DWORD dwCreationDistribution, // how to create e to file with attributes to copy ); DWORD dwFlagsAndAttributes, // file attributes HANDLE hTemplateFile // hand l 用 CreateFile() API. lpFileName 為 "COM1" 或是 "COM2" dwDersiredAccess 一般為 GENER

MFC: UpdateData()

MFC: UpdateData() Posted on 一月 27, 2008 by brain ㄧ直都知道 UpdateData() 的使用時機是用於更新資料時… 當需要取得 Dialog 上之控制項儲存資料時 使用 UpdateData(TRUE) 來取得… 反之 需要將變數呈現於 Dialog 之控制項時 需要用 UpdateData(FALSE) 但卻不知道 執行 UpdateData() 這動作 用意是去呼叫 ::DoDataExchange(pDx) 這函示的 用 MFC 精靈產生專案時… 會產生類似如下之程式碼 1. void CDDXDemoDlg::DoDataExchange(CDataExchange* pDX) 2. { 3. CDialog::DoDataExchange(pDX); 4. DDX_Text(pDX, IDC_EDIT, num); 5. DDV_MinMaxInt(pDX, num, 1, 20); 6. } 其中 DDX_ 代表 -> Do Data Exchange DDV_ 則代表了 -> Do Data Verification 所以執行 UpdateData(TRUE) 就代表了 IDC_EDIT -> num 的資料交換 而 UpdateData(FALSE) 即代表了 num -> IDC_EDIT 的資料交換動作… 且執行 UpdateData() 動作後會去作類似 DDV_MinMaxInt 的資料基本檢查….