• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

4mhz internal clock on the 16f1827?

Status
Not open for further replies.

ClydeCrashKop

Well-Known Member
Most Helpful Member
I have been modifying Nigel's 16F628A tutorials to run on the 16F1827. So far I haven't been able to configure them to run on the 4mhz internal clock. I would like to do that to use the LCD routines. Could someone help me with that? This runs okay with the 20mhz crystal but I would like to use the 4mhz internal clock.
Blinks 8 LEDs on PORTB in asm.

C:
;Modified from Tutorial 1.5 - Nigel Goodwin 2002 tutorials from Electrotech online
 
list  p=16f1827      ; list directive to define processor
#include <p16f1827.inc> ; processor specific variable definitions
;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;    __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_ON & _IESO_OFF & _FCMEN_OFF
  __CONFIG _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_ON & _IESO_OFF & _FCMEN_OFF
    __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
 
cblock  0x20    ;start of general purpose registers
  count1    ;used in delay routine
  counta    ;used in delay routine
  countb    ;used in delay routine
endc
LEDPORT Equ PORTB  ;set constant LEDPORT = 'PORTB'
LEDTRIS Equ TRISB  ;set constant for TRIS register
 
org 0x0000  ;org sets the origin, 0x0000 for the 16F628,
    ;this is where the program starts running
; movlw 0x07
; movwf CMCON  ;turn comparators off (make it like a 16F84)
;    bsf  STATUS,  RP0 ;This doesn't work on 16F1827 use BANKSEL instead
BANKSEL TRISB
    movlw  b'00000000'  ;set PortB all outputs
    movwf  LEDTRIS
; bcf STATUS,  RP0 This doesn't work on 16F1827 use BANKSEL instead
BANKSEL PORTB
clrf LEDPORT  ;set all outputs low
Loop
movlw b'10000000'
; movlw b'11111111'
movwf LEDPORT
call Delay  ;this waits for a while!
movlw b'01000000'
movwf LEDPORT
call Delay  ;this waits for a while!
movlw b'00100000'
movwf LEDPORT
call Delay  ;this waits for a while!
movlw b'00010000'
movwf LEDPORT
call Delay  ;this waits for a while!
movlw b'00001000'
movwf LEDPORT
call Delay  ;this waits for a while!
movlw b'00000100'
movwf LEDPORT
call Delay  ;this waits for a while!
movlw b'00000010'
movwf LEDPORT
call Delay  ;this waits for a while!
movlw b'00000001'
movwf LEDPORT
call Delay  ;this waits for a while!
goto Loop  ;go back and do it again
Delay movlw d'250' ;d'250'  ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
end
 
Last edited:

Mike - K8LH

Well-Known Member
Something like this perhaps?

Code:
  __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _IESO_OFF & _FCMEN_OFF
  __CONFIG _CONFIG2, _PLLEN_OFF &_BORV_HI & _LVP_OFF
;
; _PWRTE_OFF    default
; _MCLRE_ON     default
; _CP_OFF       default
; _CPD_OFF      default
; _BOREN_ON     default
; _CLKOUTEN_OFF default
;
; _WRT_OFF      default
; _STVREN_ON    default
; _VCAPEN_OFF   default
;
The following code excerpt turns off the ADC module and changes the INTOSC operation from the default power-up 500-KHz setting to a 4-MHz setting;

Code:
;******************************************************************
;  reset vector                                                   *
;******************************************************************
        org     0x0000
init
;
;  turn off ADC and select digital I/O
;
        banksel ANSELA          ; bank 3                          |B3
        clrf    ANSELA          ; set digital I/O                 |B3
        clrf    ANSELB          ; set digital I/O                 |B3
;
;  setup INTOSC for 4-MHz
;
        banksel OSCCON          ; bank 1                          |B1
        movlw   b'01101010'     ;                                 |B1
        movwf   OSCCON          ; setup 4-MHz INTOSC              |B1
waitfs  btfss   OSCSTAT,HFIOFS  ; stable? yes, skip, else         |B1
        bra     waitfs          ; branch (wait until stable)      |B1
;
;  setup port direction and latch registers
;
Good luck with your project.

Cheerful regards, Mike
 
Last edited:

ClydeCrashKop

Well-Known Member
Most Helpful Member
Thank you Mike.
I appreciate it.
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top