Hi,
Iam working on PIC18F2420 ,it has 3 ports A,B,C .. I used all the bits in port B and C so I am run out of free bits.. PortA has other functions beside parallelI/O like analog, how can i define it to be for digital input/output only and what are settings for CMCON1, CM0,CM1,CM2..
If you look in the data sheet in section 10.1, it has the exact code required to make the port digital.
For your convenience,
Code:
clrf PORTA ; Initialize PORTA by
; clearing output
; data latches
clrf LATA ; Alternate method
; to clear output
; data latches
movlw 07h ; Configure A/D
movwf ADCON1 ; for digital inputs
movwf 07h ; Configure comparators
movwf CMCON ; for digital input
movlw 0CFh ; Value used to
; initialize data
; direction
movwf TRISA ; Set RA<3:0> as inputs
; RA<5:4> as outputs
For setting PORTA as digital input/output while turning every thing off,
ADCON1=0x0f; //Taking that you have not used the AD converter module even for PORT B, otherwise refer to page 226 of datasheet
CMCON=0x07; // Turns all the comparators off, page 235,236 of datasheet
There you have it, all ports Digital, use TRISA to set direction for PORTA.
The header file you're using is generic to te pic18f series of chips. You need to specify your exact device so target locations are known. Do this as Wond3rboy showed you above:
The header file you have posted is a trimmed down version of the pic18.h header file available in hi tech C pro compiler. First i would suggest you replace it with the original one. The original one wont take up any extra code(if you haven't deleted any thing about the processor).Here is the original file. This code works fine.
View attachment CMCON.doc
this the error that I have .. and also another error occured when I add the pic18.h to the include forlder removing the old one.. why?
As you are using the compiler from a command prompt you need to tell it the include paths or copy the relevant files to your project directory. It maybe that the old version of the compiler doesn't support the 2420, try downloading the latest version.
@ktkoota i am surprised you are using the compiler in command prompt, like 3V0 said, go for an IDE, i would say MPLab, it has got a host of other tools too.
ok.. I will try to use MPlab .. command prompt is instructed from my supervisor!! but the most important thing is to finalize the project.. I will tell you all my prgress with MPlab