Header file section and internal clock

Discussion in 'Embedded Systems and Microcontrollers' started by Eric007, Aug 26, 2011.

  1. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,041
    33
    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.
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    That' most of it, you also have to set the IRCF bits of the OSCCON register. See Section 3.2 and FIGURE 3-1.
     
  3. MMcLaren

    Well-Known Member

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

    Code ( (Unknown Language)):
    1. ;******************************************************************
    2. ;                                                                 *
    3. ;   Filename: AAC 690+LCD.asm                                     *
    4. ;     Author: Mike McLaren, K8LH   (k8lh_at_arrl.net)             *
    5. ;    (C)2010: Micro Application Consultants                       *
    6. ;       Date: 01-Apr-10                                           *
    7. ;                                                                 *
    8. ;    16F690 (4-MHz INTOSC) + HD44780 2x16 LCD + DS18B20 Demo'     *
    9. ;                                                                 *
    10. ;                                                                 *
    11. ;      MPLab: 8.50    (tabs=8)                                    *
    12. ;      MPAsm: 5.35                                                *
    13. ;                                                                 *
    14. ;******************************************************************
    15.  
    16.         #include        <p16f690.inc>
    17.         radix dec
    18.         list st=off
    19.         errorlevel -302,-224
    20.  
    21. ;--< config fuses >------------------------------------------------
    22.  
    23.   __config  _FCMEN_OFF& _IESO_OFF& _MCLRE_OFF& _WDT_OFF& _INTOSCIO
    24.  
    25. ;  _FCMEN_OFF           ; -- fail safe clock monitor enable off
    26. ;  _IESO_OFF            ; -- int/ext switch over enable off
    27. ;  _BOR_ON              ; default, brown out reset on
    28. ;  _CPD_OFF             ; default, data eeprom protection off
    29. ;  _CP_OFF              ; default, program code protection off
    30. ;  _MCLR_OFF            ; -- use MCLR pin as digital input
    31. ;  _PWRTE_OFF           ; default, power up timer off
    32. ;  _WDT_OFF             ; -- watch dog timer off
    33. ;  _INTOSCIO            ; -- internal osc, OSC1 and OSC2 I/O
    34.  
    35.  
    36. ;--< variables >---------------------------------------------------
    37.  
    38.  
    39. ;--< constants >---------------------------------------------------
    40.  
    41.  
    42. ;******************************************************************
    43. ;  reset vector                                                   *
    44. ;******************************************************************
    45.         org     0x000
    46. v_reset
    47.         clrf    STATUS          ; force bank 0 and IRP = 0        |B0
    48.         goto    Init            ;                                 |B0
    49.  
    50. ;******************************************************************
    51. ;  interrupt vector                                               *
    52. ;******************************************************************
    53.         org     0x004
    54. v_interrupt
    55.  
    56.  
    57.  
    58. ;******************************************************************
    59. ;  main init                                                      *
    60. ;******************************************************************
    61. Init
    62.         bsf     STATUS,RP1      ; bank 2                          |B2
    63.         clrf    ANSEL           ; turn off analog pin functions   |B2
    64.         clrf    ANSELH          ;                                 |B2
    65.         bcf     STATUS,RP1      ; bank 0                          |B0
    66.         bsf     STATUS,RP0      ; bank 1                          |B1
    67.  
    68. ;       movlw   b'01110000'     ; setup INTOSC for 8-MHz          |B1
    69. ;       movwf   OSCCON          ;                                 |B1
    70. ;       btfss   OSCCON,HTS      ; osc stable? yes, skip, else     |B1
    71. ;       goto    $-1             ; test again                      |B1
    72.  
    73.         movlw   b'00001000'     ; RA3 input                       |B1
    74.         movwf   TRISA           ;                                 |B1
    75.         movlw   b'10000000'     ; RB7 input                       |B1
    76.         movwf   TRISB           ;                                 |B1
    77.         clrf    TRISC           ; RC7..RC0 all outputs            |B1
    78.         bcf     STATUS,RP0      ; bank 0                          |B0
    79.         clrf    PORTA           ;                                 |B0
    80.         clrf    PORTB           ;                                 |B0
    81.         clrf    PORTC           ;                                 |B0
    82. ;
    83.  
     
    Last edited: Aug 26, 2011
  4. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,041
    33
    Thanksssssss MMclaren!!!!!
     
  5. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    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
     
  6. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,041
    33
    Perfect!!! I'm learning so much in this forum...

    Thanks Mike!
     
Loading...