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 support@ccsinfo.com

18F26J50 - Usb not work

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



Joined: 16 Jul 2008
Posts: 8
Location: Mexico

View user's profile Send private message

18F26J50 - Usb not work
PostPosted: Thu May 30, 2013 12:09 pm     Reply with quote

Usb not work why ??
Fuses ?

Code:

#include <18F26J50.h>
#device adc=16

#FUSES HSPLL                    //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PLL2
//#FUSES CPUDIV2
#FUSES NOCPUDIV

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES PROTECT                  //Code not protected from reading
//#FUSES T1DIG
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOIESO                   //Internal External Switch Over mode enabled
/*
#FUSES DSWDTOSC_INT         
#FUSES NODSBOR               
#FUSES NODSWDT               
#FUSES DSWDT2               
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES MSSPMSK7             
#FUSES NOWPFP               
#FUSES WPBEG               
#FUSES NOWPCFG             
#FUSES WPDIS
*/
#FUSES RTCOSC_INT // RTC internal clock
//#FUSES RTCOSC_T1


#use delay(clock=48M, crystal=8M)

#use rs232(baud = 9600, parity = N, xmit = PIN_C6, rcv = PIN_C7, stream = SERIAL, errors)

//------------------------------------------------------------------------------

#define USB_CONFIG_HID_TX_SIZE   8
#define USB_CONFIG_HID_RX_SIZE   8

#include <pic18_usb.h>
#include <usb_desc_hid.h>
#include <usb.c>

//------------------------------------------------------------------------------

#define  Led   PIN_A0

//------------------------------------------------------------------------------

#byte OSCCON = 0xFD3
#byte UCFG  = 0xF39
#byte OSCTUNE= 0xF9B

#byte PORTA = 0xF80
#byte PORTB = 0xF81
#byte PORTC = 0xF82

#byte LATA  = 0xF89
#byte LATB  = 0xF8A
#byte LATC  = 0xF8B

//------------------------------------------------------------------------------

//include <KEYPAD.c>

//------------------------------------------------------------------------------

#define Led_On(x) output_low(x)
#define Led_Off(x) output_high(x)

//------------------------------------------------------------------------------
   
   int8 out_data[USB_CONFIG_HID_TX_SIZE];
   int8 in_data[USB_CONFIG_HID_RX_SIZE];

   int1 modo_teste;

//------------------------------------------------------------------------------
void usb_debug_task(void) {
   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;

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

   if (new_enumerated)
      Led_On(Led);
   else
      Led_Off(Led);

   if (new_connected && !last_connected)
      fprintf(SERIAL, "\nUSB ON");

   if (!new_connected && last_connected)
      fprintf(SERIAL, "\nUSB OFF");

   if (new_enumerated && !last_enumerated) {
      fprintf(SERIAL, "\nUSB OK\n");
     
      Led_On(Led);
   } else {
      Led_Off(Led);
   }
     
   if (!new_enumerated && last_enumerated) fprintf(SERIAL, "\nUSB STB");

   last_connected = new_connected;
   last_enumerated = new_enumerated;
}

//------------------------------------------------------------------------------
void make_all_pins_digital(void) {
   #byte ANSELA = 0xF38
   #byte ANSELB = 0xF39
   #byte ANSELC = 0xF3A
   
   ANSELA = 0;
   ANSELB = 0;
   ANSELC = 0;
}

//------------------------------------------------------------------------------
void configurar() {   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED, 0, 1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);   
 
   //setup_oscillator(OSC_PLL_ON);

   port_b_pullups(true);
     
   make_all_pins_digital();

   LATA = 0;
   LATB = 0;
   LATC = 0;

   PORTA = 0;
   PORTB = 0;
   PORTC = 0;

   set_tris_a(0b00000000);
   set_tris_b(0b11110000);   
   set_tris_c(0b10000000);

   //enable_interrupts(INT_EXT);
   //enable_interrupts(INT_RB);
   //enable_interrupts(INT_RDA);
   //enable_interrupts(INT_RDA2);
   
   //ext_int_edge(2, H_TO_L);   
   //enable_interrupts(INT_EXT2);   
}


usb not work

Code:

//------------------------------------------------------------------------------
void main(void) {
   int8 i, sec_old;
   char acao, letra;
   
   memset(in_data, 0x00, USB_CONFIG_HID_RX_SIZE);
   memset(out_data, 0x00, USB_CONFIG_HID_TX_SIZE);     

   configurar(); 

   usb_init_cs();

   while (1)  {
      usb_task();
      usb_debug_task();
     
      if (usb_enumerated())  {
         if (usb_kbhit(1)) {
            usb_get_packet(1, in_data, USB_CONFIG_HID_RX_SIZE);
           
            out_data[0] = in_data[0];
                       
            if (usb_put_packet(1, out_data, USB_CONFIG_HID_TX_SIZE, USB_DTS_TOGGLE)) {
               fprintf(SERIAL, "%c\n", out_data[0]);
            }
         }
      }     
   }
}



work 100%

Code:

//------------------------------------------------------------------------------
void main(void) {
   int8 i, sec_old;
   char acao, letra;
   rtc_time_t SetTime;
   rtc_time_t read_clock;
   
   memset(in_data, 0x00, USB_CONFIG_HID_RX_SIZE);
   memset(out_data, 0x00, USB_CONFIG_HID_TX_SIZE);     

   configurar(); 

   Led_On(Led);
   delay_ms(1000);
   Led_Off(Led);

   modo_teste = 0;

   //enable_interrupts(INT_RDA);
   //enable_interrupts(GLOBAL);
 

   setup_rtc(RTC_ENABLE, 2);
   //setup_rtc(RTC_ENABLE | RTC_OUTPUT_SECONDS, 0x00);
   
   SetTime.tm_year = 13;
   SetTime.tm_mon  = 1;
   SetTime.tm_mday = 1;
   SetTime.tm_wday = 1;
   SetTime.tm_hour = 0;
   SetTime.tm_min  = 0;
   SetTime.tm_sec  = 0;   
   rtc_write(&SetTime);
   

   enable_interrupts(INT_RTC);
   enable_interrupts(GLOBAL);
   
   
   fprintf(SERIAL, "START\n");
   
   sec_old = read_clock.tm_sec;
   
   while(1) {
      rtc_read(&read_clock);
     
      if (sec_old != read_clock.tm_sec) {
         sec_old = read_clock.tm_sec;
         
         printf("\n\%02u:%02u:%02u", read_clock.tm_hour, read_clock.tm_min, read_clock.tm_sec);
      }
   }   
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 30, 2013 6:12 pm     Reply with quote

Quote:

void make_all_pins_digital(void) {
#byte ANSELA = 0xF38
#byte ANSELB = 0xF39
#byte ANSELC = 0xF3A

ANSELA = 0;
ANSELB = 0;
ANSELC = 0;
}

There are no ANSELx registers in the 18F26J50. Check the data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39931d.pdf
The first two addresses you use above are actually the addresses of the
UADDR and UCFG registers. So if you write 0 to them, you are
over-writing the USB configuration registers.

If you want all digital inputs, the following line will do it, in a current
version of the CCS compiler:
Code:
setup_adc_ports(NO_ANALOGS);


But in current versions of the compiler, you don't even need to do that,
because the compiler makes all analog pins into digital pins, in the
startup code that it inserts at the beginning of main().
mpardinho



Joined: 16 Jul 2008
Posts: 8
Location: Mexico

View user's profile Send private message

PostPosted: Fri May 31, 2013 11:49 am     Reply with quote

I update my code .... but not work
i think the code is ok

3,3v, 470pf .. all ok
in the same protoboard with 5v and simple code, 18f2550 ok




Code:


#include <18F26J50.h>
#device adc=16

#FUSES HSPLL                    //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PLL2
//#FUSES CPUDIV2
#FUSES NOCPUDIV

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES PROTECT                  //Code not protected from reading
//#FUSES T1DIG
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOIESO                   //Internal External Switch Over mode enabled
/*
#FUSES DSWDTOSC_INT         
#FUSES NODSBOR               
#FUSES NODSWDT               
#FUSES DSWDT2               
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES MSSPMSK7             
#FUSES NOWPFP               
#FUSES WPBEG               
#FUSES NOWPCFG             
#FUSES WPDIS
*/
#FUSES RTCOSC_INT // RTC internal clock
//#FUSES RTCOSC_T1


#use delay(clock=8M)

#use rs232(baud = 9600, parity = N, xmit = PIN_C6, rcv = PIN_C7, stream = SERIAL, errors)

//------------------------------------------------------------------------------

#define USB_CONFIG_HID_TX_SIZE   8
#define USB_CONFIG_HID_RX_SIZE   8

#include <pic18_usb.h>
#include <usb_desc_hid.h>
#include <usb.c>

//------------------------------------------------------------------------------

#define  Led   PIN_A0

//------------------------------------------------------------------------------

#define Led_On(x) output_low(x)
#define Led_Off(x) output_high(x)

//------------------------------------------------------------------------------
   
   int8 out_data[USB_CONFIG_HID_TX_SIZE];
   int8 in_data[USB_CONFIG_HID_RX_SIZE];

   int1 modo_teste;

//------------------------------------------------------------------------------
void usb_debug_task(void) {
   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;

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

   if (new_enumerated)
      Led_On(Led);
   else
      Led_Off(Led);

   if (new_connected && !last_connected)
      fprintf(SERIAL, "\nUSB ON");

   if (!new_connected && last_connected)
      fprintf(SERIAL, "\nUSB OFF");

   if (new_enumerated && !last_enumerated) {
      fprintf(SERIAL, "\nUSB OK\n");
     
      Led_On(Led);
   } else {
      Led_Off(Led);
   }
     
   if (!new_enumerated && last_enumerated) fprintf(SERIAL, "\nUSB STB");

   last_connected = new_connected;
   last_enumerated = new_enumerated;
}

//------------------------------------------------------------------------------
void main(void) {
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED, 0, 1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);   
 
   setup_oscillator(OSC_PLL_ON);

   port_b_pullups(true);
     
   set_tris_a(0b00000000);
   set_tris_b(0b11110000);   
   set_tris_c(0b10000000);


   memset(in_data, 0x00, USB_CONFIG_HID_RX_SIZE);
   memset(out_data, 0x00, USB_CONFIG_HID_TX_SIZE);     

   
   usb_init_cs();

   while (1)  {
      usb_task();
      usb_debug_task();
     
      if (usb_enumerated())  {
         if (usb_kbhit(1)) {
            usb_get_packet(1, in_data, USB_CONFIG_HID_RX_SIZE);
           
            out_data[0] = in_data[0];
                       
            if (usb_put_packet(1, out_data, USB_CONFIG_HID_TX_SIZE, USB_DTS_TOGGLE)) {
               fprintf(SERIAL, "%c\n", out_data[0]);
            }
         }
      }     
   }
}

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