PIC Vietnam

Go Back   PIC Vietnam > Truyền thông > Giao tiếp USB, CAN, I2C, SPI, USART...

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 USB, CAN, I2C, SPI, USART... Những giao tiếp được tích hợp trên PIC

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 10-11-2008, 02:35 PM   #1
nguyenquoctoan
Đệ tử 6 túi
 
Tham gia ngày: Nov 2007
Nơi Cư Ngụ: BK TP HCM
Bài gửi: 136
:
giao tiếp máy tính

nhờ các cao thủ xem dùm em,giao tiếp với pic18 cổng com như sau,sai chỗ nào,sao chương trình kô chạy
#include<18f4550.h>
#fuses NOWDT,PUT,HS,NOPROTECT
#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[64],tam[5];
int i,j,j1;
float x5,x10,x15,x20;
int x1,x2,x3,x4,x6,x7,x8,x9,x11,x12,x13,x14,x16,x17,x1 8,x19;
int c=1;
int k=0;

void getvalue()
{
gets(buffer);
c=0;
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,"nhan du lieu");
LCD_putcmd(0xc0);
delay_us(10);
printf(LCD_putchar,"hien thi mang ?");
delay_ms(1000);
while (1)
{

if(c==1)
{
getvalue();
}
if(k==1)
{
LCD_putcmd(0x01);
delay_us(10);
LCD_putcmd(0xc0);
delay_us(10);
printf(LCD_putchar,"da ta ok");
delay_ms(500);
j=0;j1=0;

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

}

}

}
}
em đã test với mạch thật mà kô nhận được dữ liệu,...hic hic?
nguyenquoctoan vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


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à 04:03 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