Alright thanks Olin! That cleared it up so much I should probably take a refresher on the electronics - Xiao Xu On Mon, May 31, 2010 at 7:10 PM, Oli Glaser wrote: > > ----- Original Message ----- > From: "Xiao Xu" > To: "Microcontroller discussion list - Public." > Sent: Monday, May 31, 2010 10:05 PM > Subject: Re: [PIC]In C, how do you set a pin to high voltage? > > > >I got one LED to flash on the PICkit. Thanks for the help everyone! > > > > I have another question though. Below is a link of schematic for the LEDs > > on > > the PICkit (page 2 of link below), does anyone know what combination of > > bits > > are required for each LED? > > > > For example, if I set PORTA = 0b00010000, D0 LED lights up. If I set > PORTA > > = > > 0b00100000, D1 LED lights up. > > How can I figure out what combination of high/low/no voltages are > required > > to light up each of the other LEDs? > > thanks. > > Glad you got it sorted. > Better schematic for Pickit 1 here: > http://ww1.microchip.com/downloads/en/DeviceDoc/40051D.pdf > With the settings for lighting each of the LEDs, couple of examples to get > you going (don't want to spoil the fun of working it out totally :-). > Basically you have to make sure that there is a channel for current through > ONLY the LED you want to light. You can do this by setting all the pins > that > are not used to inputs, making then high resistance and unable to sink > (hardly) any current. I think the examples below *should* work.. > > So if you wanted to light D2, you would set: > TRISA4 = 0; // Output for high > TRISA5 = 1; // Make RA5 high resistance so no current can flow into it, > stopping D0 from lighting too > TRISA2 = 0; // 0V (Current sink for D2) > TRISA1 = 1; // Make RA1 high resistance > PORTA = 0b00010000; // Set RA4 to high, lighting D2 - set all bits at > once to avoid read modify write problems > > To light D0, you would set: > TRISA4 = 0; // Output for high > TRISA5 = 0; // 0V (Current sink for D0) > TRISA2 = 1; // Make RA2 high resistance > TRISA1 = 1; // Make RA1 high resistance > PORTA = 0b00010000; // Set RA4 high, lighting D0 this time, as current > now has channel to ground through RA5 > > Better way, less instructions (does same as above): > > for D2: > TRISA = 0b11101011; // Set RA4 and 2 outputs, rest high resistance > inputs > PORTA = 0b00010000; // Set RA4 to high, lighting D2 - set all bits at > once to avoid read modify write problems > > for D0: > TRISA = 0b11001111; // Set RA4 and 5 as outputs, rest as high resistance > inputs > PORTA = 0b00010000; // Set RA4 high, lighting D0 this time, as current > now has channel to ground through RA5 > > So the idea is to set the LEDs anode and cathode pins as outputs, and all > the rest (not involved) as inputs, using the TRISA register. Then set > *only* > the LED anode high using PORTA. Hope I've got it right :-) > > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist