View previous topic :: View next topic |
Author |
Message |
brutus
Joined: 14 Apr 2004 Posts: 12
|
Cannot read from PORTF - PIC16F1946 |
Posted: Thu Dec 16, 2010 9:00 am |
|
|
Hi everybody,
My problem is that on my PortF I've a dip switch with physical pullups (10k), but I always get a low input all over the port.
The port configuration is this:
Code: |
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#use fast_io(F)
#use fast_io(G)
set_tris_a(0B11101111);
set_tris_b(0B11111111);
set_tris_c(0B10000000);
set_tris_d(0B11111111);
set_tris_e(0B11111111);
set_tris_f(0B11111111);
set_tris_g(0B11111000);
|
but when I get
Code: | int8 data = input_f();
|
I have 0x00 even if all input signals are 5v.
PortD, which has a similar hardware configuration, works correctly.
My CCS version is 4.110.
Any help?
Thanks
Claudio |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu Dec 16, 2010 10:20 am |
|
|
Read the datasheet about Port F. This can be found in section12.7 (page
142). There is a note in 12.7.1 that explains your problem.
Next, if you look in the 16F1946.h header file, you will find the settings to fix
your problem. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
brutus
Joined: 14 Apr 2004 Posts: 12
|
|
Posted: Thu Dec 16, 2010 12:40 pm |
|
|
dyeatman wrote: | Read the datasheet about Port F. This can be found in section12.7 (page
142). There is a note in 12.7.1 that explains your problem.
Next, if you look in the 16F1946.h header file, you will find the settings to fix
your problem. |
Many thanks! Now is clear the problem! ...but the solution is not so clear.
In the 16F1946.h header I'm not able to find any reference to the ANSELF register setting...am I missing something?
Thanks,
C |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Thu Dec 16, 2010 3:41 pm |
|
|
Generally in CCS, you don't ever need to talk directly to any register.
Ask yourself instead, what does this register do?. Then look at 'what function/constants controls this feature'?.
What does setup_adc_ports control?.
Best Wishes |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu Dec 16, 2010 4:50 pm |
|
|
ANSELF stands for ANalog SELect for port F and is used to control the
enabling/disabling of the ADC functions for the ADC capable pins.
TTelmah is correct. Look under setup_adc_ports in the .h file to get the
parameter to turn off the ADC functions. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
brutus
Joined: 14 Apr 2004 Posts: 12
|
|
Posted: Fri Dec 17, 2010 3:21 am |
|
|
Ok guys,
Thanks both for the suggestions, I appreciate who shows me the right way...
The problem is that I'm using ADC, and even if I disable it (to try...) using the setup_adc_ports to NO_ANALOGS it doesn't work.
Finally I solved setting directly the register:
Code: |
#byte ANSELF = 0x40C
#byte ANSELG = 0x40D
ANSELF = 0x00;
ANSELG = 0x00;
|
In any case, I post also my .h file ( ADC section ):
Code: |
// Constants used in SETUP_ADC_PORTS() are:
#define ALL_ANALOG 0xffff0007 // A0 A1 A2 A3 A5 E0 E1 E2 B0 B1 B2 B3 B4 B5
#define sAN13 0x20000000 // B5
#define sAN12 0x01000000 // B0
#define sAN11 0x10000000 // B4
#define sAN10 0x02000000 // B1
#define sAN9 0x08000000 // B3
#define sAN8 0x04000000 // B2
#define sAN7 0x40000 // E2
#define sAN6 0x20000 // E1
#define sAN5 0x10000 // E0
#define sAN4 0x20 // A5
#define sAN3 0x8 // A3
#define sAN2 0x4 // A2
#define sAN1 0x2 // A1
#define sAN0 0x1 // A0
#define NO_ANALOGS 0x00000 // None
|
Don't you think is wrong? Where are F and G inputs?
Greetings, C |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Fri Dec 17, 2010 4:06 am |
|
|
Yes.
Looks like your version hasn't got the constants right. In many cases they _are_ the right values, but the naming is wrong. For example sAN7, is labelled as E2, but AN7, actually uses F2. The value is correct to use F2 in the chip....
Best Wishes |
|
|
|