Lập trình ngắt timer0 pic8f452

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • linhk43
    Nhập môn đệ tử
    • Feb 2010
    • 3

    #1

    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
    Đệ tử 3 túi
    • Oct 2008
    • 57

    #2
    Nguyên văn bởi linhk43 View Post
    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!
    Attached Files

    Comment

    • linhk43
      Nhập môn đệ tử
      • Feb 2010
      • 3

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

      Comment

      Working...