![]() |
|
Tài trợ cho PIC Vietnam |
Giao tiếp cổng COM và LPT RS232, RS485 và LPT là những giao tiếp cơ bản và kinh điển khi mới học về vi điều khiển... |
|
Ðiều Chỉnh | Xếp Bài |
![]() |
#23 |
Đệ tử 1 túi
Tham gia ngày: Mar 2010
Bài gửi: 13
: |
MONG SỰ GIÚP ĐỠ GẤP CỦA MỌI NGƯỜI VỀ RS232 ( MÌNH ĐANG RẤT CẦN )
Mình đang làm một chương trình kết nối cổng RS232 sử dụng visual c++. không hiểu vì sao khi test chương trình thì thấy không truyền xuống PIC6f877a được. chương trình của mình : #include "stdafx.h" #include <windows.h> // kiem tra che do mo cong. TCHAR *pcCommPort = TEXT("COM3"); HANDLE hcom = CreateFile( pcCommPort, GENERIC_READ | GENERIC_WRITE, 0, // must be opened with exclusive-access NULL, // default security attributes OPEN_EXISTING, // must use OPEN_EXISTING 0, // not overlapped I/O NULL // hTemplate must be NULL for comm devices ); // cài đặt trạng thái ban đầu . void Setting() { if (hcom == INVALID_HANDLE_VALUE) { // Handle the error. printf ("CreateFile failed with error %d.\n", GetLastError()); return ; } else { // set timeouts COMMTIMEOUTS cto = { 1, 100, 1000, 0, 0 }; DCB dcb; if(!SetCommTimeouts(hcom,&cto)) printf ("E013_SetCommTimeouts failed\n"); // Thiet lap cac che do cong com memset(&dcb,0,sizeof(dcb)); dcb.DCBlength = sizeof(dcb); dcb.BaudRate = 9600; dcb.fBinary = 1; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; dcb.ByteSize = 8; dcb.fDtrControl = DTR_CONTROL_ENABLE; dcb.fRtsControl = RTS_CONTROL_ENABLE; if(!SetCommState(hcom,&dcb)) printf ("E013_SetCommTimeouts failed 2\n"); CloseHandle(hcom); } } // Mo cong com void RS232(CString data) { // Chuyen va nhan du lieu char p; char data_receive; DWORD read = 0; DWORD write=1; // Number of bytes to write to serial port p = WriteFile(hcom,&data,write,&write,NULL); // write is updated with the number of bytes written ReadFile(hcom,&data_receive,sizeof(data_receive),& read,NULL); // read is updated with the number of bytes read DWORD i; for (i=0; i<read; i++) printf("%i ", (unsigned char)data_receive); } // BAT DAU HAM MAIN GUI MOT KY TU XUONG PIC16F877A. void main(){ setting(); RS232('R'); } CẢM ƠN MỌI NGƯỜI RẤT RẤT NHIỀU !! thay đổi nội dung bởi: xuanducdhcn, 08-11-2010 lúc 04:04 PM. |
![]() |
![]() |
|
|
![]() |
||||
Ðề tài | Người gửi | Chuyên mục | Trả lời | Bài mới |
Cho hỏi về giao tiếp RS232 của PIC16F877A | enti | Giao tiếp cổng COM và LPT | 31 | 25-03-2016 10:14 PM |
Giao tiếp RS232 trên PC qua Matlab | ngohaibac | Giao tiếp cổng COM và LPT | 47 | 18-11-2015 03:51 PM |
giao tiep RS232 voi C | dangngoc | Giao tiếp cổng COM và LPT | 9 | 26-02-2012 02:25 AM |
cần mua bộ thu GPS có giao tiếp RS232 | kienvq | Tìm mua sản phẩm | 15 | 17-03-2011 11:25 PM |
Help! Dùng C để giao tiếp RS232 | dandiennang | Các ngôn ngữ lập trình khác (CCS C, HT PIC,...) | 6 | 15-03-2009 06:41 PM |