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 27-07-2012, 02:43 PM   #2
tdm
Đệ tử 7 túi
 
Tham gia ngày: May 2005
Bài gửi: 258
:
Trích:
Nguyên văn bởi sontvak42 View Post
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;
}
}
}
tham khảo code sau:
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()
{
if( !input(PIN_B4) )
{
output_c(0xff);
model =model+1;
if(model==3)
model =1;
nokia_clear_screen();
switch (model)
{
case 1:
{
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_gotoxy(17,2);
printf(nokia_printchar,"Interrupts");
delay_us(10);
}
break;
}
clear_interrupt(int_rb);
}
}



void main()
{
set_tris_a(0xff); // all input
set_tris_b(0xff);
port_b_pullups(true); // treo tro port b
set_tris_c(0x00);
set_tris_d(0x00); // all output


ext_int_edge(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);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
// TODO: USER CODE!!

model =1;
nokia_init();
nokia_gotoxy(0,0);
printf(nokia_printchar,"ADC!");
while(true)

{
switch (model)
{
case 1:
{
adc = read_adc();
nokia_gotoxy(17,2);
printf(nokia_printchar,"%4.3f",adc);
delay_ms(100);//thoi gian lay mau adc
}
break;
}
}
}
Hình Kèm Theo
File Type: jpg adc.jpg (163.8 KB, 0 lần tải)
__________________
viết chương trình cho vdk chạy ổn định là cả một vấn đề.
tdm 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à 04:26 AM.


Đượ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