Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIC12F1840
#1
Hi

I am not getting this to work no matter how hard I try.  There was a thread that had some configuration settings but I lost it...

I tried setting USE_BRGH to 0 since that is what it is after reset and what the datasheet suggests also no luck.

I also tried varius PLL settings.  The hardware uart works if PLL is enabled in the config word but 0 in osscon in Picbasic Pro.

To get this PIC's uart to work without the boot-loader is also tricky so I think I am missing a configuration setting or something.

tx


Attached Files
.zip   ds30 12f1840 8mHz 9600 baud.zip (Size: 56.87 KB / Downloads: 2)
Reply
#2
This is working on my 12F1822 dev board, hopefully it is helpful for you:
Code:
; Set internal oscillator to 16MHz
                banksel    OSCCON
                bsf        OSCCON, IRCF3    
                bsf        OSCCON, SCS1            
                ; Make pins digital
                banksel        ANSELA
                movlw        0x00
                movwf        ANSELA
                ; Disable weak pull-ups
                banksel        WPUA
                movwf        WPUA        
                ; Select rx(ra5) and tx(ra4) pins
                banksel    APFCON
                bsf        APFCON, RXDTSEL
                bsf        APFCON, TXCKSEL    
                ; Light led
                banksel    TRISA
                bcf        TRISA, TRISA2
                banksel LATA
                bsf        LATA, LATA2
Code:
;------------------------------------------------------------------------------
;
; Title:            ds30 Loader for PIC12F and PIC16F
;
; File description:    settings used by the author during development
;
; Copyright:         Copyright © 10-11, Mikael Gustafsson
;                                                                            
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
;    This file is part of ds30 Loader.
;
;    ds30 Loader is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation.
;
;    ds30 Loader is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.
;
;    You should have received a copy of the GNU General Public License
;    along with ds30 Loader. If not, see <http://www.gnu.org/licenses/>.
;------------------------------------------------------------------------------


;------------------------------------------------------------------------------
; Device
;------------------------------------------------------------------------------
        LIST          P=12F1822


;------------------------------------------------------------------------------
; Includes
;------------------------------------------------------------------------------
        #include    "devices.inc"


;------------------------------------------------------------------------------
; User preferences
;------------------------------------------------------------------------------
        radix DEC
    
        #define        DEV_MODE_12F    1                ;xxx delete or comment this line
        #define        FOSC            16000000        ;xxx
        #define        BLINIT            2000            ;xxx hello receive timeout [ms]
        #define        HELLOTRIES        2                ;xxx number of non hello characters received before branching to the user application
        #define        BLTIME            2000            ;xxx data receive timeout [ms]
        

;------------------------------------------------------------------------------
; UART settings
;------------------------------------------------------------------------------
        #define        USE_UART1        1                ;xxx uncomment to use uart1
        ;#define    USE_UART2        1                ;xxx uncomment to use uart2
        #define        BAUDRATE         115200            ;xxx baudrate
        ;#define    USE_ABAUD        1                ;auto baud rate detection, only available on enhanced mid-range devices(?)
        #define        USE_BRGH        1                ;
        #define        USE_BRG16        1                ;16-bit brg, only available on enhanced mid-range devices(?)
        ;#define    USE_TXENABLE    1                ;xxx uncomment to use a tx enable pin        
        ifdef USE_TXENABLE
            #define    TRISR_TXE        TRISA            ;xxx tris register containing tx enable
            #define    PORTR_TXE        PORTA            ;xxx port register containing tx enable
            #define    TRISB_TXE        TRISA3            ;xxx tris bit for tx enable
            #define PORTB_TXE        RA3                ;xxx port bit for tx enable
        endif
        

;------------------------------------------------------------------------------
; SW UART settings
;
; Baud rate constant calculation:
; FCY             = OSCF / 4
; TCY             = 1 / FCY
; BITTIME         = 1 / BAUDRATE
;
; BITWAITCNT     = ((( (BITTIME - 24*TCY) / TCY / 3 ) + 1 ) / 2 )
;
;------------------------------------------------------------------------------
        ;#define        USE_SWUART        1                ;xxx uncomment to use software uart
        #define     BITWAITCNT         2                ;xxx baud rate, see formula above
        
        #define        TRISR_TX        TRISA            ;xxx tris register containing tx
        #define        TRISB_TX        TRISA4            ;xxx tris bit for tx
        #define        LATR_TX            LATA            ;xxx port register containing tx        
        #define     LATB_TX            LATA4            ;xxx port bit for tx
        
        #define        TRISR_RX        TRISA            ;xxx tris register containing tx
        #define        TRISB_RX        TRISA5            ;xxx tris bit for tx
        #define        PORTR_RX        PORTA            ;xxx port register containing tx        
        #define     PORTB_RX        RA5                ;xxx port bit for tx


;------------------------------------------------------------------------------
; I2C settings, commercial version only www.ds30loader.com
;------------------------------------------------------------------------------
;COMMERCIAL_BEGIN
        ;#define     USE_I2C1        1                ;xxx uncomment to use I2C1
        ;#define    USE_I2C2        1                ;xxx uncomment to use I2C2

        #define        ADDR_PIC        14                ;xxx node address for this device, 7 bits
        
        #define        TRISR_SDA        TRISA            ;xxx tris register containing SDA pin
        #define         TRISB_SDA        TRISA2            ;xxx port bit for SDA pin
        #define        TRISR_SCL        TRISA            ;xxx tris register containing SCL pin
        #define     TRISB_SCL        TRISA1            ;xxx port bit for SCL pin
;COMMERCIAL_END


;------------------------------------------------------------------------------
; Advanced settings
;------------------------------------------------------------------------------
        ;#define     KICK_WD            1                ;xxx only uncomment if the watchdog is enabled
        #define        WRITE_VER        1                ;do flash write verification
        #define        EWRITE_VER        1                ;do eeprom write verification
        #define        USE_READ        1                ;uncomment to enable read from GUI, commercial version only    
        
        #define        BLPLW            256                ;bootloader placement, words from end, should be a multiple of 64
        
                
;------------------------------------------------------------------------------
; Configuration bits, these macros can be found at the end of the inc-files located in
; C:\Program Files\Microchip\MPASM Suite\
;
; These can also be set in MPLAB IDE instead, they are found in Configure->Configuration bits...
;------------------------------------------------------------------------------
        __CONFIG    _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
        __CONFIG    _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
Reply
#3
It lives !!!

Turns out the problem was banksel.  After reading your post I did some more reading and it seems like some pic's want you to use banksel, and others don't care either way.

also, you have to set up the apfcon register.

Thank you again Mikael
Reply
#4
Great! Thanks for the feedback.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)