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

help with USB HID bootloader [solved]

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



Joined: 16 Oct 2010
Posts: 7

View user's profile Send private message

help with USB HID bootloader [solved]
PostPosted: Wed Oct 20, 2010 6:03 am     Reply with quote

Hi,

I'm running USB HID bootloader on 18F2550.
I trying to modify the USB HID bootloader to use RC6 pin 17 to match my schematic.
However it seems with my code the condition is always true and it always enters into bootloader mode.

the bootloader code here
Code:

#define mInitAllSwitches()  TRISCbits.TRISC6=1;
#define mInitSwitch2()      TRISCbits.TRISC6=1;
#define sw2                 PORTCbits.RC6

void main(void)

ADCON1 = 0x0F;
mInitSwitch2();
PORTCbits.RC6=1;//if pressed will be 0

    if(sw2 == 1)    //This example uses the sw2 I/O pin to determine if the device should enter the bootloader, or the main application code
    {
           ADCON1 = 0x07;
        _asm
        goto 0x1000
        _endasm
    }

    InitializeSystem();
    while(1){
//do something
}

I get the code from others, and I'm newbie, not quite understand how to init the ADCON1, what could be the problem?

Thanks,
rampage



Joined: 16 Oct 2010
Posts: 7

View user's profile Send private message

PostPosted: Wed Oct 20, 2010 6:27 am     Reply with quote

well, lesson learned,
Beginners checklist for PIC Microcontrollers
http://www.piclist.com/techref/piclist/begin.htm
rule 9
Don't Float: Tie the switch pin Hi or Lo with a ~10K resistor or use internal pullups to avoid floating inputs when the switch is open. In general, do something with unused pins don't just leave them floating
rampage



Joined: 16 Oct 2010
Posts: 7

View user's profile Send private message

PostPosted: Thu Oct 21, 2010 5:32 am     Reply with quote

what if I want to use the internal pull up resistor on portB of 18F2550? Can I have a switch there without a pull up resistor? How to do the settings?
sturnfie



Joined: 26 Apr 2010
Posts: 17
Location: Palatine, IL

View user's profile Send private message Visit poster's website

PostPosted: Thu Oct 21, 2010 9:30 am     Reply with quote

rampage wrote:
what if I want to use the internal pull up resistor on portB of 18F2550? Can I have a switch there without a pull up resistor? How to do the settings?


You need a pull-up resistor (or pull-down) to ensure a constantly driven logic state. A common switch configuration involves a I/O port pin tied to a node with one branching leading to a weak (~10k) pull-up to +V and another branch leading to one side of the switch. The other side of the switch is connected to ground. When the circuit is open, the I/O port will read a "1". When the switch is closed, the I/O port will be pulled to GND and will read as a "0". Without a pull resistor, the floating logic value is...well, not logical Smile.

See the CCS C function "port_x_pullups()" for how to enable to internal port resistors.

(edit: just saw this in a recent post, more clarification on the pull-up resistors
http://www.ccsinfo.com/forum/viewtopic.php?t=43841 )

Lucas
_________________
Lucas Sturnfield
Blog - http://www.sturntech.com/blog
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