PIC Vietnam

Go Back   PIC Vietnam > Truyền thông > Giao tiếp cổng COM và LPT

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

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...

Trả lời
 
Ðiều Chỉnh Xếp Bài
Old 12-10-2011, 09:20 PM   #1
student_dtvt
Nhập môn đệ tử
 
Tham gia ngày: Aug 2011
Bài gửi: 2
:
Mấy bác cho em hỏi cái này. Em truyền nhận dữ liệu giữa 16f877 và VB6 đã nhận đc nhưng chỉ với thạch anh 4000000Hz, khi thay đổi cái này thì lại không nhận được. Em làm với kit thạch anh 24Mhz ko thể nhận dữ liệu được. Mong các bác chỉ giáo giùm em với.

VB:

Private Sub Command1_Click()
On Error GoTo OpenFalse
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
Exit Sub
OpenFalse:
MsgBox Err.Description & vbLf + vbCr + "Loi, khong the mo cong. Hay dong cac ung dung dang su dung cong COM"

End Sub

Private Sub Command2_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End
End Sub

Private Sub Command3_Click()
On Error GoTo sendfalse
MSComm1.Output = Text1.Text
Exit Sub
sendfalse:
MsgBox Err.Description & vbLf + vbCr + "Loi, Cong COM chua duoc mo, nhan Connect"
End Sub

Private Sub Form_Load()
With MSComm1
.Settings = cmbBaudRate.Text + "N,8,1"
.RThreshold = 1
.SThreshold = 0
.InBufferSize = 1024
.OutBufferSize = 1024
.InputMode = comInputModeText
.ParityReplace = ""
.CommPort = Switch(cmbComPort.Text = "COM 1", 1, cmbComPort.Text = "COM 2", 2, cmbComPort.Text = "COM 3", 3, cmbComPort.Text = "COM 4", 4)
End With
End Sub

Private Sub MSComm1_OnComm()
Dim StringIn As String
If MSComm1.CommEvent = comEvReceive Then
StringIn = MSComm1.Input 'Nhan chuoi du lieu to VCOM
Text2.Text = StringIn
End If
End Sub




PIC:
#include <16f877a.h>
#FUSES NOWDT, HS, NOPUT,NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=4000000)
#use rs232(baud=9600, parity=N, xmit=pin_C6, rcv=pin_C7)
#include <stdlib.h>
#byte porta = 0x05
#byte portb = 0x06
#byte portc = 0x07
#byte porte = 0x09
int8 y,i,a,b,c,d,e;
int16 x;
char string[5];
BYTE CONST maled[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};

void nhan_rs232()
{

for(i=0;i<=4;i++)
{
string[i]=getc();
}
printf("%s",string);
y=0;
x=atol(string);
a=x/10000;
x=x%10000;
b=x/1000;
x=x%1000;
c=x/100;
x=x%100;
d=x/10;
x=x%10;
e=x;

a=maled[a];
b=maled[b];
c=maled[c];
d=maled[d];
e=maled[e];

for(i=0;i<=200;i++)
{
output_A(0b01111);
output_D(a);
delay_ms(1);
output_A(0b11111);

output_A(0b10111);
output_D(b);
delay_ms(1);
output_A(0b11111);

output_A(0b11011);
output_D(c);
delay_ms(1);
output_A(0b11111);

output_A(0b11101);
output_D(d);
delay_ms(1);
output_A(0b11111);

output_A(0b11110);
output_D(e);
delay_ms(1);
output_A(0b11111);
}


}
/*void xoa()
{
for(i=0;i<=4;i++)
{
string[i]=0;
}
}*/
void main()
{
set_tris_b(0);
set_tris_e(0);
while(true)
{
if(y==0)
{
nhan_rs232();
delay_ms(100);

}
}
}


Em làm nhận một số 5 chữ số hiển thị led 7 đoạn

đây là file mô phỏng: http://www.mediafire.com/?d4g26cwn4bx4g8y
student_dtvt vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Trả lời


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến

Similar Threads
Ðề 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


Múi giờ GMT. Hiện tại là 12:22 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam