PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Các ngôn ngữ lập trình khác (CCS C, HT PIC,...)

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 16-09-2013, 03:39 PM   #1
minhkhai
Nhập môn đệ tử
 
Tham gia ngày: Jan 2013
Bài gửi: 1
:
giao tiếp máy tính

em đang làm đồ án dùng PC điều khiển động cơ bước thông qua 16f877A, gửi 1 kí tự từ máy tính xuống để đk động cơ xoay thuận nghịch, e có đoạn code sau biên dịch ko lỗi nhưng mô phỏng không chạy, mong các pro giúp e kiểm tra sai ở đâu.

#include <16F877A.h>
#fuses NOWDT,HS,NOPUT,NOPROTECT,NODEBUG,NOBROWNOUT,NOLVP, NOCPD,NOWRT
#use delay(clock=20000000,RESTART_WDT)
#use rs232(baud=9600, parity=N, xmit=pin_C6, rcv=pin_C7, bits=9)
#byte portb=0x06
#byte portd=0x08
char t;
int i;
//quay 1 buoc;
void motvong();
void quay();
void motvongnguoc();
void quaynguoc();

#int_RDA
void RDA_interrupt()
{

t = getc();

{

switch(t)
{
// quay thuan 1 buoc
case 'A': motvong(); break;
case 'B': quay(); break;
//quay nguoc 1 buoc
case 'C': motvongnguoc(); break;
case 'D': quaynguoc(); break;
}
}
}
//CHUONG TRINH CHINH
void main()
{
set_tris_b(0xff);
set_tris_d(0x00);
portd=0b11111110;

enable_interrupts(global);
enable_interrupts(int_RDA);
ext_int_edge(h_to_l);
while(1)
{

}
}

///quay 1 vong
void motvong()
{
for(i=0;i<50;i++)
{
portd=0b00001101;
delay_ms(200);
portd=0b00001011;
delay_ms(200);
portd=0b00000111;
delay_ms(200);
portd=0b00001110;
delay_ms(200);
}
}
//quay thuan
void quay()
{
while(1)
{
portd=0b00001101;
delay_ms(200);
portd=0b00001011;
delay_ms(200);
portd=0b00000111;
delay_ms(200);
portd=0b00001110;
delay_ms(200);
}
}

//mot vong nguoc
void motvongnguoc()
{
for(i=0;i<50;i++)
{
portd=0b00000111;
delay_ms(200);
portd=0b00001011;
delay_ms(200);
portd=0b00001101;
delay_ms(200);
portd=0b00001110;
delay_ms(200);
}
}
//quay nguoc
void quaynguoc()
{
while(1)
{
portd=0b00000111;
delay_ms(200);
portd=0b00001011;
delay_ms(200);
portd=0b00001101;
delay_ms(200);
portd=0b00001110;
delay_ms(200);
}
}
minhkhai vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


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


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam