RP Store Tìm linh kiện theo mã, gửi BOM nhận báo giá Gửi BOM

cần giúp đỡ về bộ timer pic 18f4520

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • xlheomoixl
    Nhập môn đệ tử
    • Nov 2015
    • 1

    #1

    cần giúp đỡ về bộ timer pic 18f4520

    mình đang viết code phần phát một mã hồng ngoại dùng bộ timer để tạo xung 38k . code của mình thời gian để tắt bật timer không chuẩn xác như thiết lập bạn nào có thể chỉnh giúp mình với mình mới học về pic chưa hiểu lắm mong mọi người giúp đỡ
    #include<p18f4520.h>
    #include<stdio.h>
    #include<delays.h>
    #include<timers.h>

    #pragma config OSC=HS
    #pragma config WDT=OFF
    #pragma config MCLRE=ON
    #pragma config PBADEN=OFF

    #define xung PORTBbits.RB4
    #define xung2 PORTBbits.RB5
    void guibit(unsigned char b);
    void guibyte(unsigned char b);
    void high_isr (void);
    void guibit(unsigned char b)
    {
    if (b)
    {
    T0CONbits.TMR0ON = 1;
    Delay1KTCYx(1);
    T0CONbits.TMR0ON =0;
    xung=1;
    Delay1KTCYx(3);
    }
    else
    {
    T0CONbits.TMR0ON = 1;
    Delay1KTCYx(3);
    T0CONbits.TMR0ON =0;
    xung=1;
    Delay1KTCYx(1);
    }
    }

    void guibyte(unsigned char b)
    {
    unsigned char i;
    for(i=0;i<=8;i++)
    {
    guibit(b&0x80);
    b=b<<1;
    }
    }
    #pragma code high_vector=0x08
    void interrupt_at_high_vector(void)
    {
    _asm GOTO high_isr _endasm
    }
    #pragma code /* return to the default code section */
    #pragma interrupt high_isr
    void high_isr (void)
    {
    TMR0L =(256-5);
    INTCONbits.TMR0IF=0;
    xung=~xung;
    }

    void main()
    {
    unsigned char dem=0;
    ADCON1 = 0X0F;
    TRISB = 0;
    TRISC = 0;
    TRISD = 0xff;

    RCONbits.IPEN=1;
    INTCONbits.GIE=1;
    INTCONbits.TMR0IE=1;
    INTCONbits.TMR0IF=0;
    INTCON2bits.TMR0IP=1;

    T0CONbits.T08BIT = 1;
    T0CONbits.T0CS = 0;
    T0CONbits.PSA = 0;
    T0CONbits.T0PS2 = 0;
    T0CONbits.T0PS1 = 0;
    T0CONbits.T0PS0 = 0;
    xung = 0;
    while(1)
    {
    guibyte(0x0f);
    Delay10KTCYx(100);
    }
    }
Working...