View previous topic :: View next topic |
Author |
Message |
jfk1965
Joined: 21 Oct 2003 Posts: 58
|
Help with a stuck IO Pin |
Posted: Wed Feb 15, 2006 6:41 am |
|
|
Hi
I'm using the 16F818 with Compiler version 3.217.
My problem always arises when I try to use pin B3 as an output, it won't change state when programmed. Until now I have got around this by switching to another spare pin which has worked fine. When programmed to go high the pin always stays low and won't alter state at all.
I aways program all pins to a known state at powerup (usually all low) by using the standard output_low (Pin_B0) through to pin B7 command. All other pins will switch to high when programmed to using the standard output_high(Pin_B0) command except for pin B3
I now have an application coming up that needs all pins as outputs so I need to overcome this problem.
Has anyone got any ideas what I'm doing wrong?
thanks in advance
JFK |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Feb 15, 2006 7:17 am |
|
|
Without knowing your code it is difficult to help you, so I just can guess something like
Pin_B3 is usually shared with the ICSP as enable pin.
Does your code has the directive #ICD=TRUE ?
Humberto |
|
|
jfk1965
Joined: 21 Oct 2003 Posts: 58
|
|
Posted: Wed Feb 15, 2006 8:17 am |
|
|
No I don't use the ICD here's a simple program that I used earlier today to test it out you will see I switched the redled output to Pin B0 from B3 to get it to work.
Code: |
#include <touch.h>
#include <stdlib.h>
//Lithium Ion charger
//Revision 1.0
//written on compiler version 3.217
//tested on compiler version 3.217
#define timer 210
#define vconnect 452
#define vmin 258 //minimum battery voltage 10V
#define imin 63 //switch over current from hi V to lo V
#define ledred (Pin_B0)
#define ledgreen (Pin_B2)
#define onoff (Pin_B6)
long int vbatt,ibatt,minute;
long tick;
void RedLedFlash()
{
output_high ledred;
delay_ms(200);
output_low ledred;
delay_ms(200);
}
void Reset()
{
Output_low onoff;
Output_low ledred;
Output_low ledgreen;
vbatt=0,ibatt,minute=0,tick=0;
}
#int_RTCC
void RTCC_isr()
{
tick++;
if(tick == 15000)
{
minute++;
tick=0;
}
}
void main()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_2);
setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
goto start;
charged:
set_adc_channel(0);
output_low onoff; //switch charger off
output_high ledgreen; //change led to show charged
output_low ledred;
disable_interrupts(global);
do
{
vbatt = read_adc();
delay_ms(500);
}
while(vbatt > vmin);
start:
Reset();
do //test for battery connected
{
set_adc_channel(0);
delay_us(100);
vbatt = read_adc();
RedLedFlash();
}
while (vbatt < vmin);
output_high onoff; //switch charger on and indicate charging
output_high ledred;
enable_interrupts(global);
do //loop until battery disconnected or charged
{
delay_ms(1000);
vbatt = read_adc();
if (vbatt >= vconnect) goto charged;
set_adc_channel(2);
delay_ms(500);
ibatt = read_adc();
if(ibatt < imin) goto charged;
if(minute > timer)goto charged;
set_adc_channel(0);
}
while (1);
}
|
|
|
|
drh
Joined: 12 Jul 2004 Posts: 193 Location: Hemet, California USA
|
|
Posted: Wed Feb 15, 2006 8:24 am |
|
|
Look at your #FUSES statement.
Change LVP to NOLVP. _________________ David |
|
|
|