Trích:
Nguyên văn bởi tuananhk53
chào các anh,em mới bắt đầu học về pic nên có nhiều bỡ ngỡ,mong các anh chỉ giáo
có đoạn code CCS này
#include <16f877a.h>
#use delay(clock=20m)
void main()
{set_tris_b(0);
set_tris_a(255);
output_b(0);
while(1)
{
if(input(pin_a0)==1)
{
output_b(0xff);delay_ms(500);
output_b(0);delay_ms(500);
}
}
}
khi nạp vào pic thì nó chạy được rồi nhưng em muốn sau khi ấn nút,bỏ tay ra mà led vẫn nháy theo ý muốn thì phải sửa code thế nào cho đúng...
Anh nào rảnh lên chỉ giúp em với,thanks!!!
|
bạn sửa lại như thế này
Code:
#include <16f877a.h>
#use delay(clock=20000000)
#bit ra0=0x5.0
void main()
{
set_tris_b(0);
set_tris_a(0xff);
output_b(0);
while(1)
{
if(ra0==1)
{
a: output_b(0xff);
delay_ms(500);
output_b(0);
delay_ms(500);
if(ra0==0)
goto a;
}
}
}