• AVR Freaks

Hot!CDC_BASIC PIC24fj1024GB610 on board ex16/32

Author
hichamrol
Starting Member
  • Total Posts : 41
  • Reward points : 0
  • Joined: 2019/07/10 07:22:53
  • Location: 0
  • Status: online
2019/07/18 01:35:11 (permalink)
0

CDC_BASIC PIC24fj1024GB610 on board ex16/32

Good Morning Guys , 
So my problem is i want to send and receive datas  from the pic to my computer throught usb cable , i build  and make project device "CDC_basic" Demo project MLA given by Microchip on my pic , the problem is i don't know from where and how to begin , i just need how to blink led if i received a character from the interface given by MICROchip "USB SERIAL TERMINAL ", something like that ,
 
 
Thank you guys 
#1

3 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23185
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: CDC_BASIC PIC24fj1024GB610 on board ex16/32 2019/07/18 21:28:27 (permalink)

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    PStechPaul
    Super Member
    • Total Posts : 2342
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: online
    Re: CDC_BASIC PIC24fj1024GB610 on board ex16/32 2019/07/21 19:33:24 (permalink)
    0
    Here is some code I used in one USB project a while ago:
     
    STUPID FORUM won't allow me to post it.
    #if defined(__18CXX)
    void main(void)
    #else
    int main(void)
    #endif
    {   
        InitializeSystem();

        while(1)
        {
            // Check bus status and service USB interrupts.
            USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
                              // this function periodically.  This function will take care
                              // of processing and responding to SETUP transactions
                              // (such as during the enumeration process when you first
                              // plug in).  USB hosts require that USB devices should accept
                              // and process SETUP packets in a timely fashion.  Therefore,
                              // when using polling, this function should be called
                              // frequently (such as once about every 100 microseconds) at any
                              // time that a SETUP packet might reasonably be expected to
                              // be sent by the host to your device.  In most cases, the
                              // USBDeviceTasks() function does not take very long to
                              // execute (~50 instruction cycles) before it returns.
                          

            // Application-specific tasks.
            // Application related code may be added here, or in the ProcessIO() function.
            ProcessIO();        
        }//end while
    }//end main

     
    The user functions are in ProcessIO():
    #define mPWR                LATBbits.LATB3


    void ProcessIO(void)
    {   
        //Blink the LEDs according to the USB device status
        BlinkUSBStatus();
        // User Application USB tasks
        if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

    #if defined(BTSA3)
        if(USBDeviceState == CONFIGURED_STATE)
            mPWR_On();
    #endif

        if (RS232_Out_Data_Rdy == 0)  // only check for new USB buffer if the old RS232 buffer is
        {                          // empty.  This will cause additional USB packets to be NAK'd
            LastRS232Out = getsUSBUSART(RS232_Out_Data,64); //until the buffer is free.
            if(LastRS232Out > 0)
            {    
                RS232_Out_Data_Rdy = 1;  // signal buffer full
                RS232cp = 0;  // Reset the current position
            }
        }

        if(RS232_Out_Data_Rdy && mTxRdyUSART())
        {
            putcUSART(RS232_Out_Data[RS232cp]);
            ++RS232cp;
            if (RS232cp == LastRS232Out)
                RS232_Out_Data_Rdy = 0;
        }

        if(mDataRdyUSART())
        {
            USB_Out_Buffer[NextUSBOut] = getcUSART();
            ++NextUSBOut;
            USB_Out_Buffer[NextUSBOut] = 0;
        }

        if((USBUSARTIsTxTrfReady()) && (NextUSBOut > 0))
        {
            putUSBUSART(&USB_Out_Buffer[0], NextUSBOut);
            NextUSBOut = 0;
        }

        CDCTxService();
    }        //end ProcessIO


     
    #3
    PStechPaul
    Super Member
    • Total Posts : 2342
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: online
    Re: CDC_BASIC PIC24fj1024GB610 on board ex16/32 2019/07/21 19:44:53 (permalink)
    0
    Here are other macros from the HardwareProfile.h file:
    /** LED and Outputs **************************************************/
    #define mInitAllLEDs()      LATB &= 0x00; LATB |= 0x0B; TRISB &= 0x00; TRISB |= 0x08;  

    #define mLED_1              LATBbits.LATB0
    #define mLED_2              LATBbits.LATB1
    #define mLED_3              LATBbits.LATB2
    #define mPWR                LATBbits.LATB3

        #define mGetLED_1()         !mLED_1
        #define mGetLED_2()         !mLED_2
        #define mGetLED_3()         !mLED_3
        #define mGetPWR()           !mPWR

    #define mLED_1_On()         mLED_1 = 0;
    #define mLED_2_On()         mLED_2 = 0;
    #define mLED_3_On()         mLED_3 = 0;
    #define mPWR_On()             mPWR = 0;

    #define mLED_1_Off()        mLED_1 = 1;
    #define mLED_2_Off()        mLED_2 = 1;
    #define mLED_3_Off()        mLED_3 = 1;
    #define mPWR_Off()             mPWR = 1;

    #define mLED_1_Toggle()     mLED_1 = !mLED_1;
    #define mLED_2_Toggle()     mLED_2 = !mLED_2;
    #define mLED_3_Toggle()     mLED_3 = !mLED_3;


     
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5