![]() |
|
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 |
![]() |
#1 |
Đệ tử 1 túi
Tham gia ngày: Jul 2007
Bài gửi: 22
: |
![]() Mình mới viết 1 chg trình dùng để điều khiển con trỏ dịch chuyển : lên, xuống, trái, phải trên màn mình LCD, để điều khiển nó, mình viết VB truyền dữ liệu xuống 16f877a để ra lệnh điều khiển và test lại bằng Serial in out Monitor của CCS, sau đây là code CCS và code VB ,mong các bạn tham khảo và góp ý:
Code:
#include <16f877a.h> #include <def_877a.h> #use delay(clock=20000000) #fuses HS, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOPROTECT #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,stream=GPS) #include <flex_lcd_1.c> //#include <lcd1.c> #include <stdlib.h> #include <string.h> int32 dulieu; int i=1; int j=1; char kytu; #INT_RDA void nhandulieu() { dulieu=getc(); if(dulieu=='l') { i--; lcd_gotoxy(i,j); } else if(dulieu=='r') { i++; lcd_gotoxy(i,j); } else if(dulieu=='u') { j=1; lcd_gotoxy(i,j); } else if(dulieu=='d') { j=2; lcd_gotoxy(i,j); } else if(dulieu=='`') { lcd_putc('\n'); } else { lcd_putc(dulieu); } } void main(void) { set_tris_c(128); enable_interrupts(GLOBAL); enable_interrupts(INT_RDA); lcd_init(); delay_ms(10); lcd_gotoxy(1,1); while(true) { //lcd_send_byte(0,0x0A); lcd_send_byte(0,0x0E); //bat hien thi, nhap nhay con tro. } } thay đổi nội dung bởi: ngohaibac, 11-06-2008 lúc 07:00 PM. Lý do: Bỏ code trong thẻ code |
![]() |
![]() |
![]() |
#2 |
Đệ tử 1 túi
Tham gia ngày: Jul 2007
Bài gửi: 22
: |
code VB:
Code:
Dim dulieu As String Dim a, b As Integer Private Sub Command1_Click() End End Sub Private Sub Form_Load() MSComm1.PortOpen = True ''MSComm1.CommPort = 1 MSComm1.Settings = "9600,N,8,1" End Sub Private Sub Option1_Click() If (Option1.Value = True) And (Option2.Value = False) Then a = 1 ElseIf (Option1.Value = False) And (Option2.Value = True) Then a = 2 End If End Sub Private Sub Option2_Click() If (Option1.Value = True) And (Option2.Value = False) Then a = 1 ElseIf (Option1.Value = False) And (Option2.Value = True) Then a = 2 End If End Sub Private Sub Text1_Change() MSComm1.Output = Right(Text1.Text, 1) End Sub Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 37 Then ''left MSComm1.Output = "l" ElseIf KeyCode = 38 Then ''up MSComm1.Output = "u" ElseIf KeyCode = 39 Then ''right MSComm1.Output = "r" ElseIf KeyCode = 40 Then ''down MSComm1.Output = "d" ElseIf KeyCode = 13 Then ''enter MSComm1.Output = "`" End If End Sub thay đổi nội dung bởi: ngohaibac, 11-06-2008 lúc 07:01 PM. |
![]() |
![]() |
![]() |
#3 |
Đệ tử 1 túi
Tham gia ngày: Jul 2007
Bài gửi: 22
: |
Đây chỉ là một ứng dụng nhỏ chỉ để chúng ta luyện tập viết code VB và CCS thôi, nên không khó lắm, nhưng mình nghĩ trong thực tế ngoài đời chắc chả ai đi làm thế này làm jì cả...
|
![]() |
![]() |
![]() |
|
|