|
|
View previous topic :: View next topic |
Author |
Message |
rao
Joined: 03 Oct 2010 Posts: 10 Location: Pune
|
Newbie Looking for Help CCS4.110 and PIC18F4550 |
Posted: Sun Oct 03, 2010 5:30 am |
|
|
Guys I am a newbie with microcontrollers particularly the microchip and obviously new to CCS, here is a code that I am trying to compile, and I keep getting warning 203 messages:
Code: |
while(1)
{
usb_task();
usb_isr();
if(DelayCount)
continue;
if(Connect)
{
if(UADDR!=HubAddress)
usb_set_address(HubAddress);
puts("Connect!");
DevicePort=Connect;
port_status[Connect-1] = PORT_FULL;
port_change[Connect-1] = C_PORT_CONN;
TxBuf[0]=1<<Connect;
if(Force0DTS)
usb_put_packet(1,TxBuf,1,0);
else
usb_put_packet(1,TxBuf,1,USB_DTS_TOGGLE);
Connect=0;
Force0DTS=0;
}
if(Reset)
{
puts("Reset!");
TxBuf[0]=1<<Reset;
usb_put_packet(1,TxBuf,1,USB_DTS_TOGGLE);
Reset=0;
}
if(Disconnect)
{
if(UADDR!=HubAddress)
usb_set_address(HubAddress);
puts("Disconnect!");
DevicePort=Disconnect;
port_status[Disconnect-1] = PORT_EMPTY;
port_change[Disconnect-1] = C_PORT_CONN;
TxBuf[0]=1<<Disconnect;
usb_put_packet(1,TxBuf,1,USB_DTS_TOGGLE);
Disconnecting=Disconnect;
Disconnect=0;
}
if(WaitJig)
{
if(WaitJig==1)
{
if(usb_kbhit(2))
{
unsigned char c;
puts("JIG!");
Chirp();
c=usb_get_packet(2,TxBuf,8);
nJigs++;
EP_BDxST_I(1) = 0x40; //Clear IN endpoint
if(nJigs==8)
{
nJigs=0;
WaitJig=2;
Delay10ms(50);
}
}
}
else
{
int n=0;
for(n=0;n<8;++n)
TxBuf[n]=jig_response[8*nJigs+n];
if(usb_put_packet(1,TxBuf,8,nJigs==0?0:USB_DTS_TOGGLE))
{
puts("DJIG");
Delay10ms(1);
nJigs++;
Chirp();
if(nJigs==8)
{
nJigs=0;
WaitJig=0;
Delay10ms(15);
Disconnect=3;
}
}
}
}
if(Address!=-1)
{
printf("Address %X",Address);
usb_set_address(Address);
Address=-1;
}
}
}
|
And I keep getting warning messages:
Warning 203:"C:\.....\PICC\Devices\pic18_usb.c"Line531(1,1):Condition always TRUE
Warning 203:"C:\.....\PICC\Devices\usb.c"Line576(1,1): Condition always TRUE
Warning 203:"main.c"Line389(1,1): Condition always TRUE
I cannot seem to compile the code despite changing computers and searching on the net has resulted nothing.
Any help will be highly appreciated. |
|
|
MiniMe
Joined: 17 Nov 2009 Posts: 50
|
|
Posted: Sun Oct 03, 2010 6:46 am |
|
|
Seems code you presented is missing main() { like. I assume you got it. Sometimes ig you have syntax ... program structure mistake ( missing { or ; maybe) you will get many errors.
If you see warnings only (no errors) you should get program compiled in .hex file. Warning are there to inform you and point your attentions to situations where problems might start... For example in your case While(TRUE) warning is infinite loop where program might get stuck. I believe it is not a problem in your case because it was intended to be so.
You can find program file, a compiled program, .hex file in your project folder. Folder which might be tricky to find. |
|
|
rao
Joined: 03 Oct 2010 Posts: 10 Location: Pune
|
|
Posted: Sun Oct 03, 2010 7:05 am |
|
|
Code: |
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
usb_init();
output_bit(LEDR,1);
set_timer0(0x8ad0);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER0);
puts("Init");
for(;;)
{
usb_task();
usb_isr();
if(DelayCount)
continue;
if(Connect)
{
if(UADDR!=HubAddress)
usb_set_address(HubAddress);
puts("Connect!");
DevicePort=Connect;
port_status[Connect-1] = PORT_FULL;
port_change[Connect-1] = C_PORT_CONN;
TxBuf[0]=1<<Connect;
if(Force0DTS)
usb_put_packet(1,TxBuf,1,0);
else
usb_put_packet(1,TxBuf,1,USB_DTS_TOGGLE);
Connect=0;
Force0DTS=0;
}
if(Reset)
{
puts("Reset!");
TxBuf[0]=1<<Reset;
usb_put_packet(1,TxBuf,1,USB_DTS_TOGGLE);
Reset=0;
}
if(Disconnect)
{
if(UADDR!=HubAddress)
usb_set_address(HubAddress);
puts("Disconnect!");
DevicePort=Disconnect;
port_status[Disconnect-1] = PORT_EMPTY;
port_change[Disconnect-1] = C_PORT_CONN;
TxBuf[0]=1<<Disconnect;
usb_put_packet(1,TxBuf,1,USB_DTS_TOGGLE);
Disconnecting=Disconnect;
Disconnect=0;
}
if(WaitJig)
{
if(WaitJig==1)
{
if(usb_kbhit(2))
{
unsigned char c;
puts("JIG!");
Chirp();
c=usb_get_packet(2,TxBuf,8);
nJigs++;
EP_BDxST_I(1) = 0x40; //Clear IN endpoint
if(nJigs==8)
{
nJigs=0;
WaitJig=2;
Delay10ms(50);
}
}
}
else
{
int n=0;
for(n=0;n<8;++n)
TxBuf[n]=jig_response[8*nJigs+n];
if(usb_put_packet(1,TxBuf,8,nJigs==0?0:USB_DTS_TOGGLE))
{
puts("DJIG");
Delay10ms(1);
nJigs++;
Chirp();
if(nJigs==8)
{
nJigs=0;
WaitJig=0;
Delay10ms(15);
Disconnect=3;
}
}
}
}
if(Address!=-1)
{
printf("Address %X",Address);
usb_set_address(Address);
Address=-1;
}
}
}
|
Sorry forgot to post the main loop here it is.
Anyways I have the compiled hex file, but since I am trying to learn, and thats why I posted here at this forum, where I think people are much more helpful.
With the precompiled hex file when I load the file in "PDFSUSB" the code starts from "000800" whereas the one which I generate with warnings the code starts from "2C41DF0", and when I burn the generated file on the PIC it simply doesnt execute the program, whereas with the precompiled version the code executes perfectly.
Last edited by rao on Mon Oct 04, 2010 2:32 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Sun Oct 03, 2010 10:07 am |
|
|
Post the header you are using.
Loading at the wrong address, would be a header problem, not a code problem.
Ignoring anything else, if the fuses are set correctly, and the RS232 statement is properly declared in your header, then you should get 'Init' out the RS232. If this is not happening, then there is something wrong in the header.
Then, learn to debug.
When you have problems, start with the basics, then expand. In your case, a half dozen line program that just displays the 'Init', and does nothing else, would prove that your header is OK, and the RS232 is OK.
Only once this is working, add the first part of the USB, to check if it is enumerated. If it is, output another message.
Again, once this is working, add the next section. etc. etc..
Best Wishes |
|
|
rao
Joined: 03 Oct 2010 Posts: 10 Location: Pune
|
|
Posted: Sun Oct 03, 2010 10:42 am |
|
|
@Ttlemah
Thanks for the kind reply and suggestions, I'l keep your suggestions in mind while learning CCS programming over the period of time. Meanwhile here is rest of the code
Code: |
#include <18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,NOBROWNOUT,USBDIV,PLL2,CPUDIV1,VREGEN,PUT,MCLR
#use delay(clock=48000000)
#use rs232(baud=115200, xmit=pin_c6, rcv=pin_c7)
#define LEDR PIN_B4
/////////////////////////
// Bootloader Memory Space
// Microchip USB HID Bootloader
#define CODE_START 0x0800
#build(reset=CODE_START, interrupt=CODE_START+0x08)
#org 0, CODE_START-1 {}
/////////////////////////
#define USB_MAX_NUM_INTERFACES 1
#define USB_HID_DEVICE FALSE
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT
#define USB_EP1_TX_SIZE 8
#define USB_EP2_RX_ENABLE USB_ENABLE_INTERRUPT
#define USB_EP2_RX_SIZE 8
#include "usb.h"
#include "usb_desc.h"
#define __USB_DESCRIPTORS__
unsigned char USB_NUM_INTERFACES[1]={1};
char const USB_STRING_DESC[]={5,USB_DESC_STRING_TYPE,'H',0,'O',0,'L',0,'A',0,};
#include "pic18_usb.h"
#include "pic18_usb.c"
#include "usb.c"
unsigned char BlinkMode=0;
unsigned char cnt=0;
unsigned char led1=0;
unsigned char DelayCount=0;
#int_timer0
void timer()
{
set_timer0(0x8ad0);
if(DelayCount)
--DelayCount;
if(BlinkMode==0) //blink
{
if(cnt==20)
{
led1=!led1;
output_bit(LEDR,led1);
cnt=0;
}
else
cnt++;
}
if(BlinkMode==2) //chirp
{
if(!cnt)
{
output_bit(LEDR,0);
}
else
cnt--;
}
}
char Connect=0;
char Reset=0;
char Disconnect=0;
char Disconnecting=0;
char Address=-1;
char DevicePort=0;
char WaitJig=0;
char nJigs=0;
char Force0DTS=0;
unsigned char HubAddress;
unsigned char TxBuf[8];
#define PORT_EMPTY 0x0100
#define PORT_FULL 0x0103
#define C_PORT_CONN 0x0001
#define C_PORT_RESET 0x0010
#define C_PORT_NONE 0x0000
unsigned int16 port_status[6] = { PORT_EMPTY, PORT_EMPTY, PORT_EMPTY, PORT_EMPTY, PORT_EMPTY, PORT_EMPTY };
unsigned int16 port_change[6] = { C_PORT_NONE, C_PORT_NONE, C_PORT_NONE, C_PORT_NONE, C_PORT_NONE, C_PORT_NONE };
void Chirp()
{
cnt=2;
output_bit(LEDR,1);
}
void Delay10ms(unsigned char delay)
{
DelayCount=delay;
}
void Hub_SetFeature(unsigned char feature,unsigned char port)
{
Chirp();
if(feature==8)
{
HubAddress=UADDR;
printf("PORT_POWER %X\r\n",port);
if(port==6)
{
Connect=1;
}
}
else if(feature==4)
{
printf("PORT_RESET %X\r\n",port);
port_change[port-1]|=C_PORT_RESET;
Reset=port;
Delay10ms(2);
}
else
printf("SF %X %X\r\n",feature,port);
}
void Hub_ClearFeature(unsigned char feature,unsigned char port)
{
Chirp();
if(feature==0x10)
{
printf("C_PORT_CONN %X\r\n",port);
port_change[port-1]&=~C_PORT_CONN;
if(Disconnecting)
{
if(Disconnecting==2)
{
Connect=4;
Delay10ms(15);
}
else if(Disconnecting==3)
{
Disconnect=5;
Delay10ms(20);
}
else if(Disconnecting==5)
{
Disconnect=4;
Delay10ms(20);
}
else if(Disconnecting==4)
{
Disconnect=1;
Delay10ms(20);
}
else if(Disconnecting==1)
{
Connect=6;
Delay10ms(20);
}
Disconnecting=0;
}
}
else if(feature==0x14)
{
printf("C_PORT_RESET %X\r\n",port);
port_change[port-1]&=~C_PORT_RESET;
Address=0;
}
else
printf("CF %X %X\r\n",feature,port);
}
void Hub_GetStatus(unsigned char port,unsigned char *buf)
{
Chirp();
printf("Sta %X",port);
buf[0]=port_status[port-1]&0xFF;
buf[1]=port_status[port-1]>>8;
buf[2]=port_change[port-1]&0xFF;
buf[3]=port_change[port-1]>>8;
}
int16 GetDevicePointer()
{
Chirp();
printf("Device %X", DevicePort);
if(DevicePort==0)
return HUB_DEVICE_OFFSET;
else if(DevicePort==1)
return PORT1_DEVICE_OFFSET;
else if(DevicePort==2)
return PORT2_DEVICE_OFFSET;
else if(DevicePort==3)
return PORT3_DEVICE_OFFSET;
else if(DevicePort==4)
return PORT4_DEVICE_OFFSET;
else if(DevicePort==5)
return PORT5_DEVICE_OFFSET;
else if(DevicePort==6)
return PORT6_DEVICE_OFFSET;
printf("ErrorDevice");
}
int16 GetDeviceLength()
{
return 0x12;
}
int16 GetConfigPointer(unsigned char nConfig,char shortConfig)
{
Chirp();
printf("Config %X %X %X",DevicePort,nConfig,shortConfig);
if(DevicePort==0)
{
BlinkMode=2;
return HUB_CONFIG_OFFSET;
}
else if(DevicePort==1)
{
if(shortConfig)
{
return PORT1_SHORT_CONFIG_OFFSET;
}
else
{
if(nConfig==3 && !shortConfig)
{
Delay10ms(10);
Connect=2;
}
return PORT1_CONFIG_OFFSET;
}
}
else if(DevicePort==2)
{
if(!shortConfig)
{
Delay10ms(15);
Connect=3;
}
return PORT2_CONFIG_OFFSET;
}
else if(DevicePort==3)
{
if(!shortConfig)
{
Delay10ms(10);
Disconnect=2;
}
return PORT3_CONFIG_OFFSET;
}
else if(DevicePort==4)
{
if(nConfig==0)
{
return PORT4_CONFIG_1_OFFSET;
}
else if(nConfig==1)
{
if(shortConfig)
return PORT4_SHORT_CONFIG_2_OFFSET;
else
return PORT4_CONFIG_2_OFFSET;
}
else if(nConfig==2)
{
if(!shortConfig)
{
Delay10ms(20);
Connect=5;
Force0DTS=1;
}
return PORT4_CONFIG_3_OFFSET;
}
}
else if(DevicePort==5)
{
puts("wjig");
WaitJIG=1;
nJigs=0;
return PORT5_CONFIG_OFFSET;
}
else if(DevicePort==6)
{
return PORT6_CONFIG_OFFSET;
}
printf("ErrorConfig");
}
int16 GetConfigLength(unsigned char nConfig,char shortConfig)
{
if(DevicePort==0)
return HUB_CONFIG_SIZE;
else if(DevicePort==1)
{
if(shortConfig)
return PORT1_SHORT_CONFIG_SIZE;
else
return PORT1_CONFIG_SIZE;
}
else if(DevicePort==2)
{
return PORT2_CONFIG_SIZE;
}
else if(DevicePort==3)
{
return PORT3_CONFIG_SIZE;
}
else if(DevicePort==4)
{
if(nConfig==0)
{
return PORT4_CONFIG_1_SIZE;
}
else if(nConfig==1)
{
if(shortConfig)
return PORT4_SHORT_CONFIG_2_SIZE;
else
return PORT4_CONFIG_2_SIZE;
}
else if(nConfig==2)
{
return PORT4_CONFIG_3_SIZE;
}
}
else if(DevicePort==5)
{
return PORT5_CONFIG_SIZE;
}
else if(DevicePort==6)
{
return PORT6_CONFIG_SIZE;
}
}
int16 GetStringPointer(unsigned char nString)
{
return 0;
}
int16 GetStringLength(unsigned char nString)
{
return 0x3;
}
int16 GetHubPointer()
{
puts("Hub");
return HUB_HUB_DEVICE_OFFSET;
}
int16 GetHubLength()
{
return 0x9;
}
void OnDongleOK()
{
BlinkMode=1;
output_bit(LEDR,1);
}
void main()
|
From "void main()" onwards the code is already mentioned.
Thanks for the help in advance.
Last edited by rao on Mon Oct 04, 2010 2:31 am; edited 1 time in total |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Sun Oct 03, 2010 9:23 pm |
|
|
I don't like those "condition always TRUE" warnings either, and there is a way to get rid of some of them. You can change:to:It looks a bit strange, but it's perfectly standard C that achieves the same thing - without the warning. _________________ Andrew |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Mon Oct 04, 2010 1:51 am |
|
|
Where did you get the lines you are using to set the build address from?.
You refer to the working code starting at address 800, but these set the start address to be 1000. If the bootloader wants the code to be at address 800, then it is not going to work... Could be the whole problem. These lines _must_ match exactly what the bootloader requires.
Best Wishes |
|
|
rao
Joined: 03 Oct 2010 Posts: 10 Location: Pune
|
|
Posted: Mon Oct 04, 2010 2:41 am |
|
|
@andrewg
@Ttelmah
Thank you very much to you both, I dont have the exact words to thank for the help that you both have extended. Changed the "while" statement to "for" statement and also changed the code start address from 0x1000 to 0x0800.
When I load the generated file in PDFSUSB the code now starts from 0800 instead of previous one. I havent tested the code yet, but once I go back home I'll test it out and post my results here.
However, the warning associated to the following are still there, will they have any impact on the generated hex file?
Warning 203:"C:\.....\PICC\Devices\pic18_usb.c"Line531(1,1):Condition always TRUE
Warning 203:"C:\.....\PICC\Devices\usb.c"Line576(1,1): Condition always TRUE
I cant post the code of these files due to copyright infringements, and they are standard files included in the CCS Compiler
Another "noob" question is that apparently according to the code the resonator frequency is 8MHZ, what if I want to change it to 12MHZ, I have gone through the datasheet of 18Fx550 particularly the page dealing with oscillator frequency but I cant seem to recollect how to change it. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Mon Oct 04, 2010 3:17 am |
|
|
I find that
Does NOT give the warning but
does. So I tend to use while(true).
You will probably find that the reason the USB code gives the errors is because of this, the easy option is to copy the USB files to your own folder and make the changes you require. This is what I have done.
Don't try and change the original files as an update to CCS may overwrite them! |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Mon Oct 04, 2010 3:23 am |
|
|
The other "condition always TRUE" messages are most likely because you haven't defined USB_CON_SENSE_PIN. That's not an error, but does mean the USB libraries assume the USB is always connected, and the code that tests for connection is "always TRUE" as the warning indicates.
To change the crystal from 8 to 12, change PLL2 to PLL3. As the data sheet says, the PLL input must be 4MHz: 12/3 = 4. _________________ Andrew |
|
|
rao
Joined: 03 Oct 2010 Posts: 10 Location: Pune
|
|
Posted: Mon Oct 04, 2010 3:50 am |
|
|
@wayne_
I'll give this one a try "while(true)" instead of "while(1)"
While making the project I do give the include files path, where all project files are kept, so I would assume it should use those files, and those files are purpose generated for this project.
One last question is regarding the "bootloader button", if I burn the pre-made hex file the bootloader button get defined at RC6, if I want to change it to RB5, how could I achieve that, because I think it is activated via interrupts in this code. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Mon Oct 04, 2010 5:52 am |
|
|
_Beware_ of using 'resonators' for USB. An enormous amount of 'commercial' kit fails, if the temperature goes outside 'office' ranges, when these cannot meet the accuracy requirements of USB. Triple check that the part you are using will meet the USB timing spec, for quite a few degrees 'outside' your likely temperature range.
The only change needed to switch from an 8MHz source to a 12MHz source, is to change PLL2 to PLL3 in the fuses.
The change for RC6 to RB5, needs to be made in the bootloader itself. You'd need access to it's source code, or to disassemble it, and then change the pin reference, and possibly the TRIS settings on the pins concerned.
Best Wishes |
|
|
rao
Joined: 03 Oct 2010 Posts: 10 Location: Pune
|
|
Posted: Mon Oct 04, 2010 9:23 am |
|
|
Ok, changed the resonator to crystal.
It seems I have some problem with my computers, I compiled the files on my office laptop which is a Toshiba Tecra, the compile did generate the hex file with two warnings and upon burning it with PDFSUSB the code seems to work alright.
However, on my home laptop and PC the project compiles with the same warnings but when I load the hex file in PDSFUSB, instead of showing the code start from 0x0800 it shows the code start from 2C58E80, strange.
Now coming to getting the source codes of bootloader, the sources are available on the net.
My problem remains the same, when I burn the premade hex file of the bootloader the "bootloader" button is at RB4, I burn the bootloader via PICKIT2, after burning the bootloader when I ground the RB4 pin while connecting it to USB it is detected as a USB device.
However, when I burn the pre-made hex file of the mentioned project via PDFSUSB, after burning the firmware RB4 pin doesnt work any more as a bootloader button rather PIN RC6, now works as a bootloader button.
Which makes me believe that this firmware somehow redefines bootloader button from RB4 to RC6 |
|
|
|
|
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
|