PIC Assembler 12 Bit Instruction Device Family Shop Talk

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thank you Bebe

;***** RC CALIBRATION
RCCAL CODE 0x1FF ; processor reset vector
res 1 ; holds internal RC cal value, as a movlw k

This is from 12F508 source code.

What about that part?

See the 1FF address? Last address in 12F509 is03FF.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
;***** RESET VECTOR *****************************************************
RESET CODE 0x000 ; effective reset vector
movwf OSCCAL ; apply internal RC factory calibration

This looks like it can be left alone.

Can it?
 

JohnInTX

Joined Jun 26, 2012
4,787
Yup. The processor actually starts execution at the END of program memory. At that location is a factory-set oscillator calibration in the form of MOVLW xx i.e. load W with the calibration value. After executing this instruction, the program counter rolls over to 000h where the first instruction you need to write is that movwf OSCCAL which writes that calibration value in W to the OSCCAL register. Your programmer has to know to save that value before bulk-erasing the chip in preparation for loading the new program..

Its kind of a kludge.. but it works.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Thank you John

Edited '508 source code.

Used Build and it was successful.

I will add LED to breadboard and run tomorrow.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Will add LED this afternoon.

MPLAB X IDE renamed my source code in tutorial directory.

I think it leaves template files alone in Microchip/ASM/Templates directory thought when you rename them.

Windows opened source file in Notepad.

I have seen this mentioned that you can use and text editor to code.

Seeing is believing!
 

be80be

Joined Jul 5, 2008
2,072
Let's see 12F509
Code:
    list      p=12F509            ; list directive to define processor
    #include <p12F509.inc>        ; processor specific variable definitions

    __CONFIG   _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.




;***** VARIABLE DEFINITIONS
temp    EQU     0x07        ;example variable definition



;**********************************************************************
    ORG     0x3FF             ; processor reset vector

; Internal RC calibration value is placed at location 0x3FF by Microchip
; as a movlw k, where the k is a literal value.

    ORG     0x000             ; coding begins here
    movwf   OSCCAL            ; update register with factory cal value




start 
    nop                       ; example code
    movlw   0xFF              ; example code
    movwf   temp              ; example code

; remaining code goes here






    END                       ; directive 'end of program'
looks the same to me
Code:
    list      p=12F508            ; list directive to define processor
    #include <p12F508.inc>        ; processor specific variable definitions

    __CONFIG   _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.




;***** VARIABLE DEFINITIONS
temp    EQU     0x07        ;example variable definition



;**********************************************************************
    ORG     0x1FF             ; processor reset vector

; Internal RC calibration value is placed at location 0x1FF by Microchip
; as a movlw k, where the k is a literal value.

    ORG     0x000             ; coding begins here
    movwf   OSCCAL            ; update register with factory cal value




start 
    nop                       ; example code
    movlw   0xFF              ; example code
    movwf   temp              ; example code

; remaining code goes here






    END                       ; directive 'end of program'
I never worried about the OSCCAL setting it just saved on the chip and I just add the code microchip said to used to move it so it not lost cause some of these 12f5xx chips are picky as can be if you write over it on misstake.
Just make sure you set this right
Code:
ORG    0x3FF            ; processor reset vector
that changes too but after that just write some asm code and go.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Bebe

Rolling over continuing this to tomorrow AM.

Am using source code for 12F508.

With 12F509 on breadboard programming with PICKit 3.

I will check code then.
 

be80be

Joined Jul 5, 2008
2,072
Here's some bit bang serial code I did for a 12f508 it's just a one line change to use it on a 509 I used udata
variables. Takes headaches away.
Code:
   Filename:     serial.asm                                        *
;    Date:                                                            *
;    File Version:                                                    *
;                                                                     *
;    Author:   Burt E Ratliff                                         *
;    Company:                                                         *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files Required: P12F508.INC                                      *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:                                                           *
;                                                                     *
;**********************************************************************

list      p=12F508            ; list directive to define processor
#include <p12F508.inc>        ; processor specific variable definitions

__CONFIG   _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC

; pin assignments
  
#define  TX  GPIO,0  ; transmit pin on GP0



;***** VARIABLE DEFINITIONS
      UDATA
buffer     res    1           
counter    res    1
Count      res    1


;**********************************************************************


; Internal RC calibration value is placed at location 0x1FF by Microchip
; as a movlw k, where the k is a literal value.

RESET   CODE    0x000           ; effective reset vector
        movwf   OSCCAL          ; update OSCCAL with factory cal value
   
    goto    init              ; jump to main program
init
movlw b'00000000'   ; set I/O
    tris    GPIO
bsf  TX
movlw 'b'               ; sets text to loads buffer with
call start
movlw 'e'
call start
movlw '8'
call start
movlw '0'
call start
movlw 'b'
    call start
movlw 'e'
    call start
movlw ' '
call start
movlw 'w'
call start
movlw 'a'
call start
movlw 's'
call start
movlw ' '
call start
movlw 'h'
call start
movlw 'e'
call start
movlw 'r'
call start
movlw 'e'
call start
movlw 0x0A
call start
movlw 0x0D
call start
    goto init   ;loop for ever
start
movwf buffer
movlw 0x08
movwf counter        ; counts the 8 bits
    bcf   TX             ; set TX low
    call  BItdelay       ; delay to get a 9600 bit rate
TXLoop 
    rrf   buffer ,f      ;send one bit
    btfss STATUS ,C      ; 
    bcf   TX             ;
    btfsc STATUS ,C  ;
    bsf   TX  ;
    call  BItdelay  ;
    decfsz counter,f     ;test if all done
    goto  TXLoop  ;
    bsf   TX  ;
    call  BItdelay  ;
    return
BItdelay                 ; timing delay

    movlw 0x17
    movwf  Count 
Wait   
    nop
    decfsz Count ,f
    goto   Wait
    return

END  ; directive 'end of program'
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Bebe

Really! How do we see the calibration value to write it down?

To be safe. I mean on the 12F509.

Last program memory location hex 3FF. I can doublecheck that in datasheet.

Have PICKit3 and MPLAB IPE.
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Generally.

Is it possible to put in a few lines to send to the terminal?

Think I found Terminal in MPLAB X IDE.

Idea is to make sure compile works and all that.

Code sample for 12F509. IF somebody knocks it out.

DEBUG. So to speak.
 
Last edited:

be80be

Joined Jul 5, 2008
2,072
The code I posted thats what its for I just add the text to send out something to show.

Code:
movwf buffer
movlw 0x08
movwf counter        ; counts the 8 bits
    bcf   TX             ; set TX low
    call  BItdelay       ; delay to get a 9600 bit rate
TXLoop
    rrf   buffer ,f      ;send one bit
    btfss STATUS ,C      ;
    bcf   TX             ;
    btfsc STATUS ,C  ;
    bsf   TX  ;
    call  BItdelay  ;
    decfsz counter,f     ;test if all done
    goto  TXLoop  ;
    bsf   TX  ;
    call  BItdelay  ;
    return
BItdelay                 ; timing delay
    movlw 0x17
    movwf  Count
Wait 
    nop
    decfsz Count ,f
    goto   Wait
    return
END  ; directive 'end of program'
That's what the above code dose
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
Bebe

Thank you!

Okay. We will stick with 'Light an LED'.

I will save this to do a Terminal project on side.

It was dumb idea of mine to see if there was quick DEBUG print to screen.

Basic Stamp's give you wrong ideas.
 

be80be

Joined Jul 5, 2008
2,072
Some one wrote the code for you in the stamp lol. The code I posted is probably close to it just hid from you with the p basic
 

Thread Starter

PICNewbee

Joined Mar 31, 2017
355
'The target circuit may require more power than the debug tool can provide. An external power supply might be necessary.
Connection Failed.'

Getting this message in output window MPLAB X IDE.

What needs to be fixed?

That's with LED circuit disconnected.
 

absf

Joined Dec 29, 2010
1,968
Generally.

Is it possible to put in a few lines to send to the terminal?

Think I found Terminal in MPLAB X IDE.

Idea is to make sure compile works and all that.

Code sample for 12F509. IF somebody knocks it out.

DEBUG. So to speak.
Yes, the program in post #68 is putting text onto the term. The 12F508 doesnt have the UART built in so this technique is called bit bangging.

Here's is the simulation of his program in proteus.

12f509 term.PNG
Allen
 
Top