PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Những câu hỏi thường gặp (http://www.picvietnam.com/forum/forumdisplay.php?f=54)
-   -   Ngắt ngoài pic 16f887 (http://www.picvietnam.com/forum/showthread.php?t=37963)

113vina 15-11-2018 09:52 AM

Ngắt ngoài pic 16f887
 
EM CÓ VẤN ĐỀ THẾ NÀY MONG CÁC BÁC TRỢ GIÚP Ạ:
EM DÙNG PIC 16F887, KHI EM DÙNG NGẮT NGOÀI RB0, THÌ MẠCH CHẠY BÌNH THƯỜNG, KHI EM DÙNG NGẮT PORTB(RB4-RB7) CŨNG CHẠY BÌNH THƯỜNG, NHƯNG KHI EM DÙNG CẢ NGẮT CHÂN RB0 VÀ PORTB(RB0-RB7) THÌ TRƯƠNG TRÌNH CHẠY BỊ SAI

TRƯƠNG TRÌNH ĐÂY Ạ

#include <16F887.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV40 //Brownout reset at 4.0V

#byte CoNgatRB=6

#use delay(crystal=20000000)
#use FIXED_IO( A_outputs=PIN_A5,PIN_A4,PIN_A3,PIN_A2,PIN_A1 )
#use FIXED_IO( B_outputs=PIN_B3,PIN_B2,PIN_B1 )
#use FIXED_IO( C_outputs=PIN_C6,PIN_C5,PIN_C4,PIN_C3,PIN_C2,PIN_C 1,PIN_C0 )
#use FIXED_IO( D_outputs=PIN_D7,PIN_D6,PIN_D5,PIN_D4,PIN_D3,PIN_D 2,PIN_D1,PIN_D0 )
#use FIXED_IO( E_outputs=PIN_E2,PIN_E0 )

int8 uv,light;

#INT_RB
void RB_isr(void)
{
int8 a;
if(!input(pin_b5))
{
while(!input(pin_b5)){}
light++;
if(light>1) light=0;
}
a = CoNgatRB;
clear_interrupt(INT_RB);
}

#INT_EXT
void EXT_isr(void)
{
uv++;
if(uv>1)
{
uv=0;
}
}

#INT_TIMER0
void TIMER0_isr(void)
{

}

void main()
{
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_DIV_2);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bi t); //13.1 ms overflow
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //13.1 ms overflow
setup_timer_2(T2_DIV_BY_1,0,1); //0.2 us overflow, 0.2 us interrupt

clear_interrupt(INT_RB);
enable_interrupts(INT_RB4);
enable_interrupts(INT_RB5);
enable_interrupts(INT_RB6);
enable_interrupts(INT_RB7);

enable_interrupts(INT_EXT);
ext_int_edge( L_TO_H );
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
uv=0;light=0; output_low(pin_C5);output_low(pin_C6);
while(TRUE)
{
if(uv==1) output_high(pin_C6);
else output_low(pin_C6);
output_d(uv);
if(light==1) output_high(pin_C5);
else output_low(pin_C5);
output_d(light);
}

}

CÁC BÁC XEM TRỢ GIÚP EM VỚI Ạ, EM CẢM ƠN NHIỀU


Múi giờ GMT. Hiện tại là 07: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