View previous topic :: View next topic |
Author |
Message |
rampage
Joined: 16 Oct 2010 Posts: 7
|
help with USB HID bootloader [solved] |
Posted: Wed Oct 20, 2010 6:03 am |
|
|
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
|
|
Posted: Wed Oct 20, 2010 6:27 am |
|
|
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
|
|
Posted: Thu Oct 21, 2010 5:32 am |
|
|
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
|
|
Posted: Thu Oct 21, 2010 9:30 am |
|
|
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 .
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 |
|
|
|