18FJ Series WDTCON Register

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

18FJ Series WDTCON Register

Post by Doj » Wed Sep 26, 2007 4:37 pm

I had blissfully ignored new register WDTCON in the 18FxxJxx as long as I have been using them.
I have also noticed that I could not get certain ports(AN ports) to work as digital inputs at all using the normal code(after setting all the registers that are needed to make them digital):-

Code: Select all

Input(DWN)
    If DWN=1 Then
        While DWN=1
            LED_ON
        Wend
    EndIf
The led never came on, so next(after replacing the chip) I tried printing out all the registers to make sure they were set correctly, and I found that the registers "ANCON0 and ANCON1" which tell the ports if they are analogue(default at startup) or digital, never changed from their default.

After reading and reading I noticed in the small initialisation example that is given in ASM that it toggled WDTCON.4 from 0 to 1 while it wrote to ANCON0 and ANCON1 so I have now done this and it works:-

Code: Select all

'MAKE ALL PORTS DIGITAL ON 18F67J11
    WDTCON.4=1                                           'ANCONx(shared registers) can only be written when WDTCON.4=1
    ANCON0=%11111111                                'make AN0 to AN7 digital
    ANCON1=%11111111                                'make AN8 to AN15 digital
    WDTCON.4=0                                           'switch off shared registers  
    ADCON0=%00000000                                'switch off the AD converter
    ADCON1=%10000000                                'right justify AD result
    INTCON=%00000000                                'disable all INTCON interrupt components
    INTCON2=%10000000                               'disable PORTB pullups
    TRISG.7=0                                       'disable PORTD pullups
    TRISG.6=0                                       'disable PORTE pullups
    TRISG.5=0                                       'disable PORTJ pullups
    CCP1CON=%00000000                               'disable CCP module
    CCP2CON=%00000000                               'disable CCP module
    CCP3CON=%00000000                               'disable CCP module
    CCP4CON=%00000000                               'disable CCP module
    CCP5CON=%00000000                               'disable CCP module
    CM1CON=%00000000                                'disable comparator module
    CM2CON=%00000000                                'disable comparator module
    CVRCON=%00000000                                'disable comparator reference


Post Reply