PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   dsPIC - Bộ điều khiển tín hiệu số 16-bit (http://www.picvietnam.com/forum/forumdisplay.php?f=29)
-   -   Nhận chuỗi kí tự từ máy tính (http://www.picvietnam.com/forum/showthread.php?t=31577)

pphamtuan 03-01-2013 01:08 AM

Nhận chuỗi kí tự từ máy tính
 
Làm sao để nhận được chuỗi kí tự từ máy tính qua cổng RS232 hiện thị đúng lên LCD vậy mọi người. Mình đã truyền nhận được 1 kí tự, khi truyền 1 chuõi thì hiển thị lên LCD chỉ đúng kí tự đầu tiên,các kí tự sau hiển thị chính xác.Mình dùng Pic6f887

pthien0288 08-01-2013 12:17 PM

bạn có thể mô phỏng trên proteus dùng 2 con pic
+ 1 con dùng để phát chuỗi ký tự.
+ 1 con dùng để nhận và hiển thị trên LCD.
code phát :
#include <transmiter.h>
#include <LCD_lib_4bit.c>
#use fast_io(D)
#use fast_io(B)
#use fast_io(C)
#byte portd=0x08
#byte portb=0x06
#byte portc=0x07
#bit but = portb.0
char data[7],temp;
void main()
{
set_tris_C(0x80);
set_tris_B(0x00);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
LCD_Init ();
delay_ms(1);
while(1)
{
if(but==0)
{
printf("University"); // nhan nut thuc thi lenh
while(but==0);
// nhan nut nha ra thuc thi cong viec
}
}
}

code nhận :

#include <UART.h>
#include <string.h>
#include <D:\chuong trinh\dk dien thoai\sim900\thien\myLCD16x2.c>
#use fast_io(D)
#use fast_io(B)
#use fast_io(C)
#byte portd=0x08
#byte portb=0x06
#byte portc=0x07
#bit but = portb.0
unsigned char data[65],kt[]="University";
int1 ok=0;
int8 count=0,temp;
signed char i;

#INT_RDA
void serial_isr()
{
data[count]=getc();
count++;
if(count==10)
{
count=0;
ok=1;
}
}
void main()
{
set_tris_C(0x80);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
lcd_init ();
delay_ms(1);

while(1)
{
if(ok==1)
{
for(i=0;i<10;i++)
{
putc(data[i]);
lcd_putc(data[i]);
}
ok=0;
}
}
}


Múi giờ GMT. Hiện tại là 03:31 PM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam