![]() |
Hỏi cách nối chuỗi để thực hiện 1 chức năg qua Virtual terminal
Mới học nên ko biết sao ko chạy dc!!
Chương trình mình muốn nhập vào Virtual Terminal "sd1" thì led thứ 1 của portd sáng,tương tự "sd2","sd3"... "td1": chỉ tắt đèn vị trí thứ 1 của portd các đèn khác ko ảnh hưởng,tương tự "td2","td3".... Code như sau: "Các bạn giúp m nhé" Thân!!! #include <16f877.h> #use delay (clock = 16000000) #use rs232 (uart1, baud=9600,parity=n,xmit=pin_c6,rcv=pin_c7 ) #include <string.h> #byte portd=0x08 #bit t0=portd.0 #bit t1=portd.1 #bit t2=portd.2 #bit t3=portd.3 #bit t4=portd.4 #bit t5=portd.5 #bit t6=portd.6 #bit t7=portd.7 char a="sd1", b = "sd2", c = "sd3", d = "sd4", e = "sd5", f = "sd6", g = "sd7", h = "sd8", a1 = "td1", b2 = "td2", c3 = "td3", d4 = "td4", e5 = "td5", f6 = "td6", g7 = "td7", h8 = "td8"; void main() { char test[3]; int i; set_tris_d (0x00) ; set_tris_c (0xff) ; portd = (0x00); while (1) { for (i = 0; i < 3; i++) { test[i] = getc () ; printf ("%c",test[i]) ; } sprintf (test,"%c%c%c",test[0],test[1],test[2]); if (strcmp (test, a) == 0) portd = 0x01; else if (strcmp (test, b) == 0) portd = 0x02; else if (strcmp (test, c) == 0) portd = 0x04; else if (strcmp (test, d) == 0) portd = 0x08; else if (strcmp (test, e) == 0) portd = 0x10; else if (strcmp (test, f) == 0) portd = 0x20; else if (strcmp (test, g) == 0) portd = 0x40; else if (strcmp (test, h) == 0) portd = 0x80; else if (strcmp (test, a1) == 0) t0 = 0; else if (strcmp (test, b2) == 0) t1 = 0; else if (strcmp (test, c3) == 0) t2 = 0; else if (strcmp (test, d4) == 0) t3 = 0; else if (strcmp (test, e5) == 0) t4 = 0; else if (strcmp (test, f6) == 0) t5 = 0; else if (strcmp (test, g7) == 0) t6 = 0; else t7 = 0; } } |
Trích:
Code:
#include <16f877.h> |
Múi giờ GMT. Hiện tại là 03:41 AM. |
Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam