PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   dsPIC - Bộ điều khiển tín hiệu số 16-bit (http://www.picvietnam.com/forum/forumdisplay.php?f=29)
-   -   code mau! (http://www.picvietnam.com/forum/showthread.php?t=5229)

tkpro 02-11-2009 11:08 PM

code mau!
 
Chao cac pac!
e dang học về dsPic33FJ256GP, anh nào trên diễn đàn có thể cho e đoạn code bất kỳ để e tét cổng D được không ah?thanks!

tungnh 04-11-2009 01:46 AM

Code:

#include "p33FJ256GP710.h"
_FOSCSEL(FNOSC_PRIPLL);                        // Primary (XT, HS, EC) Oscillator with PLL
_FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF  & POSCMD_XT);
_FWDT(FWDTEN_OFF);             
_FGS(GCP_OFF);                           
int i;
int main(void)
{
                                        // Configure Oscillator to operate the device at 40Mhz
                                        // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
                                        // Fosc= 10M*32/(2*2)=80Mhz for 10M input clock
        PLLFBD=30;                                        // M=32
        CLKDIVbits.PLLPOST=0;                // N1=2
        CLKDIVbits.PLLPRE=0;                // N2=2
        OSCTUN=0;                                        // Tune FRC oscillator, if FRC is used
                                                                // Disable Watch Dog Timer
        RCONbits.SWDTEN=0;
                                                                // Wait for PLL to lock
        PSVPAG = 0;
        CORCONbits.PSV=1;
        __builtin_write_OSCCONH(0x03);                // Initiate Clock Switch to Primary
                                                                // Oscillator with PLL (NOSC=0b011)
        __builtin_write_OSCCONL(0x01);                // Start clock switching
        while (OSCCONbits.COSC != 0b011);        // Wait for Clock switch to occur
        while(OSCCONbits.LOCK!=1) {};
        TRISD = 0;
        while(1)
        {
            LATD++;
          for(i=0;i<65000;i++);
          for(i=0;i<65000;i++);
        }
}

bạn có thể đo câc chân ở cổng D , bạn sẽ thấy độ rộng xung tăng dần từ D0->D15


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