mikroC USB and Proteus Simulation

General discussion on mikroC.
Post Reply
Author
Message
amrbekhit
Posts: 95
Joined: 05 Jul 2007 12:55
Contact:

mikroC USB and Proteus Simulation

#1 Post by amrbekhit » 03 Feb 2008 18:19

Hello all,

I was wondering whether anyone has managed to run their mikroC USB code using the Proteus USB simulation? My simulated circuit seems to work fine, but there doesn't seem to be any USB activity. The real hardware works fine as well, so I'm sure the code's fine.

--Amr

mbaser
Posts: 43
Joined: 02 Aug 2007 19:11
Location: Türkiye
Contact:

#2 Post by mbaser » 04 Feb 2008 11:14


amrbekhit
Posts: 95
Joined: 05 Jul 2007 12:55
Contact:

#3 Post by amrbekhit » 04 Feb 2008 14:07

Hi mbaser,

I already have the Proteus USB simulator. The issue is getting my mikroC firmware to work with the simulation. The screenshot shows what I'm getting at the moment.

Image

The LCD screen displays text, so it seems like the firmware is working fine. I guess the question to ask is, does anyone know if the mikroC USB firmware works with the Proteus USB simulation?

--Amr

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#4 Post by xor » 04 Feb 2008 16:36

There are methods using the HEX or making an MPLAB conversion of the mE ASM. Otherwise, mikroC is not on the supported compilers list:

http://www.labcenter.co.uk/products/compilers.cfm
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

mbaser
Posts: 43
Joined: 02 Aug 2007 19:11
Location: Türkiye
Contact:

#5 Post by mbaser » 04 Feb 2008 18:04

Image

Code: Select all

/*
 * Project name:
     HIDtest (Testing the USB HID connection)
 * Copyright:
     (c) MikroElektronika, 2005 - 2006
 * Revision History:
     20050502:
       - initial release;
 * Description:
     This example establishes connection with the HID terminal that is active
     on the PC. Upon connection establishment, the HID Device Name will appear
     in the respective window, and the software will start transmitting fixed
     message over the USB HID connection, for eternity.
 * Test configuration:
     MCU:             PIC18F2550
     Dev.Board:       EasyPIC2/EasyPIC3
     Oscillator:      HS 8.000 MHz  (USB osc. is raised with PLL to 48.000MHz)
     Ext. Modules:    USB-HID terminal board/None
     SW:              mikroC v6.0
 * NOTES:
     - Be VERY careful about the configuration flags for the 18F4550 - there's
       so much place for mistake!
*/


unsigned char k;
unsigned char userWR_buffer[64];

unsigned int df = 0 absolute 15;

const char *text = "Microchip Technology Inc.\r\n";


//**************************************************************************************************
// Main Interrupt Routine
//**************************************************************************************************
void interrupt()
{
  HID_InterruptProc();

}
//**************************************************************************************************




//**************************************************************************************************
// Initialization Routine
//**************************************************************************************************
void Init_Main()
{
	//--------------------------------------
	// Zabrana svih interapta
	//--------------------------------------
	INTCON = 0;                             // Disable GIE, PEIE, TMR0IE,INT0IE,RBIE
	INTCON2 = 0xF5;
	INTCON3 = 0xC0;
	RCON.IPEN = 0;                          // Disable Priority Levels on interrupts
	PIE1 = 0;
	PIE2 = 0;
	PIR1 = 0;
	PIR2 = 0;

	ADCON1 |= 0x0F;                         // Configure all ports with analog function as digital
	//--------------------------------------
	// Ports Configuration
	//--------------------------------------
	TRISA = 0xFF;
	TRISB = 0xFF;
	TRISC = 0xFF;
	//TRISD = 0;
	//TRISE = 0x07;

	LATA = 0;
	LATB = 0;
	LATC = 0;
	//LATD = 0;
	//LATE = 0;
	//--------------------------------------
	// Clear user RAM
	// Banks [00 .. 07] ( 8 x 256 = 2048 Bytes )
	//--------------------------------------

	
}
//**************************************************************************************************





//**************************************************************************************************
// Main Program Routine
//**************************************************************************************************

void main()
{ char i;
  Init_Main();

 HID_Enable((unsigned)&userWR_buffer,(unsigned)&userWR_buffer);
 Delay_mS(1000);
 Delay_mS(1000);
 while(1) {
 Delay_mS(1000);
  i=0;
  while(text[i]) {
    userWR_buffer[0]= text[i++];
    while (!HID_Write((unsigned)&userWR_buffer, 1));
    }
  }

  Delay_mS(1000);
  HID_Disable();
}
//**************************************************************************************************

amrbekhit
Posts: 95
Joined: 05 Jul 2007 12:55
Contact:

#6 Post by amrbekhit » 04 Feb 2008 20:33

Thanks for your replies, chaps.

@mbaser: Thanks for your code. I tried it out but unfortunately it still didn't work in the simulation. Have you had success in simulating mikroC USB code in Proteus?

@xor: I can accept that mikroC is not supported in terms of debugging capabilities, however, that should not stop Proteus from running the hex file. On the very same link you have in your post is the following quote:
All Proteus VSM processor models are able to run binary files (i.e. Intel or Motorola Hex files) produced by any assembler or compiler. However, the debugging facilities available are very limited since the processor model has no way to correlate the machine code it is executing with your original source program.
And I have found this to be true so far (USB excluded) - programs I write in mikroC work perfectly in Proteus.

I've done some more tests and have found some interesting results. I wrote the following USB test code:

Code: Select all

unsigned char read[64],write[64];

void interrupt(void)
{
	HID_InterruptProc();
}


void main(void)
{
	ADCON1=0x0F;
	CMCON=0x07;
	TRISA=0;
	PORTA=0;
	HID_Enable(&read,&write);

	while(1)
	{
		write[0]='A';
	     while(!HID_Write(write,1));
	    PORTA.RA0=~PORTA.RA0;
    	Delay_ms(500);
	}
}
Now, this software works perfectly on hardware - the LED flashes and the letter 'A' is sent via USB. The interesting thing is that if I load the hex file into Proteus, the LED on RA0 stays on constantly (it is meant to flash at 1Hz) and of course there is no USB activity in the simulation. What's even better is that if I remove all the USB code from the project, recompile and load it into Proteus, the simulation works fine, with the LED flashing as expected. So it seems like the USB code is causing problems with the Proteus simulation.

What I'd like to know is if there might be any difference between the USB code compiled using mikroC and mikroBasic. The reason why I ask this is due to this post. You can see a screenshot of his simulation, but what's interesting is the fact that the Proteus USB Transaction Analyzer has simulated USB activity on his PIC and Windows has even asked for a driver (although as the post states that shouldn't have happened).

As I don't have mikroBasic (and the demo limit is too short) I was wondering whether someone would be kind enough to rewrite my little test program in mikroBasic and email me the hex file so that I can test it? I'm using a PIC18F4550 and a 20Mhz crystal (PIC clock = 20Mhz, USB clock derived from 20MHz to produce 48MHz). My email address amrbekhit !!at! gmail !dot!! com

Thanks

--Amr

fvgm
Posts: 96
Joined: 30 Oct 2007 16:16
Location: Brazil

#7 Post by fvgm » 21 Jan 2009 13:28

hi amrbekhit

Did you get USB simulation work with mikroC's HEX files?
I cannot get this think to work, but all examples bundled with Proteus works.

Thanks.

amrbekhit
Posts: 95
Joined: 05 Jul 2007 12:55
Contact:

#8 Post by amrbekhit » 21 Jan 2009 13:36

Hi fvgm,

Unfortunately I haven't succeeded yet. :(

--Amr
[url=http://www.mikroe.com/forum/viewtopic.php?p=69489]mikroC USB Joystick[/url]
[url=http://helmpcb.com/software/usb-hid-template-for-visual-basic-2005]USB HID Template for Visual Basic 2005/2008/2010[/url]
[url=http://www.mikroe.com/forum/viewtopic.php?p=55958]Storing floats and other objects in EEPROM[/url]

fabim
Posts: 197
Joined: 18 Jan 2007 15:49

#9 Post by fabim » 21 Jan 2009 18:06

for hex works in usb simulation of proteus..

VID of the you project = microchip VID
PID ,,,,,,,,,,,,,,,,,,,,,,,,, = microchip PID"or other"
String ,,,,,,,,,,,,,,,,,,,,,, = microchio string

Speedy, only low speedy = USB 1.1

fvgm
Posts: 96
Joined: 30 Oct 2007 16:16
Location: Brazil

#10 Post by fvgm » 22 Jan 2009 18:24

hi, i can't get this thing to work.
I have created a new descriptor from HID Terminal, with these values:

VID - 04D8 (microchip vendor id)
PID - 0001 and others..

but it does not work with proteus simulation...
it give an error when GET_DESCRIPTOR_FROM_DEVICE[/img]

amrbekhit
Posts: 95
Joined: 05 Jul 2007 12:55
Contact:

#11 Post by amrbekhit » 22 Jan 2009 18:49

fabim, could you tell us which version of Proteus you are using? Also, could you post a copy of a working hex file?

Thanks

--Amr
[url=http://www.mikroe.com/forum/viewtopic.php?p=69489]mikroC USB Joystick[/url]
[url=http://helmpcb.com/software/usb-hid-template-for-visual-basic-2005]USB HID Template for Visual Basic 2005/2008/2010[/url]
[url=http://www.mikroe.com/forum/viewtopic.php?p=55958]Storing floats and other objects in EEPROM[/url]

fabim
Posts: 197
Joined: 18 Jan 2007 15:49

#12 Post by fabim » 22 Jan 2009 18:51

hehe, the drives is only USB 1.1!!
My proteus is version. 7.4 SP4.

mrfit
Posts: 11
Joined: 04 Nov 2009 10:48

#13 Post by mrfit » 04 Nov 2009 22:29

fabim so could u make it run on Proteus if so how? would appreciate ur help

prancius
Posts: 148
Joined: 26 Sep 2007 21:52

Can you post you project with proteus

#14 Post by prancius » 27 Nov 2009 21:27

Hello,

Can you attach your project? I am also working on usb via proteus.

Thank you
Pranas

07arunsharma
Posts: 46
Joined: 16 Apr 2011 14:37

Re: mikroC USB and Proteus Simulation

#15 Post by 07arunsharma » 09 Mar 2012 05:19

Are you getting any error when you put your code in Proteus uC,
If not then try this..

Pause the Simulation and then right click on PIC18 CPU and then Click on USB analyzer.

Hope this solve your problem.

Post Reply

Return to “mikroC General”