18F2321 - two unrelated problems

Thread Starter

atferrari

Joined Jan 6, 2004
4,770
18F2321 MPLABX 5.45 PICKit4 Win10 Assembly

Two problems that I could not solve after many days trying:

1st problem) if the micro was previously blank, after being programmed with the PICKit4, the program does
not start but, by briefly disconnecting and reconnecting power, it starts with no problem.

Just in case, my configuration follows:

Code:
;------------------------------------------------------------------------------
  CONFIG OSC = INTIO2,    FCMEN = OFF,    IESO = OFF,       PWRT = OFF
  CONFIG BOR=0,           BORV = 3,       WDT = OFF,        WDTPS = 1
  CONFIG CCP2MX = RC1,    PBADEN = DIG,   LPT1OSC = OFF,    MCLRE = ON
  CONFIG STVREN = OFF,    LVP = OFF,      BBSIZ = BB256,    XINST = OFF
  CONFIG DEBUG = OFF,     CP0 = OFF,      CP1 = OFF,        CPB = OFF
  CONFIG CPD = OFF,       WRT0 = OFF,     WRT1 = OFF,       WRTC = OFF
  CONFIG WRTB = OFF,      WRTD = OFF,     EBTR0 = OFF,      EBTR1 = OFF
  CONFIG EBTRB = OFF
;------------------------------------------------------------------------------
2nd problem) I need RA0,RA1 and RA2 to be available as digital OUT.

I know that on POR, all analog inputs become digital but, just in case I load ADCON1, explicitly:

LOADREG_IN_ACC ADCON1,00001111B ;all ADC inputs are made digital

I also know that on POR, both comparators are turned off but, just in case again I load CMCON, explicitly:

LOADREG_IN_ACC CMCON,00000111B ;for 18F2321 turn comparators OFF

I finally do

BCF TRISA,0 ;pin is OUT
BCF TRISA,1 ;pin is OUT
BCF TRISA,2 ;pin is OUT

I could not get any output through those pins.

Is there any way too obvious step I did not consider?

Thanks for any help.
 

cmartinez

Joined Jan 17, 2007
8,253
For your second problem, did you select the proper memory bank before clearing the TRISA register's bits?
For instance, in a PIC16LF1823, you'd go something like:

Code:
       ;************ PORTA
       banksel ANSELA     ;Bank 3
       clrf ANSELA        ;no analog inputs in this port, so clear the analog select register
                          ;which for some stupid reason is enabled by default ... otherwise
                          ;the digital i/o functions won't work
      
       ;- Internal Weak Pull Up setup:
       banksel WPUA       ;Bank 4
       movlw b'00001001'  ;0 = Disabled, 1 = Enabled
       movwf WPUA

       ;- I/O configuration setup:
       banksel TRISA      ;Bank 1
       movlw b'11111001'  ;0 = Push-Pull Output, 1 = Tri-State Input
       movwf TRISA

       ;- Set initial output state
       banksel LATA       ;Bank 2
       movlw b'00000010'  ;Data Latch, set Tx_PIN/RA1 as high and all output pins as low, the
       movwf LATA         ;LATA state of an input does not matter
 

cmartinez

Joined Jan 17, 2007
8,253
For your first problem, I can only imagine it has to do with MPLAB's settings ... I remember tweaking them a while ago (but I can't remember the exact parameter) until I had things up and running immediately after programming, without having to manually reset the MCU, as you've been doing.
 

Thread Starter

atferrari

Joined Jan 6, 2004
4,770
For your second problem, did you select the proper memory bank before clearing the TRISA register's bits?
Hola César

The 18F family has a "common" memory (access memory) that you can always access no matter what bank you have selected, if any; SFRs reside there.
 

Thread Starter

atferrari

Joined Jan 6, 2004
4,770
For your first problem, I can only imagine it has to do with MPLAB's settings ... I remember tweaking them a while ago (but I can't remember the exact parameter) until I had things up and running immediately after programming, without having to manually reset the MCU, as you've been doing.
This is the most puzzling situation I run across in a very long time.

My previous project used the same micro with almost no hardware difference and started flawlessly always.

I decided to move to another micro I have handy just to move on and get my project done. Later, I could eventually come back to this intriguing thing.

Gracias.
 
Top