sontvak42
25-07-2012, 04:33 PM
Ai có thể giúp em gỡ rối phần ngắt RB này cái không ạ.!
Tại sao khi chương trình của em viết khi nó nhảy vào chương trình phục vụ ngắt thì lại không thực hiện ở phần case 2 nữa, màn hình LCD cũng bị treo luôn không làm cách nào khôi phục được.
Mong các pro giúp đỡ em với!
Em cám ơn nhiều.
Code :
#include <16F877A.h>
#include <def_877a.h>
#device adc=10
#FUSES NOWDT, XT, PUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, WRT_50%
#use delay(clock=4000000)
#use fast_io(a)
#use fast_io(b)
#include <lcd_nokia3310.c>
int8 model;
float adc;
#int_RB
void RB_isr()
{
output_c(0xff);
model =model+1;
clear_interrupt(int_rb);
}
void main()
{
set_tris_a(0xff); // all input
set_tris_b(0xff);
// port_b_pullups(1); // treo tro port b
set_tris_c(0x00);
set_tris_d(0x00); // all output
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
ext_int_edge(0,H_to_L);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
model =1;
while(true)
{
nokia_init();
// if(RB7==0)
// model++;
if(model==3)
model =1;
switch (model)
{
case 1:
{
nokia_clear_screen();
adc = read_adc();
nokia_gotoxy(0,0);
printf(nokia_printchar,"ADC!");
nokia_gotoxy(17,2);
printf(nokia_printchar,"%4.3f",adc);
delay_us(10);
}
break;
case 2:
{
nokia_clear_screen();
nokia_gotoxy(17,2);
printf(nokia_printchar,"Interrupts");
delay_us(10);
}
break;
}
}
}
Tại sao khi chương trình của em viết khi nó nhảy vào chương trình phục vụ ngắt thì lại không thực hiện ở phần case 2 nữa, màn hình LCD cũng bị treo luôn không làm cách nào khôi phục được.
Mong các pro giúp đỡ em với!
Em cám ơn nhiều.
Code :
#include <16F877A.h>
#include <def_877a.h>
#device adc=10
#FUSES NOWDT, XT, PUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, WRT_50%
#use delay(clock=4000000)
#use fast_io(a)
#use fast_io(b)
#include <lcd_nokia3310.c>
int8 model;
float adc;
#int_RB
void RB_isr()
{
output_c(0xff);
model =model+1;
clear_interrupt(int_rb);
}
void main()
{
set_tris_a(0xff); // all input
set_tris_b(0xff);
// port_b_pullups(1); // treo tro port b
set_tris_c(0x00);
set_tris_d(0x00); // all output
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
ext_int_edge(0,H_to_L);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
model =1;
while(true)
{
nokia_init();
// if(RB7==0)
// model++;
if(model==3)
model =1;
switch (model)
{
case 1:
{
nokia_clear_screen();
adc = read_adc();
nokia_gotoxy(0,0);
printf(nokia_printchar,"ADC!");
nokia_gotoxy(17,2);
printf(nokia_printchar,"%4.3f",adc);
delay_us(10);
}
break;
case 2:
{
nokia_clear_screen();
nokia_gotoxy(17,2);
printf(nokia_printchar,"Interrupts");
delay_us(10);
}
break;
}
}
}