Thông báo

Collapse
No announcement yet.

8051 giao tiếp với máy tính bị treo

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • 8051 giao tiếp với máy tính bị treo

    mình đang có đồ án như sau: vdk 89c51 dk 12 nút bấm. khi bấm nút vdk sẽ truyền 1 chuỗi thông báo tương ứng. nhưng trước đó nếu có tín hiệu từ máy tính
    vd: '1' thì vdk sẽ ngắt nút bấm thứ 1. mình gặp rắc rồi ở chỗ vdk chỉ nhận tín hiệu từ máy tính lần thứ nhất rồi bị treo không làm được gì nữa. mong các bác giúp đỡ
    đây là code của mình :

    #include<AT89x51.h>
    #include<string.h>
    #define CB1a P0_0
    #define CB1 P0_1
    #define CB2a P0_2
    #define CB2 P0_3
    #define CB3a P0_4
    #define CB3 P0_5
    #define CB4a P0_6
    #define CB4 P0_7
    #define CB5a P1_0
    #define CB5 P1_1
    #define CB6a P1_2
    #define CB6 P1_3
    #define CB7a P1_4
    #define CB7 P1_5
    #define CB8a P1_6
    #define CB8 P1_7
    #define CB9a P2_0
    #define CB9 P2_1
    #define CB10a P2_2
    #define CB10 P2_3
    #define CB11a P2_4
    #define CB11 P2_5
    #define CB12a P2_6
    #define CB12 P2_7

    void send(unsigned char a);
    void sendchuoi(char *a);
    unsigned char temp;
    void send(unsigned char a)
    {
    SBUF=a;
    while(TI==0){}
    TI=0;
    }
    void sendchuoi(char *a)
    { int i,n;
    n=strlen(a);
    for(i=0;i<n;i++)
    {
    send(a[i]);
    }
    }
    void main(void)
    {
    TMOD=0x20;
    TH1=0xFD;
    SCON=0x50;
    TR1=1;
    IE=0x90;
    P1=0xAA;
    P2=0xAA;
    P0=0xAA;
    while(1)
    {
    if(CB1 == 0)
    {
    while(!CB1);
    sendchuoi("phong 1 trai phep");
    send(10);}
    if(CB2 == 0)
    {
    while(!CB2);
    sendchuoi("phong 2 trai phep");
    send(10);}
    if(CB3 == 0)
    {
    while(!CB3);
    sendchuoi("phong 3 trai phep");
    send(10);}
    if(CB4 == 0)
    {
    while(!CB4);
    sendchuoi("phong 4 trai phep");
    send(10);}
    if(CB5 == 0)
    {
    while(!CB5);
    sendchuoi("phong 5 trai phep");
    send(10);}
    if(CB6 == 0)
    {
    while(!CB6);
    sendchuoi("phong 6 trai phep");
    send(10);}
    if(CB7 == 0)
    {
    while(!CB7);
    sendchuoi("phong 7 trai phep");
    send(10);}
    if(CB8 == 0)
    {
    while(!CB8);
    sendchuoi("phong 8 trai phep");
    send(10);}
    if(CB9 == 0)
    {
    while(!CB9);
    sendchuoi("phong 9 trai phep");
    send(10);}
    if(CB10 == 0)
    {
    while(!CB10);
    sendchuoi("phong 10 trai phep");
    send(10);}
    if(CB11 == 0)
    {
    while(!CB11);
    sendchuoi("phong 11 trai phep");
    send(10);}
    if(CB12 == 0)
    {
    while(!CB12);
    sendchuoi("phong 12 trai phep");
    send(10);}
    if(temp=='1')
    {CB1=0;}
    if(temp=='2')
    {CB2=0;}
    if(temp=='3')
    {CB3=0;}
    if(temp=='4')
    {CB4=0;}
    if(temp=='5')
    {CB5=0;}
    if(temp=='6')
    {CB6=0;}
    if(temp=='7')
    {CB7=0;}
    if(temp=='8')
    {CB8=0;}
    if(temp=='9')
    {CB9=0;}
    if(temp=='a')
    {CB10=0;}
    if(temp=='b')
    {CB11=0;}
    if(temp=='c')
    {CB12=0;}
    }
    }
    void nhandulieu(void) interrupt 4 // khai bao ngat truyen thong
    {
    if(RI==1) // kiem tra xem co phai ngat nhan hay khong
    {
    temp=SBUF; // lây du lieu luu vao bien temp
    RI=0; //xóa co nhan chuyen bi cho nhan du lieu tiep theo

    }


    }

Về tác giả

Collapse

riseofdark Tìm hiểu thêm về riseofdark

Bài viết mới nhất

Collapse

Đang tải...
X