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 18-02-2009, 11:20 AM   #1
vuthien86
Đệ tử 1 túi
 
Tham gia ngày: Feb 2009
Bài gửi: 13
:
Cool xem giúp mình đoạn code này lỗi ở đâu

#include <16F84A.h>
#include <def_84a.h>
#FUSES NOWDT, HS, NOPUT, NOPROTECT
#use delay(clock=10000000)
int8 i; //khai bao bien chay vong lap i
int8 temp;
//khai bao cac chuong trinh con ()
void chuong_trinh_1();//nhap nhay cong B
void chuong_trinh_2();//led sang tu trai qua phai
void chuong_trinh_3();//led sang tu phai qua trai
void chuong_trinh_4();//nhap nhay xen ke
void chuong_trinh_5();//led tat chay tu ngoai vao trong,roi chay ra ngoai
void chuong_trinh_6();//
void chuong_trinh_7();
void chuong_trinh_8();


void main()
{
trisb=0x00;//cong b xuat du lieu


while(1)
{
chuong_trinh_1();delay_ms(250);
chuong_trinh_3();delay_ms(250);
chuong_trinh_4();delay_ms(250);
chuong_trinh_5();delay_ms(250);
chuong_trinh_6();delay_ms(250);
chuong_trinh_7();delay_ms(250);
chuong_trinh_8();delay_ms(250);
}
}

void chuong_trinh_1()
{
portb=0x00;
delay_ms(1000);
portb=0xFF;
delay_ms(1000);
}
void chuong_trinh_2()
{//led nhay sang tu trai qua phai ,tao tre 250ms)
temp=0xFF;
for(i=0;i<=8;i++)
{
portb=temp;
delay_ms(250);
temp>>=1;//
}
}
void chuong_trinh_3()
{//led sang dich tu phai sang trai
temp=0xFF;
for(i=0;i<=8;i++)
{
portb=temp;
delay_ms(250);
temp<<=1;
}
}
void chuong_trinh_4()
{
portb=0xAA;
delay_ms(500);
portb=0x55;
delay_ms(500);
}
void chuong_trinh_5()
{
portb=0x7E;delay_ms(150);
portb=0xBD;delay_ms(150);
portb=0xDB;delay_ms(150);
portb=0xE7;delay_ms(150);
portb=0xDB;delay_ms(150);
portb=0xBD;delay_ms(150);
portb=0x7E;delay_ms(150);
}
void chuong_trinh_6()
{
temp=0xFF;
for(i=0;i<=8;i++)
{
portb=temp;
delay_ms(250);
temp=temp>>1;
}
}
void chuong_trinh_7()
{
portb=0xFE;delay_ms(150);
portb=0xFD;delay_ms(150);
portb=0xFB;delay_ms(150);
portb=0xF7;delay_ms(150);
portb=0xEF;delay_ms(150);
portb=0xDF;delay_ms(150);
portb=0xBF;delay_ms(150);
portb=0x7F;delay_ms(150);
}
void chuong_trinh_8()
{
portb=0x7F;delay_ms(150);
portb=0xBF;delay_ms(150);
portb=0xDF;delay_ms(150);
portb=0xEF;delay_ms(150);
portb=0xF7;delay_ms(150);
portb=0xFB;delay_ms(150);
portb=0xFD;delay_ms(150);
portb=0xFE;delay_ms(150);
}

=======================
mình dùng pic 16f84a ,thạch anh ngoài 10Mhz để đièu khiển nháy 8 led cổng B0->b7
mình định nghĩa chương trình con và gọi nó sao ko được vậy .xin các anh em chỉ giúp mình ,kiến thức C còn hạn chế lắm
vuthien86 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à 02:47 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