View previous topic :: View next topic |
Author |
Message |
Rez
Joined: 10 Feb 2019 Posts: 26
|
Help with 12f683 GP2 and GP1 as output [Solved] |
Posted: Tue Feb 19, 2019 8:01 pm |
|
|
I cant figure out how to make GP2 and GP1 as an output. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Tue Feb 19, 2019 9:10 pm |
|
|
CCS calls them PIN_A2, PIN_A1.....
I'm not too sure why Microchip call them 'GP' when from day one I/O pins have been called by the port name like 'A' or 'B'.
just a qurk ??
Jay |
|
|
Rez
Joined: 10 Feb 2019 Posts: 26
|
|
Posted: Tue Feb 19, 2019 9:23 pm |
|
|
temtronic wrote: | CCS calls them PIN_A2, PIN_A1.....
I'm not too sure why Microchip call them 'GP' when from day one I/O pins have been called by the port name like 'A' or 'B'.
just a qurk ??
Jay |
Sorry, I know the names its not that.
I am using A0 as an input to control a 10k pot as well.
I have an LED on pin 4 A2 and it just flashes.
Code: |
void main()
{
setup_adc(ADC_CLOCK_DIV_8); //must use ADC_CLOCK_DIV_8 or ADC_CLOCK_DIV_16 when clock is set to 4Mhz
setup_adc_ports(sAN0);
set_adc_channel(0);
setup_comparator(NC_NC_NC_NC); //turn off comp
while(TRUE)
{
output_high(PIN_A2);
}
}
|
Last edited by Rez on Tue Feb 19, 2019 9:27 pm; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Tue Feb 19, 2019 9:27 pm |
|
|
You should post your complete program, but I'm guessing you have the WDT fuse enabled.
Jay |
|
|
Rez
Joined: 10 Feb 2019 Posts: 26
|
|
Posted: Tue Feb 19, 2019 9:28 pm |
|
|
temtronic wrote: | You should post your complete program, but I'm guessing you have the WDT fuse enabled.
Jay |
WDT is disabled |
|
|
Rez
Joined: 10 Feb 2019 Posts: 26
|
|
Posted: Tue Feb 19, 2019 9:31 pm |
|
|
Code: | #include <12F683.h>
#use delay(clock = 4000000)
#fuses NOMCLR,NOPROTECT,NOWDT,INTRC_IO //,NOIESO,NOCPD,NOFCMEN,NOBROWNOUT
void main()
{
setup_adc(ADC_CLOCK_DIV_8);
setup_adc_ports(sAN0);
set_adc_channel(0);
setup_comparator(NC_NC_NC_NC); //turn off comp
while(TRUE)
{
output_high(PIN_A2);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 19, 2019 10:09 pm |
|
|
Add this line to your setup code in main(). That should fix pin GP2.
Code: | setup_timer_0(T0_INTERNAL); |
Timer0 in this PIC defaults to using an external clock on pin GP2.
By adding the above line, it's reconfigured to use the internal clock
and GP2 can now be used as an output pin. |
|
|
Rez
Joined: 10 Feb 2019 Posts: 26
|
|
Posted: Tue Feb 19, 2019 10:14 pm |
|
|
PCM programmer wrote: | Add this line to your setup code in main(). That should fix pin GP2.
Code: | setup_timer_0(T0_INTERNAL); |
Timer0 in this PIC defaults to using an external clock on pin GP2.
By adding the above line, it's reconfigured to use the internal clock
and GP2 can now be used as an output pin. |
Thanks for the response, but that still does not work, it just keeps flashing. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 20, 2019 4:13 am |
|
|
Do you have a series resistor in your LED circuit ? You need one.
Example:
Code: |
pin 470 ohms LED
A2 -----/\/\/\/------->|----
|
|
----- Ground
---
-
|
Use a resistor between 220 and 1K. 470 ohms will work fine. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Wed Feb 20, 2019 7:16 am |
|
|
Classic 'two minds with one thought' here. I just started to post and
saw PCM_programmmer had the same idea.
Thought is that without the resistor, lamp comes on and overloads the
PIC. PIC then stops/crashes, possibly lowering the supply voltage.
It then restarts. Result, flashing LED....
Also, as a 'second thought', make sure the watchdog actually is disabled. If
(for instance) the programmer was not set to update the fuses, you could
have the watchdog 'off' in the code, but it still 'on' in the chip. |
|
|
Rez
Joined: 10 Feb 2019 Posts: 26
|
|
Posted: Wed Feb 20, 2019 12:48 pm |
|
|
Yes there is a resistor. I tried using port A1 (GP1) and it does the same thing.
I am using a PICKit 2 programmer. |
|
|
Rez
Joined: 10 Feb 2019 Posts: 26
|
|
Posted: Wed Feb 20, 2019 1:06 pm |
|
|
LMAO, I am so dumb. I just know realized I was using a flashing LED I have know idea how it got into my regular batch of LED's. |
|
|
Rez
Joined: 10 Feb 2019 Posts: 26
|
|
Posted: Wed Feb 20, 2019 1:13 pm |
|
|
Everything is working fine now, I didb't have to add anything to the code, It was just the flashing LED. WOW! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Wed Feb 20, 2019 2:45 pm |
|
|
No wonder it flashed!....
That's a real 'silly'. |
|
|
|