Header file section and internal clock

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Hi all!

Below is what i have written so far with regards to setting up the chip and i also want to set the PIC16F690 internal clock to 4Mhz!

BUT now my concern is where does it say that it's the internal clock that has been chosen and where does it say that 4Mhz has been chosen as well???

Do i have to write something else specify "internal clock and 4Mhz"? in other words how does one set the internal clock with a 4 Mhz frequency??


Thanks all for you comments!!!
list p=16F690 ; tell assembler what chip we are using
#include <p16F690.inc> ; include the default for the chip

__CONFIG _CP_OFF & _CPD_OFF & _BOR_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _FCMEN_OFF & _IESO_OFF
errorlevel -302 ; suppress the bank sel check warnings

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The labels following the directive are located in the respective .inc file.
 

MMcLaren

Joined Feb 14, 2010
861
If it helps to see an example, here's how I do it;

Rich (BB code):
;******************************************************************
;                                                                 *
;   Filename: AAC 690+LCD.asm                                     *
;     Author: Mike McLaren, K8LH   (k8lh_at_arrl.net)             *
;    (C)2010: Micro Application Consultants                       *
;       Date: 01-Apr-10                                           *
;                                                                 *
;    16F690 (4-MHz INTOSC) + HD44780 2x16 LCD + DS18B20 Demo'     *
;                                                                 *
;                                                                 *
;      MPLab: 8.50    (tabs=8)                                    *
;      MPAsm: 5.35                                                *
;                                                                 *
;******************************************************************

        #include        <p16f690.inc>
        radix dec
        list st=off
        errorlevel -302,-224

;--< config fuses >------------------------------------------------

  __config  _FCMEN_OFF& _IESO_OFF& _MCLRE_OFF& _WDT_OFF& _INTOSCIO

;  _FCMEN_OFF           ; -- fail safe clock monitor enable off
;  _IESO_OFF            ; -- int/ext switch over enable off
;  _BOR_ON              ; default, brown out reset on
;  _CPD_OFF             ; default, data eeprom protection off
;  _CP_OFF              ; default, program code protection off
;  _MCLR_OFF            ; -- use MCLR pin as digital input
;  _PWRTE_OFF           ; default, power up timer off
;  _WDT_OFF             ; -- watch dog timer off
;  _INTOSCIO            ; -- internal osc, OSC1 and OSC2 I/O


;--< variables >---------------------------------------------------


;--< constants >---------------------------------------------------


;******************************************************************
;  reset vector                                                   *
;******************************************************************
        org     0x000
v_reset
        clrf    STATUS          ; force bank 0 and IRP = 0        |B0
        goto    Init            ;                                 |B0

;******************************************************************
;  interrupt vector                                               *
;******************************************************************
        org     0x004
v_interrupt



;******************************************************************
;  main init                                                      *
;******************************************************************
Init
        bsf     STATUS,RP1      ; bank 2                          |B2
        clrf    ANSEL           ; turn off analog pin functions   |B2
        clrf    ANSELH          ;                                 |B2
        bcf     STATUS,RP1      ; bank 0                          |B0
        bsf     STATUS,RP0      ; bank 1                          |B1

;       movlw   b'01110000'     ; setup INTOSC for 8-MHz          |B1
;       movwf   OSCCON          ;                                 |B1
;       btfss   OSCCON,HTS      ; osc stable? yes, skip, else     |B1
;       goto    $-1             ; test again                      |B1

        movlw   b'00001000'     ; RA3 input                       |B1
        movwf   TRISA           ;                                 |B1
        movlw   b'10000000'     ; RB7 input                       |B1
        movwf   TRISB           ;                                 |B1
        clrf    TRISC           ; RC7..RC0 all outputs            |B1
        bcf     STATUS,RP0      ; bank 0                          |B0
        clrf    PORTA           ;                                 |B0
        clrf    PORTB           ;                                 |B0
        clrf    PORTC           ;                                 |B0
;
 
Last edited:

MMcLaren

Joined Feb 14, 2010
861
Please note that 4-MHz is the default INTOSC configuration on the 16F690 so you don't need to include the instructions in that listing that modify the OSCCON register (the four instructions that are commented out)...

Regards, Mike
 
Top