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 07-11-2008, 10:32 AM   #1
nguyenquoctoan
Đệ tử 6 túi
 
Tham gia ngày: Nov 2007
Nơi Cư Ngụ: BK TP HCM
Bài gửi: 136
:
Question giao tiếp máy tính vẫn là nóng bỏng nhất

#include<18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOPUT,NODEBUG,NOBROWNOUT, NOCPD,NOWRT
#device PIC184550*=16 ADC=10
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
#include<stdlib.h>
#include<lcd_lib_4bit.c>
#byte porta = 0x80
#byte portb = 0x81
#byte portc = 0x82
#byte porte = 0x84
char buffer[60],tam[7];
int i,j,j1;
int k = 0;
float x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15 ,x16,x17,x18,x19,x20;
#int_RDA
void getvalue()
{
gets(buffer);
k=1;
}


void main()
{
set_tris_b(0);
set_tris_e(0);

LCD_init();
delay_us(10);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"cat185");
LCD_putcmd(0xc0);
delay_us(10);
printf(LCD_putchar,"hien thi mang ?");
delay_ms(1000);
enable_interrupts(global);
enable_interrupts(int_RDA);
while (1)
{
if(k==1)
{

LCD_putcmd(0x01);
delay_us(10);
LCD_putcmd(0xc0);
delay_us(10);
printf(LCD_putchar,"du lieu da nhan");
delay_us(10);
j=0;j1=0;

for (i=1;i<60;++i)
{
if (buffer[i]!='B') //nue khac B
{
tam[j]=buffer[i];
j=j+1;
}
else
{
//tam[j]='\0';
if (j1==0) x1=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x1);
delay_ms(1000);
if (j1==1) x2=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x2);
delay_ms(1000);
if (j1==2) x3=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x3);
delay_ms(1000);
if (j1==3) x4=atol(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x4);
delay_ms(1000);
if (j1==4) x5=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x5);
delay_ms(1000);
if (j1==5) x6=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x6);
delay_ms(1000);
if (j1==6) x7=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x7);
delay_ms(1000);
if (j1==7) x8=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x8);
delay_ms(1000);
if (j1==8) x9=atof(tam);
LCD_putcmd(0x80);
printf(LCD_putchar,"chuoi:%f",x9);
delay_ms(1000);
if (j1==9) x10=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x10);
delay_ms(1000);
if (j1==10) x11=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x11);
delay_ms(1000);
if (j1==11) x12=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x12);
delay_ms(1000);
if (j1==12) x13=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x13);
delay_ms(1000);
if (j1==13) x14=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x14);
delay_ms(1000);
if (j1==14) x15=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x15);
delay_ms(1000);
if (j1==15) x16=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x16);
delay_ms(1000);
if (j1==16) x17=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x17);
delay_ms(1000);
if (j1==17) x18=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x18);
delay_ms(1000);
if (j1==18) x19=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x19);
delay_ms(1000);
if (j1==19) x20=atof(tam);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"chuoi:%f",x20);
delay_ms(1000);
j1=j1+1;
j=0;
if (j1==20) break; //j1 xac dinh so chuoi
}

}

}
else
{
LCD_putcmd(0x01);
delay_us(10);
LCD_putcmd(0x80);
delay_us(10);
printf(LCD_putchar,"du lieu chua nhan");
delay_ms(500);
}
k=0;
}
}

nhận hết dữ liệu vào bộ đệm khi có ngắt vậy mà kô chạy,có ngắt xảy ra nhưng kô hiện thị các giá trị
xin các sư huynh chí giáo
nguyenquoctoan vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 07-11-2008, 04:38 PM   #2
phanyen
Đệ tử 1 túi
 
Tham gia ngày: Apr 2008
Bài gửi: 16
:
Question help me !

em đang làm bài tập lớn " điều khiển động cơ bước (góc quay , chiều quay và vị trí) " có giao tiếp pc với r232 , nhưng thấy khó quá ! bác nào biết hướng dẫn em với . phần cứng thì em đã ok , em đang gặp vấn đề ở chỗ pc giao tiếp với r232.
em được biết gần đây picvietnam co tổ chức cuộc thi " pid cho dc motor " bác náo có bài đó cho em xin bản nháp để tham khảo .
nếu được thì gửi cho em theo đĩa chỉ này nè : Mr.son84@gmail.com or nguyenson8486@yahoo.com.vn
thanks !
phanyen vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
Old 07-11-2008, 10:08 PM   #3
nguyenquoctoan
Đệ tử 6 túi
 
Tham gia ngày: Nov 2007
Nơi Cư Ngụ: BK TP HCM
Bài gửi: 136
:
hàm gets(buffer) nhận chuỗi,mà trong hàm ngắt kô được nhận chuỗi,kô chạy là phải,...
cảm ơn sư phụ linh đã chỉ giáo
nguyenquoctoan 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


Múi giờ GMT. Hiện tại là 08:39 AM.


Đượ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