CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC87J50 and USB(SOLVED)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Jody



Joined: 08 Sep 2006
Posts: 182

View user's profile Send private message Send e-mail

PIC87J50 and USB(SOLVED)
PostPosted: Mon May 30, 2011 4:01 am     Reply with quote

Forgot the VUSB connection!!!!
FUSES:
Code:

#include <18F87J50.h>
#device ICD=TRUE
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES PLL12                     //Divide By 12(48MHz oscillator input)
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES NOCPUDIV
#FUSES NOPROTECT
#FUSES HSPLL
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOFCMEN
#FUSES NOIESO
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOEASHFT
#FUSES MSSPMSK7

#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=ID20)



Hello,

I had the CDC code running on a PIC18F4550.. and now I want to get it running at a PIC87J50...
But I am missing something....
I think I messed up the fuse settings... (PIC Wizard isn't helping much)
What I have:

Compiler version: 4.119
Fuses:
Code:

#include <18F87J50.h>
#device ICD=TRUE
#device adc=16

#FUSES ECPLL
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL12                     //Divide By 12(48MHz oscillator input)
#FUSES NOCPUDIV
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES DEBUG                    //Debug mode for use with ICD

#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=ID20)


and in mine code I enable the PLLEN:

Code:

#include <main.h>
#include <stdlib.h>
#include <string.h>
#include <input.c>
#include <M95160SPI.c>
#include <LCD_CCS.c>
#include <DS1302SPI.c>
// Includes all USB code and interrupts, as well as the CDC API
#include <usb_cdc.h>

#define SLOT         pin_H3   //Relais uitgang 1
#define START         pin_H6   //Digitale I/O bit0
#define LICHTSLUIS0   pin_H7   //Digitale I/O bit1
#define LICHTSLUIS1   pin_H5   //Digitale I/O bit2

int              string_ready            = 0;
signed int      next_in               = 0;
char            string[20];
char            string_lengte[8];
char            string_papagaai_teller[4];
char            RFID[5];
int16           addres                  = 0;
int8            teller                = 0;
int8            papagaai_teller         = 0;
int8            papa_teller            = 0;
int8            first                  = 1;
int8            lengte_string         = 0;
int8            i                     = 0;
int8            hr                     = 0;
int8            min                     = 0;
int8             sec                     = 0;
int8          data_eeprom            = 0;

#byte OSCTUNE = 0xF9B
#bit PLLEN = OSCTUNE.6


char   string1[6]    = "C820\0";//papagaainummer

#USE SPI (MASTER, SPI2, MODE=0, BITS=8, STREAM=SPI_2, MSB_FIRST)

#int_RDA
void  RDA_isr(void)
{
 string[next_in]=fgetc(ID20);
  if((string[next_in] == 0x0D) & (next_in > 1))   //Einde string
  {
    string_ready = 1;
    string[next_in+1] = '\0';
   next_in = 0;
  }
  next_in=(next_in+1);
  if(next_in > 20) next_in = 0;
}


void main()
{
   int8 data;
    int8 wrote;
    int16 addr;
    int16 errors = 0;

   setup_timer_1(T1_DISABLED);
      setup_timer_3(T3_INTERNAL|T3_DIV_BY_1);
      setup_timer_4(T4_DISABLED,0,1);
   setup_spi2(SPI_MASTER|SPI_XMIT_L_TO_H|SPI_SAMPLE_AT_MIDDLE|SPI_CLK_DIV_16);// test
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_RDA2);
   enable_interrupts(GLOBAL);

    PLLEN = 1;    // Enable PLL
   delay_ms(50);

   usb_cdc_init();
   usb_init();

     init_ext_eeprom();
      lcd_init();
      delay_ms(50);
      output_low(SLOT);// van het slot af...

   lcd_gotoxy(1,1);
    printf(lcd_putc, "Papagaaiendeur");

  for(teller = 0; teller < 45; teller++)
  {
    string[teller] = ' ';
  }
  next_in = 0;

   while(1)
   {
       usb_task();
       if (usb_enumerated())
       {
   lcd_gotoxy(1,1);
   printf(lcd_putc, "USB enumerated!");
         }

         if(string_ready == 1)
            {
            printf(usb_cdc_putc,"string = ");
            printf(usb_cdc_putc,string);
            lengte_string = strlen(string);//lengte van de ontvangen string
            itoa(lengte_string, 10, string_lengte);// omzetten naar een string
            printf(usb_cdc_putc,string_lengte);// afbeelden
            printf(usb_cdc_putc,"\n");

            RFID[0] = string[(lengte_string-5)];
            RFID[1] = string[(lengte_string-4)];
            RFID[2] = string[(lengte_string-3)];
            RFID[3] = string[(lengte_string-2)];
            RFID[4] = '\0';
            printf(usb_cdc_putc,"RFID = ");
            printf(usb_cdc_putc,RFID);

              string_ready    = 0;
              next_in       = 0;
            lengte_string    = 0;

              for(teller = 0; teller < 20; teller++)
              {
                string[teller] = ' ';
              }

               if((strcmp(RFID, string1))==0)
               {
                    output_high(SLOT);// deur open
               }
               if(input(LICHTSLUIS0))// deur open gedaan
               {
                  papagaai_teller = papagaai_teller + 1;
                  rtc_get_time(hr,min,sec);
                  write_ext_eeprom(addres,hr);addres++;
                  write_ext_eeprom(addres,min);addres++;
                  write_ext_eeprom(addres,sec);addres++;
                  write_ext_eeprom(addres,papagaai_teller);addres++;
                  delay_ms(50);
                  papa_teller   = read_ext_eeprom(0x000);
                  itoa(papa_teller, 10, string_papagaai_teller);// omzetten naar een string
                  printf(usb_cdc_putc,"papagaai_teller_eeprom = ");
                  printf(usb_cdc_putc,string_papagaai_teller);   
                  printf(usb_cdc_putc,"\n");
                  first = 0;
               }
            }
      }
   }
}


anybody any ideas?????

Regards,
Jody
Code:
Code:
Code:
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Mon May 30, 2011 7:59 am     Reply with quote

Is this solved?.
Thread title says so.

I have to ask 'why' you are using 48MHz?. Unless it is available elsewhere for some reason, you get less RF problems, and lower power consumption, running off a slower clock.
However with 48MHz, the combination you are trying to use is 'over complex'.
You have 48MHz, so don't need the PLL.

EC
FOSC2=1
PLLEN=0
FSEN=1
gives 48MHz to the USB.

Then CPUDIV1, and primary clock source enabled, gives 48MHz to the CPU.
You are unnecessarily taking 48MHz, dividing it by 12, multiplying by 24, and then dividing by 2. All extra power that is not needed.....


Best Wishes
Jody



Joined: 08 Sep 2006
Posts: 182

View user's profile Send private message Send e-mail

PostPosted: Mon May 30, 2011 8:03 am     Reply with quote

@Ttelmah,

You are right... it is a overkill and not charming to do this, this way.

And I will change it like the way you sugest... but the problem was that I can't connect to the USB ... and that is solved.

Thanks for thinking with me.

Regards,
Jody
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group