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

PIC 18F4550 USB and LCD problem

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



Joined: 14 Feb 2013
Posts: 1
Location: Guatemala

View user's profile Send private message

PIC 18F4550 USB and LCD problem
PostPosted: Thu Feb 14, 2013 9:35 pm     Reply with quote

Hi everyone, I'm new in this.

I'm doing a USB connection but when I use the int_lcd(); the USB doesn’t enumerate. Also it shows me 3 warnings that disable all interrupts, the Problem is that I need to use the LCD and after I'll need to use the RS232 module.

I leave my code so someone could help me.

In advance thanks for all your help.

Warnings:
--------------------------
Interrupts disable during call to prevent re-entrancy: (usb_token_reset)
Interrupts disable during call to prevent re-entrancy: (usb_flush_out)
Interrupts disable during call to prevent re-entrancy: (usb_flush_in)

PIC CODE:

Code:

#include <18F4550.h>
#FUSES HSPLL, PLL5, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, CPUDIV1, VREGEN
#USE DELAY(CLOCK=48000000)

#define USB_HID_DEVICE     FALSE             //deshabilitamos el uso de las directivas HID
#define USB_EP1_TX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE    64                 //size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE    64                 //size to allocate for the rx endpoint 1 buffer



#include <pic18_usb.h>     //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
#include <PicWinUSB.h>         //Configuración del USB y los descriptores para este dispositivo
#include <usb.c>           //handles usb setup tokens and get descriptor reports

//#define use_portd_lcd TRUE //definir portb lcd
#include <lcd.c>

#BYTE PORTA  = 0x0F80                           // Registro del puerto A
#BYTE PORTB  = 0x0F81
#BYTE PORTD = 0xf83                           // Registro del puerto B
#BYTE PORTC = 0xf82

#BYTE TRISC = 0XF94

//#define USB_CON_SENSE_PIN PIN_B2

int8 dato[64];

void main()
{
 
   set_tris_A(0b111111);
   set_tris_B(0b00000000);
   TRISC=(0B00000000);
   //#use fast_io(B)
   //#use fast_io(D)
   //set_tris_d(0x00);

   portb=0b01000000;
   
   usb_init();                                  // inicializamos el USB
   usb_task();                                  // habilita periferico usb e interrupciones
   usb_wait_for_enumeration();                  // esperamos hasta que el PicUSB sea configurado por el host
   delay_ms(500);
   portb=0b10000000;
   
   lcd_init();
   //delay_us(50);//pausa
  // setup_adc(ADC_CLOCK_INTERNAL);//enables the a/d module                                                                   //and sets the clock to internal adc clo
  // setup_adc_ports(ALL_ANALOG);        //sets all the adc pins to analog
   while (TRUE)
   {
     
      if(usb_enumerated())                      // si el Pic está configurado via USB
      {
         if (usb_kbhit(1))                      // si el endpoint de salida contiene datos del host
         {
            usb_get_packet(1, dato, 64);        // cojemos el paquete de tamaño 8bytes del EP1 y almacenamos en dato
            portb = dato[0];// Se muestra al byte completo en el puerto
             //lcd_gotoxy(1,1);             //Vamos a la posicion 1 de la 1 linea
             //printf(lcd_putc, "Hola mun do" );
      //      set_adc_channel(0);                                //the next read_adc call will read channel 0
       //     dato[1]=read_adc();     
        //    set_adc_channel(1);                                //the next read_adc call will read channel 0
            dato[2]=25;
           // set_adc_channel(2);                                //the next read_adc call will read channel 0
            dato[3]=255;
            dato[4]=0;
            dato[5]=15;
            dato[6]=128;
            dato[7]=199;
           
            dato[1]=porta;
            usb_put_packet(1, dato, 64, USB_DTS_TOGGLE); // Send 2 byte packet to EP 1
       
         } 
      }
    }   
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Fri Feb 15, 2013 1:41 am     Reply with quote

First, the warnings, don't 'disable all interrupts'. They disable interrupts just for the duration of the individual calls in the external code. Now each of these calls is _tiny_ (literally a handful of instructions), and most need only be called once during the USB setup, or if the USB is being stopped, which is 'why' CCS elected not to worry about this. They are _warnings_ only. Something you may want to know about, but are probably not critical.
The only reason it'd not work, is that your lcd_init is hanging. This will happen, if you are using the handshake, and the LCD wiring has a problem.
Almost certainly the problem is that you have the LCD on PORTB, and you are not turning off the ADC on this port, and the chip defaults to enabling it on this port. Add the fuse NOPBADEN, which will change the behaviour so the ADC is off on PORTB by default.
usb_task, should be in your loop.

Best Wishes
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