|
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 |
07-11-2008, 10:32 AM | #1 |
Đệ 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 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 |
|
|