Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic18f4550 + usb_cdc+ pic c

Status
Not open for further replies.

lordmag

Junior Member level 3
Joined
Nov 9, 2010
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,446
HI
My project objective is to simulate the statue of contact which are the input of the 18F4550 pic
my input contact will from D0_pin to E2_pin
so that i want to build a sequence of bits or a charactere like 100011001 and send it to the PC from the USB connector
1= contact close
0= contact open

my problem here is haw can i establish my USB connction to the PC and where can i found that sequence
this will be my isis simulator circuit
Sans titre.png
 

this is my code pic c
Code:
#define __USB_PIC_PERIF__ 1

#if !defined(__PCH__)
#error USB CDC Library requires PIC18
#endif

#if __USB_PIC_PERIF__
 #DEFINE LED1  PIN_A1
 #include <18F4550.h>
 #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN

//#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,CPUDIV1,VREGEN

 #use delay(clock=48000000)
#else 
 #DEFINE LED1  PIN_a1
 #include <18F452.h>
 #fuses HS,NOWDT,NOPROTECT,NOLVP
 #use delay(clock=20000000)
#endif   //endif check to see which peripheral to use

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#if __USB_PIC_PERIF__ && defined(__PCH__)
 #define USB_CON_SENSE_PIN PIN_c2
#endif

#include <usb_cdc.h>

char d0,d1,d2,d3,d4,d5,d6,d7,e0,e1,e2;

void usb_debug_task(void) {
   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;
   static int8 last_cdc;
   int8 new_cdc;

   new_connected=usb_attached();
   new_enumerated=usb_enumerated();
   new_cdc=usb_cdc_connected();


   if (new_connected && !last_connected)
      printf("USB connected, waiting for enumaration...\r\n\n");
   if (!new_connected && last_connected)
      printf("USB disconnected, waiting for connection...\r\n\n");
   if (new_enumerated && !last_enumerated)
      printf("USB enumerated by PC/HOST\r\n\n");
   if (!new_enumerated && last_enumerated)
      printf("USB unenumerated by PC/HOST, waiting for enumeration...\r\n\n");
   if (new_cdc && !last_cdc) {
      printf("Serial program initiated on USB<->UART COM Port\r\n\n");
      printf(usb_cdc_putc, "\r\n\n USB connected....\r\n\n");
   }

   last_connected=new_connected;
   last_enumerated=new_enumerated;
   last_cdc=new_cdc;
}

void main(void) {
d0=0;
d1=0;
d2=0;
d3=0;
d4=0;
d5=0;
d6=0;
d7=0; 
e0=0;
e1=0;
e2=0;



  #ifdef __PCH__
   printf("PCH: v");
   printf(__PCH__);
  #else
   printf("PCM: v");l,l
   printf(__PCM__);
  #endif
   printf("\r\n");

   usb_init_cs();

  #if !(__USB_PIC_PERIF__)
   printf("USBN: 0x%X", usbn_get_version());
   printf("\r\n\n");
  #endif
       

 

   while (TRUE) {
  
      usb_task();
      usb_debug_task();
      
      
                 if (input(PIN_D0))
                    {
                       d0=1;
                    }
                      else
                    {
                       d0=0;
                    }
                if (input(PIN_D1))
                    {
                       d1=1;
                    }
                      else
                    {
                       d1=0;             
                    }
                if (input(PIN_D2))
                    {
                       d2=1;
                    }
                      else
                    {
                       d2=0;
                    }
                if (input(PIN_D3))
                    {
                       d3=1;
                    }
                     else
                    {
                       d3=0;
                    }
               if (input(PIN_D4))
                    {
                       d4=1;
                    }
                     else
                    {
                       d4=0;
                    }   
               if (input(PIN_D5))
                    {
                       d5=1;
                    }
                      else
                    {
                       d5=0;
                    }
               if (input(PIN_D6))
                    {
                        d6=1;
                    }
                      else
                    {
                        d6=0;
                    } 
               if (input(PIN_D7))
                    {
                        d7=1;
                    }
                else
                    {
                        d7=0;
                     }
               if (input(PIN_E0))
                    {
                         e0=1;
                    }
                else
                    {
                         e0=0;
                    }
              if (input(PIN_E1))
                    {
                         e1=1;
                    }
                 else
                   {
                         e1=0;
                    } 
               if (input(PIN_E2))
                    {
                        e2=1;
                    }
                else
                    {
                        e2=0;
                    }          
}
      
        
       printf(usb_cdc_putc,"%c %c %c %c %c %c %c %c %c %c %c\n\r",d0,d1,d2,d3,d4,d5,d6,d7,e0,e1,e2);          
 }

which line i should delete and wich one i should keep it

---------- Post added at 02:46 ---------- Previous post was at 02:41 ----------

please take a look to my project and tell me what can i do :)
in this link you will find my isis circuit and my PIC C code
https://http://www.ziddu.com/download/19173508/essai2.rar.html
 

the isis circuit ESSAI1
THE pic c code ESSAI3
 

Attachments

  • essai 2.rar
    133.9 KB · Views: 49

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top