• AVR Freaks

Hot!12F752 can't ouput to PORTA,RA5 even in MPLAB simulator

Author
JTW
Starting Member
  • Total Posts : 21
  • Reward points : 0
  • Joined: 2012/02/27 08:20:12
  • Location: Australia
  • Status: offline
2020/12/01 18:44:53 (permalink)
0

12F752 can't ouput to PORTA,RA5 even in MPLAB simulator

I have stepped up to a 12F752 from my usual 12F675 to get better resolution in the comparator.
 
However, I can't get past first base trying to output to PORTA,RA5.
 
Even in the simulator
 
Here's my test code. Other outputs work fine.
 
    __CONFIG   _CP_OFF & _BOREN_DIS & _MCLRE_ON & _WDTE_OFF & _PWRTE_ON & _CKLOUTEN_OFF

    ERRORLEVEL -302

        BANKSEL    ANSELA
        CLRF    ANSELA

        BANKSEL    LATA
        CLRF    LATA

        BANKSEL    TRISA
        CLRF    TRISA

        BANKSEL    PORTA
        CLRF    PORTA
        BSF        PORTA,RA0
        BSF        PORTA,RA1
        BSF        PORTA,RA2
        BSF        PORTA,RA4
        BSF        PORTA,RA5
        GOTO    $-1

        END
 
MPLAB v8.80 PicKit3
 
I have been hung up on problems like this in the past and found simple things I was (or wasn't doing right). Any suggestions welcome.
 
Jeff
 
#1

11 Replies Related Threads

    ric
    Super Member
    • Total Posts : 29435
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: 12F752 can't ouput to PORTA,RA5 even in MPLAB simulator 2020/12/01 19:37:15 (permalink)
    +1 (3)
    Your CONFIG word is missing the FOSC setting, so it is defaulting to using RA5 as CLKIN.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    ric
    Super Member
    • Total Posts : 29435
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: 12F752 can't ouput to PORTA,RA5 even in MPLAB simulator 2020/12/01 19:39:38 (permalink)
    +3 (5)
    n.b. you have "stepped up" from a ten year old chip to a nine year old one.
    Why not try something a little more recent?
     
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    JTW
    Starting Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2012/02/27 08:20:12
    • Location: Australia
    • Status: offline
    Re: 12F752 can't ouput to PORTA,RA5 even in MPLAB simulator 2020/12/01 20:09:00 (permalink)
    0
    Thanks Ric. You are a legend.
     
    Just quickly I have added   &  _FOSC0_INT   but no luck. I will look into the correct way to select the internal osc for this chip.
     
    I went for the 752 as I have them in my stock and I am in a remote area (Sapphire Queensland Aust).
     
    Thanks again.
     
    Edit: space in  &  _FOSC0_INT
    post edited by JTW - 2020/12/01 20:10:50
    #4
    dan1138
    Super Member
    • Total Posts : 4157
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: 12F752 can't ouput to PORTA,RA5 even in MPLAB simulator 2020/12/01 21:07:51 (permalink)
    0
    Sorry, did examples for the wrong target.
     
    I will edit this post and add the PIC12F752 in a few hours.
     
    Example for MPASMWIN(v5.51):
    ;
    ; File:     main.S
    ; Target:   PIC12F675
    ; Author:   dan1138
    ; Date:     2020-12-1
    ; Compiler: MPASMWIN v5.51
    ; IDE:      MPLAB v8.92
    ;
    ; Description:
    ;
    ;      Example project for the PIC12F675 controller using the MPASMWIN tool chain.
    ;
    ;
        list        p=12F675
        list        c=132
        list        r=dec
        errorlevel  -302

    #include <p12F675.inc>

      __CONFIG _CP_ON & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_OFF & _INTRC_OSC_NOCLKOUT

    ;
    ; Power-On-Reset entry point
    ;
    Por_Vec: CODE   0x0000
    resetVec:
        goto    main
    ;
    ;   Data space use by interrupt handler to save context
    IsrData:   UDATA_SHR
    ;
    WREG_save:      res  1
    STATUS_save:    res  1
    PCLATH_save:    res  1
    ;
    ;   Interrupt vector and handler
    IsrCode: CODE   0x0004
    ;
    IsrVec:
        movwf   WREG_save
        swapf   STATUS,W
        movwf   STATUS_save
        movf    PCLATH,W
        movwf   PCLATH_save
    ;
    IsrHandler:
    ;
    IsrExit:
        movf    PCLATH_save,W
        movwf   PCLATH
        swapf   STATUS_save,W
        movwf   STATUS
        swapf   WREG_save,F
        swapf   WREG_save,W
        retfie                      ; Return from interrupt
    ;
    ; Toggle output bit every 4 instruction cycles.
    ;
    MainCode:   code
    main:
        clrf    INTCON              ;starting point
        btfsc   STATUS,RP0
        goto    NoOscCal
        bsf     STATUS,RP0
        call    OscRetlw
        movwf   OSCCAL
    NoOscCal:
        BANKSEL GPIO
        clrf    GPIO
        movlw   0x07
        movwf   CMCON
        BANKSEL ANSEL
        clrf    ANSEL
        clrf    TRISIO
        movlw   0xFF
        movwf   OPTION_REG
    ;
    ; Application process init
    ;
        BANKSEL GPIO
        clrf    GPIO
        bsf     GPIO,GP0
        bsf     GPIO,GP1
        bsf     GPIO,GP2
        bsf     GPIO,GP4
        bsf     GPIO,GP5
    ;
    ; Application process loop
    ;
    loop:
        goto    loop
    ;     
    ;
    ; The PIC12F675 has a retlw in the highest
    ; instruction word in the code space with the
    ; factory calibration for the interna; oscillatr.
    ;
    OscRetlwCode: CODE 0x3FF
    OscRetlw:

        end

    Example for pic-as(v2.31):
    ;
    ; File:     main.S
    ; Target:   PIC12F675
    ; Author:   dan1138
    ; Date:     2020-12-1
    ; Compiler: pic-as(v2.31)
    ; IDE:      MPLABX  v5.45
    ;
    ; Description:
    ;
    ;      Example project for the PIC12F675 controller using the pic-as(v2.20) tool chain.
    ;
    ;  Add this line in the project properties box, pic-as Global Options -> Additional options:  
    ;   -Wa,-a -Wl,-pPor_Vec=0h,-pIsr_Vec=4h,-pOscRetlw=3ffh
    ;
        PROCESSOR   12F675
        PAGEWIDTH   132
        RADIX       DEC

     config FOSC = INTRCIO   ; Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
     config WDTE = OFF       ; Watchdog Timer Enable bit (WDT disabled)
     config PWRTE = OFF      ; Power-Up Timer Enable bit (PWRT disabled)
     config MCLRE = ON       ; GP3/MCLR pin function select (GP3/MCLR pin function is MCLR)
     config BOREN = OFF      ; Brown-out Detect Enable bit (BOD disabled)
     config CP = OFF         ; config FOSC = INTRCIO   // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN) Code Protection bit (Program Memory code protection is disabled)
     config CPD = OFF        ; Data Code Protection bit (Data memory code protection is disabled)

    #include <xc.inc>

    ;
    ; Power-On-Reset entry point
    ;
        PSECT   Por_Vec,global,class=CODE,delta=2
        global  resetVec
    resetVec:
        goto    main
    ;
    ;   Data space use by interrupt handler to save context
        PSECT   Isr_Data,global,class=RAM,space=1,delta=1,noexec
    ;
        GLOBAL  WREG_save,STATUS_save
    ;
    WREG_save:      DS  1
    STATUS_save:    DS  1
    PCLATH_save:    DS  1
    ;
    ;   Interrupt vector and handler
        PSECT   Isr_Vec,global,class=CODE,delta=2
        GLOBAL  IsrVec
    ;
    IsrVec:
        movwf   WREG_save
        swapf   STATUS,W
        movwf   STATUS_save
        movf    PCLATH,W
        movwf   PCLATH_save
    ;
    IsrHandler:
    ;
    IsrExit:
        movf    PCLATH_save,W
        movwf   PCLATH
        swapf   STATUS_save,W
        movwf   STATUS
        swapf   WREG_save,F
        swapf   WREG_save,W
        retfie                      ; Return from interrupt
    ;
    ; Toggle output bit every 4 instruction cycles.
    ;
        PSECT   MainCode,global,class=CODE,delta=2
    main:
        clrf    INTCON              ;starting point
        btfsc   STATUS,STATUS_RP0_POSITION
        goto    NoOscCal
        bsf     STATUS,STATUS_RP0_POSITION
        call    OscRetlw
        movwf   OSCCAL
    NoOscCal:
        BANKSEL GPIO
        clrf    BANKMASK(GPIO)
        movlw   0x07
        movwf   BANKMASK(CMCON)
        BANKSEL ANSEL
        clrf    BANKMASK(ANSEL)
        clrf    BANKMASK(TRISIO)
        movlw   0xFF
        movwf   OPTION_REG
    ;
    ; Application process init
    ;
        BANKSEL GPIO
        clrf    GPIO
        bsf     GPIO,GPIO_GP0_POSITION
        bsf     GPIO,GPIO_GP1_POSITION
        bsf     GPIO,GPIO_GP2_POSITION
        bsf     GPIO,GPIO_GP4_POSITION
        bsf     GPIO,GPIO_GP5_POSITION
    ;
    ; Application process loop
    ;
    loop:
        goto    loop
    ;     
    ;
    ; The PIC12F675 has a retlw in the highest
    ; instruction word in the code space with the
    ; factory calibration for the interna; oscillatr.
    ;
        PSECT   OscRetlw,class=CODE,delta=2
        global  OscRetlw
    OscRetlw:

        end     resetVec

     
    These both work in thier simulators.
    post edited by dan1138 - 2020/12/01 21:10:43
    #5
    JTW
    Starting Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2012/02/27 08:20:12
    • Location: Australia
    • Status: offline
    Re: 12F752 can't ouput to PORTA,RA5 even in MPLAB simulator 2020/12/01 21:20:27 (permalink)
    0
    Thanks Dan. Appreciate your time. I have done as Ric suggested (and read up on it all as well) but still unable to get RA5 to act as an output. Almost certainly it is the dual use of the pin (as Ric suggested).
     
    I am (very) familiar with most of this, but new to the PIC12F752.
     
    Thanks,
     
    Jeff
    #6
    dan1138
    Super Member
    • Total Posts : 4157
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: 12F752 can't ouput to PORTA,RA5 even in MPLAB simulator 2020/12/01 23:10:26 (permalink)
    +3 (3)
    jeffthewalker
    I am (very) familiar with most of this, but new to the PIC12F752.

    You are correct, the simulator in MPLAB 8 has a bug in the PIC12F752 simulation model.
     
    This code fails as you described:
    ;
    ; File:     main.S
    ; Target:   PIC12F752
    ; Author:   dan1138
    ; Date:     2020-12-1
    ; Compiler: MPASMWIN v5.51
    ; IDE:      MPLAB v8.92
    ;
    ; Description:
    ;
    ;      Example project for the PIC12F752 controller using the MPASMWIN tool chain.
    ;
    ; MPLAB v8.92 is bugged. PORTA bit RA5 cannot be set, LATA bit LATA5 can be set.
    ;                        Bits set in LATA do not set bits in the PORTA SFR.
    ;
    ;
        list        p=12F752
        list        c=132
        list        r=dec
        errorlevel  -302

    #include <p12F752.inc>

      __CONFIG _CP_OFF & _WRT_OFF & _BOREN_DIS & _MCLRE_ON & _WDTE_OFF & _PWRTE_OFF & _FOSC0_INT & _CLKOUTEN_OFF

    ;
    ; Power-On-Reset entry point
    ;
    Por_Vec: CODE   0x0000
    resetVec:
        goto    main
    ;
    ;   Data space use by interrupt handler to save context
    IsrData:   UDATA_SHR
    ;
    WREG_save:      res  1
    STATUS_save:    res  1
    PCLATH_save:    res  1
    ;
    ;   Interrupt vector and handler
    IsrCode: CODE   0x0004
    ;
    IsrVec:
        movwf   WREG_save
        swapf   STATUS,W
        movwf   STATUS_save
        movf    PCLATH,W
        movwf   PCLATH_save
    ;
    IsrHandler:
    ;
    IsrExit:
        movf    PCLATH_save,W
        movwf   PCLATH
        swapf   STATUS_save,W
        movwf   STATUS
        swapf   WREG_save,F
        swapf   WREG_save,W
        retfie                      ; Return from interrupt
    ;
    ; Toggle output bit every 4 instruction cycles.
    ;
    MainCode:   code
    main:
        clrf    INTCON              ;starting point
        BANKSEL PORTA
        clrf    PORTA
        BANKSEL LATA
        clrf    LATA
        BANKSEL ANSELA
        clrf    ANSELA
        BANKSEL TRISA
        clrf    TRISA
        movlw   0xFF
        movwf   OPTION_REG
    ;
    ; Application process init
    ;
        BANKSEL PORTA
        clrf    PORTA
        bsf     PORTA,RA0
        bsf     PORTA,RA1
        bsf     PORTA,RA2
        bsf     PORTA,RA4
        bsf     PORTA,RA5
    ;
        BANKSEL LATA
        clrf    LATA
        bsf     LATA,LATA0
        bsf     LATA,LATA1
        bsf     LATA,LATA2
        bsf     LATA,LATA4
        bsf     LATA,LATA5
    ;
    ; Application process loop
    ;
    loop:
        goto    loop

        end

     
    The simulator in MPLABX v5.45 works as expected:
    ;
    ; File:     main.S
    ; Target:   PIC12F752
    ; Author:   dan1138
    ; Date:     2020-12-1
    ; Compiler: pic-as(v2.31)
    ; IDE:      MPLABX  v5.45
    ;
    ; Description:
    ;
    ;      Example project for the PIC12F752 controller using the pic-as(v2.20) tool chain.
    ;
    ;  Add this line in the project properties box, pic-as Global Options -> Additional options:  
    ;   -Wa,-a -Wl,-pPor_Vec=0h,-pIsr_Vec=4h
    ;
        PROCESSOR   12F752
        PAGEWIDTH   132
        RADIX       DEC

     config FOSC0 = INT      ; FOSC: Oscillator Selection bit (Internal oscillator mode.  I/O function on RA5/CLKIN)
     config WDTE = OFF       ; Watchdog Timer Enable bit (Watchdog Timer disabled)
     config PWRTE = OFF      ; Power-up Timer Enable bit (Power-up Timer disabled)
     config MCLRE = ON       ; MCLR/VPP Pin Function Select bit (MCLR pin is MCLR function with internal weak pullup)
     config CP = OFF         ; Code Protection bit (Program memory code protection is disabled)
     config BOREN = DIS      ; Brown-out Reset Enable bits (BOR disabled)
     config WRT = OFF        ; Flash Program Memory Self Write Enable bit (Flash self-write protection off)
     config CLKOUTEN = OFF   ; Clock Out Enable bit (CLKOUT function disabled.  CLKOUT pin acts as I/O)

    #include <xc.inc>

    ;
    ; Power-On-Reset entry point
    ;
        PSECT   Por_Vec,global,class=CODE,delta=2
        global  resetVec
    resetVec:
        goto    main
    ;
    ;   Data space use by interrupt handler to save context
        PSECT   Isr_Data,global,class=RAM,space=1,delta=1,noexec
    ;
        GLOBAL  WREG_save,STATUS_save
    ;
    WREG_save:      DS  1
    STATUS_save:    DS  1
    PCLATH_save:    DS  1
    ;
    ;   Interrupt vector and handler
        PSECT   Isr_Vec,global,class=CODE,delta=2
        GLOBAL  IsrVec
    ;
    IsrVec:
        movwf   WREG_save
        swapf   STATUS,W
        movwf   STATUS_save
        movf    PCLATH,W
        movwf   PCLATH_save
    ;
    IsrHandler:
    ;
    IsrExit:
        movf    PCLATH_save,W
        movwf   PCLATH
        swapf   STATUS_save,W
        movwf   STATUS
        swapf   WREG_save,F
        swapf   WREG_save,W
        retfie                      ; Return from interrupt
    ;
    ; Toggle output bit every 4 instruction cycles.
    ;
        PSECT   MainCode,global,class=CODE,delta=2
    main:
        clrf    INTCON              ;starting point
        BANKSEL PORTA
        clrf    PORTA
        BANKSEL LATA
        clrf    LATA
        BANKSEL ANSELA
        clrf    ANSELA
        BANKSEL TRISA
        clrf    TRISA
        movlw   0xFF
        movwf   OPTION_REG
    ;
    ; Application process init
    ;
        BANKSEL PORTA
        clrf    PORTA
        bsf     PORTA,PORTA_RA0_POSITION
        bsf     PORTA,PORTA_RA1_POSITION
        bsf     PORTA,PORTA_RA2_POSITION
        bsf     PORTA,PORTA_RA4_POSITION
        bsf     PORTA,PORTA_RA5_POSITION
    ;
        BANKSEL LATA
        clrf    LATA
        bsf     LATA,LATA_LATA0_POSITION
        bsf     LATA,LATA_LATA1_POSITION
        bsf     LATA,LATA_LATA2_POSITION
        bsf     LATA,LATA_LATA4_POSITION
        bsf     LATA,LATA_LATA5_POSITION
    ;
    ; Application process loop
    ;
    loop:
        goto    loop

     
    The MPLAB 8 IDE will never be updated so you may need to move on.
     
    #7
    JTW
    Starting Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2012/02/27 08:20:12
    • Location: Australia
    • Status: offline
    Re: 12F752 can't ouput to PORTA,RA5 even in MPLAB simulator 2020/12/02 14:51:42 (permalink)
    0
    Thanks again for showing me how to move on (a bit).
     
    I still can't output from PORTA,RA5.
     
    Digging further into the CONFIG setting up, I see that all the settings default to "1". As you pointed out this is what caused RA5 to be assigned as an oscillator input (apparently unchangeable with a subsequent TRISA instruction). I have now changed this in my CONFIG statement but still no go.
     
    As the defaults for CONFIG are all ones, I could simplify my CONFIG line to:
     
         _CONFIG  _FOSC0_INT  & _MCLRE_ON  & PWRTE_ON
     
    as all other default to "OFF".
     
    Thanks again for your time.
     
    Edit: PWRTE_ON added
    post edited by JTW - 2020/12/02 14:54:05
    #8
    ric
    Super Member
    • Total Posts : 29435
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: 12F752 can't ouput to PORTA,RA5 even in MPLAB simulator 2020/12/02 15:19:30 (permalink)
    0 (2)
    Is this in the simulator or on real hardware?
    As Dan just pointed out, it won't work in the MPLAB8 simulator due to a bug.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    JTW
    Starting Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2012/02/27 08:20:12
    • Location: Australia
    • Status: offline
    Re: 12F752 can't ouput to PORTA,RA5 even in MPLAB simulator 2020/12/02 15:25:02 (permalink)
    0
    Yikes. I missed Dan's post. Thanks.
     
    I did try it in hardware but that was probably before I set the oscillator to internal.
     
    Back to the proto board. I'll update later today.
     
    Thanks,
     
    Jeff
    #10
    JTW
    Starting Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2012/02/27 08:20:12
    • Location: Australia
    • Status: offline
    Re: 12F752 can't ouput to PORTA,RA5 even in MPLAB simulator 2020/12/02 16:47:12 (permalink)
    +2 (2)
    Now running on the hardware and 100%.
     
    Thank you Ric.
     
    Thank you Dan.
     
    Jeff
    #11
    JTW
    Starting Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2012/02/27 08:20:12
    • Location: Australia
    • Status: offline
    Re: 12F752 can't ouput to PORTA,RA5 even in MPLAB simulator 2020/12/03 16:59:16 (permalink)
    +2 (2)
    Application is now complete.
     
    Project was for overload and short circuit protection for a "One Button Dimmer" for LED lighting applications. The reaction time of the comparator needed to be sensitive and fast enough to protect the output FET from frying.
     
    Thanks all,
     
    Jeff
    #12
    Jump to:
    © 2021 APG vNext Commercial Version 4.5