RP Store Tìm linh kiện theo mã, gửi BOM nhận báo giá Gửi BOM

Nhận chuỗi kí tự từ máy tính

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • pphamtuan
    Nhập môn đệ tử
    • Nov 2012
    • 1

    #1

    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
    Nhập môn đệ tử
    • Jan 2013
    • 6

    #2
    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;
    }
    }
    }

    Comment

    Working...