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)
-   -   Lập trình ngắt timer0 pic8f452 (http://www.picvietnam.com/forum/showthread.php?t=7356)

linhk43 10-11-2010 06:15 PM

Lập trình ngắt timer0 pic8f452
 
em viết đoạn chương trình này nhưng không chạy là sao hả các bác

#include <18f452.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES RC_IO //Resistor/Capacitor Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOPUT //No Power Up Timer
#FUSES STVREN //Stack full/underflow will cause reset
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
int16 count;
int8 led ;
#int_timer0
void ngat_timer0()
{
set_timer0(57);
++count;
if(count>=98)
{
count=0;
led<<=1;
led+=1;
}
}
void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
set_tris_b(0);
set_timer0(57);
enable_interrupts(global);
enable_interrupts(int_timer0);
while(1)
{
output_b(led);
}
}

kqha1025 10-11-2010 06:49 PM

1 Attachment(s)
Trích:

Nguyên văn bởi linhk43 (Post 40024)
em viết đoạn chương trình này nhưng không chạy là sao hả các bác

#include <18f452.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES RC_IO //Resistor/Capacitor Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOPUT //No Power Up Timer
#FUSES STVREN //Stack full/underflow will cause reset
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
int16 count;
int8 led ;
#int_timer0
void ngat_timer0()
{
set_timer0(57);
++count;
if(count>=98)
{
count=0;
led<<=1;
led+=1;
}
}
void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
set_tris_b(0);
set_timer0(57);
enable_interrupts(global);
enable_interrupts(int_timer0);
while(1)
{
output_b(led);
}
}

- thứ 1 : e dùng thạch anh 20 mhz mà em chưa khai fuses HS
- thứ 2 : e để thời gian quá dài, lâu mới có kết quả
-mô phỏng proteus con này e phải nối mạch reset cho pic
-xem lại mấy cái fuses e khai xem
a test ok rồi, a gưi cả folder chứa cả code a sửa và proteus nữa , e xem lại nha!
chúc zui!

linhk43 11-11-2010 07:54 AM

Cảm ơn bác kqha1025 em làm đc rồi


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