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 25-07-2013, 04:41 PM   #21
khactinh88hn
Nhập môn đệ tử
 
Tham gia ngày: Jul 2013
Bài gửi: 3
:
chào mọi người! mình mới tìm hiểu về pic.mình viêt c/trình nháy led nhiều chế độ.nhưng cảm thấy ko ưng.mọi người có cách viết hay hơn thì góp ý cho mình nhé.đây là code của mình:
#include <16f877a.h>
#FUSES NOWDT,HS,NOPUT,NOPROTECT,NODEBUG,NOLVP
#use delay(clock=20000000)
#use fast_io(b)
int i;
void led_doithuan()
{
output_b(0x00);
delay_ms(300);
output_b(0x01);
delay_ms(300);
output_b(0x02);
delay_ms(300);
output_b(0x04);
delay_ms(300);
output_b(0x08);
delay_ms(300);
output_b(0x010);
delay_ms(300);
output_b(0x020);
delay_ms(300);
output_b(0x40);
delay_ms(300);
output_b(0x80);
delay_ms(300);
}
void led_doinguoc()
{
output_b(0x80);
delay_ms(300);
output_b(0x40);
delay_ms(300);
output_b(0x20);
delay_ms(300);
output_b(0x10);
delay_ms(300);
output_b(0x8);
delay_ms(300);
output_b(0x4);
delay_ms(300);
output_b(0x2);
delay_ms(300);
output_b(0x1);
delay_ms(300);
output_b(0x0);
delay_ms(300);
}
void led_giua()
{
output_b(0x18);
delay_ms(300);
output_b(0x24);
delay_ms(300);
output_b(0x42);
delay_ms(300);
output_b(0x081);
delay_ms(300);
}
void led_ngoai()
{
output_b(0x081);
delay_ms(300);
output_b(0x042);
delay_ms(300);
output_b(0x024);
delay_ms(300);
output_b(0x018);
delay_ms(300);
output_b(0x00);
delay_ms(2000);
}
void led_duoi()
{
for (i=1;i<0x80;i=i++,output_b(0xff),delay_ms(300));
}
void main()
{
set_tris_b(0x00);
while (1)
{

led_doithuan();
delay_ms(300);
led_doinguoc();
led_giua();
led_ngoai();
}

}
khactinh88hn 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à 05:14 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