USB HID + EXTERNAL INTERRUPT

GLCD Font Creator software is the ultimate solution to create personalized fonts, symbols and icons for Graphic LCDs. It generates code compatible with All mikroElektronika compilers
Post Reply
Author
Message
anu007
Posts: 5
Joined: 09 Sep 2015 06:16

USB HID + EXTERNAL INTERRUPT

#1 Post by anu007 » 05 Feb 2016 11:03

Hello i'm using pic18f4550 and i also use an external interrupt to change LCD display bu the code doesn't work. plzz help me :(

Code: Select all

  

void interrupt()
  {

   if(PIR2.USBIF==1)
   {
   USB_Interrupt_Proc();
   PIR2.USBIF=0;
   }
   
   if(INTCON.T0IF==1  )
   {
   SW++;
   INTCON.T0IF==0;
   return;
   }

  }
void INCurrent_Read()           //FIELD CURRENT
  {
   vdc1 = ADC_Read(0);
   Vdc1 = Vdc1*4.89;
   Vdc1 = Vdc1/10;
   message3[8]  = (vdc1/100) +48 ;
   message3[9]  = (vdc1/10)%10 + 48;
   message3[11] = (vdc1/1)%10+48;
  }
void OUTCurrent_Read()   //ARM CURRENT
  {
   vdc1 = ADC_Read(1);
   Vdc1 = Vdc1*4.89;
   Vdc1 = Vdc1/10;
   message4[8]  = (vdc1/100)%10 +48 ;
   message4[9]  = (vdc1/10)%10 + 48;
   message4[11] =  (vdc1)%10+48 ;
  }

void INVoltage_Read()
  {
   vdc1 = ADC_Read(2);
   Vdc1 = Vdc1*4.89;
   Vdc1 = Vdc1/10;
   message0[8] = (vdc1/100)%10 +48 ;
   message0[9] = (vdc1/10)%10 + 48;
   message0[10] =  (vdc1)%10+48 ;
  }

void OUTVoltage_Read()
 {
   vdc2 = ADC_Read(3);
   Vdc2 = Vdc2*4.89;
   Vdc2 = Vdc2/10;
   message1[8] = (vdc2/100)%10 +48 ;
   message1[9] = (vdc2/10)%10 + 48;
   message1[10] =  (vdc2)%10+48 ;
 }

void RPM_Measure()
 { T0CON =  0b01111000;
   TMR0L = 0;
   T0CON.TMR0ON = 1;
   delay_ms(250);
   T0CON.TMR0ON = 0;    // Stop the timer
   RPM = (TMR0L)*24.019;
   message2[4] = (RPM/1000)%10 +48 ;
   message2[5] = (RPM/100)%10 +48 ;
   message2[6] = (RPM/10)%10 + 48;
   message2[7] =  (RPM)%10+48 ;
 }
void main(void)
 {
  TRISA = 0b11111111;   // make PORTA all as input
  TRISB = 0b00000011;   // make PORTB all as output
  TRISD = 0b00000000;   // make PORTD C1-C4 as Output
  T0CON =  0b01111000;
  ADCON1 = 0b00001011;

  INTCON = 0b11010000;
  INTCON2.INTEDG0=0;
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Cmd(_LCD_CLEAR);
   while(1)
  {

    INCurrent_Read();
    OUTCurrent_Read();
    INVoltage_Read();
    OUTVoltage_Read();
    RPM_Measure();
    jump:

    if(SW==1)
    {
    Lcd_Out (1,1, message0);
    Lcd_Out (2,1, message3);
    }
    else if(SW==2)
    {
    Lcd_Out (1,1, message1);
    Lcd_Out (2,1, message4);
    }
    else if(SW==3)
    {
    Lcd_Out (1,1, message2);
    }
    else if(SW==4)
    {
    SW=1;
    goto jump;
    }
    
    for(cnt=0;cnt<3;cnt++)
    writebuff[0+cnt]=message0[8+cnt];
    for(cnt=0;cnt<3;cnt++)
    writebuff[3+cnt]=message1[8+cnt];
    for(cnt=0;cnt<4;cnt++)
    writebuff[6+cnt]=message2[4+cnt];
    for(cnt=0;cnt<4;cnt++)
    writebuff[10+cnt]=message3[8+cnt];
    for(cnt=0;cnt<4;cnt++)
    writebuff[14+cnt]=message4[8+cnt];
    for(cnt=18;cnt<64;cnt++)
    writebuff[cnt]=0;
           
    for(cnt=0;cnt<1;cnt++)
    {
      HID_Write(&writebuff,64);
    }
  }
 }

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: USB HID + EXTERNAL INTERRUPT

#2 Post by filip » 02 Sep 2016 09:34

Hi,

From your code I don't see that you are using external interrupt, only HID and Timer 0 interrupt. Could you please clarify your question ?

In the compiler's examples folder you will find examples for all of these interrupts, HID, Timer and External,
so you may use them as a starting point.

Also, I suggest that you try to debug the code using the mikroICD debugger, it is quite handy in these situations.

Regards,
Filip.

Post Reply

Return to “GLCD Font Creator Software”