PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Các ngôn ngữ lập trình khác (CCS C, HT PIC,...) (http://www.picvietnam.com/forum/forumdisplay.php?f=12)
-   -   [cần giúp gấp] P16f877A interrupt Rb0 (press & hold SW) (http://www.picvietnam.com/forum/showthread.php?t=34934)

langkhachpfiev 08-05-2016 01:57 PM

[cần giúp gấp] P16f877A interrupt Rb0 (press & hold SW)
 
yêu cầu: (only use interrupt rb0)
1.press SW (not hold) ,count and display number of times of press (if up to 19 begin down,example 0,1,...18,19,18,17,...1,0,1,2....continue)--->solved
2.press and hold SW,count will up/down and display continuous--->mình không biết giải quyết như thế nào (trong hàm void ngat_RB0() hay trong void main() ?)

Code C file (PICC) and simulation (protues 8.4)
http://www.mediafire.com/download/3o...est_rb0_SW.rar


http://2.pik.vn/20162ebc68a3-80a7-4e...e274fc0384.jpg

phần code của mình,chạy tốt yêu cầu 1:
Trích:

#include <16F877A.h>
#fuses xt
#use delay(clock=4000000)
int8 ma7seg[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};
int8 count,i,n;

#int_ext
void ngat_RB0()
{

i=i+1;


}




void display()
{

if(i==19)
{i=0;n=n+1;}
if(n%2==0)
{count=i;}
else
count=19-i;


output_d(ma7seg[count/10]);
output_low(pin_e0);
delay_ms(25);
output_high(pin_e0);

output_d(ma7seg[count%10]);
output_low(pin_e1);
delay_ms(25);
output_high(pin_e1);

}


void main()
{
i=0;
n=0;
count=0;
set_tris_e(0x00);
set_tris_b(0x01);
set_tris_d(0x00);
output_e(0xff);
output_d(0x00);


enable_interrupts(global);
enable_interrupts(int_ext);
ext_int_edge(H_to_L);




while(1)
{
display();
}
}

1041002 26-06-2016 03:09 PM

Pic 16f877A có hỗ trợ ngắt khi thay đổi PortB và ngắt trên RB0 (INT/RB0). Tùy theo nhu cầu sử dung mà bạn set các thanh ghi phuc vụ ngắt. Còn việc ngắt để làm gì thì bạn viết trong hàm ngắt interrupt (){....}, khi điều kiện xảy ra tự động ngắt sẽ được gọi thôi. Ở đây minh có link bài nói về ngắt loại này, bạn có thể tham khảo.
http://www.dientudieukhien.net/2016/...int-interrupt/

Thậm chí ngắt để phát hiện xung có tần số cao, phát hiện được cạnh lên hay xuống, bạn xem tại link:
http://www.dientudieukhien.net/2016/01/19/dem-xung/

Chúc bạn thành công!


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

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam