View previous topic :: View next topic |
Author |
Message |
citroenie
Joined: 15 May 2008 Posts: 3
|
unable to read a digital pin from the E-port |
Posted: Tue Dec 29, 2009 10:54 am |
|
|
Hello pic users,
I am unable to get the right response of any of the digital pins of the E-port from a 18f46k20. Can someone tell me what I am doing wrong?
Kind regards
citroenie
CCS PCH C Compiler, Version 4.057, 32216
My source code :
Code: |
#include <18F46K20.h>
#fuses NOWDT,NOPROTECT,NOMCLR,INTRC_IO,NOLVP, NOWDT
#use delay(clock=4000000)
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)
//=========================================
void init(void)
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_comparator(NC_NC_NC_NC);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED, 255, 1);
setup_timer_3(T3_DISABLED | T3_DIV_BY_1);
set_tris_a(0b11111111);
set_tris_b(0b11111111);
set_tris_c(0b11111111);
set_tris_d(0b00000000);
set_tris_e(0b11111111);
}
//=========================================
void main(void)
{
boolean pine0;
boolean pine1;
boolean pine2;
init();
while(true)
{
pine0 = input_state(PIN_E0);
pine1 = input_state(PIN_E1);
pine2 = input_state(PIN_E2);
output_bit(PIN_D2, pine0);
output_bit(PIN_D3, pine1);
output_bit(PIN_D4, pine2);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 29, 2009 1:01 pm |
|
|
1. How are you testing this ? In a simulator or on real hardware ?
How do you know that it's failing ?
2. What external circuits are connected to the PortE and PortD pins ?
3. What voltage levels are you applying to the PortE pins ? |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Dec 29, 2009 2:04 pm |
|
|
Thanks for the reply.
I'm testing this on real hardware.
There are LEDS connected at the Dport. These LEDS will light up when a Dpin goes low. I can drive these pins by software. This seems to work.
The Epins are pulled high with a resistor of 10k to 5volt. It is shorted to ground to make an signal. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 29, 2009 2:53 pm |
|
|
Are the pins grounded by pressing a push-button switch ? How are
they grounded ?
I suggest trying a program that is very simple, and doesn't do anything
out of the ordinary, as shown below. It only tests PIN_E0 and does
output on PIN_D2.
Code: |
#include <18F46K20.h>
#fuses INTRC_IO,NOPROTECT,NOMCLR,NOLVP, NOWDT
#use delay(clock=4000000)
//=========================================
void main(void)
{
int8 pine0;
while(true)
{
pine0 = input(PIN_E0);
if(pine0)
output_high(PIN_D2);
else
output_low(PIN_D2);
delay_ms(100);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
|