I've never used a 16F1827 ... I just went from the datasheet and my experience with other micros that have bit me in similar ways. My favorite family of micros are the PIC16F15xxx series.
Test
movlb 1
bsf INTCON,PEIE
clrf PIE1 ;turn off TMR2 IE
movlb 0
movlw 250
movwf PR2
movlw b'00100001' ;1:4 prescale, 1:5 postscale
;Net scale = 1:20 x 250 = 5000
movwf T2CON
TMR2_Beat
clrf TMR2 ;probably not necessary
bcf PIR1,1 ;TMR2IF
bsf T2CON,TMR2ON
btfss PIR1,1
bra $-1
bcf T2CON,TMR2ON
nop
bra TMR2_Beat
My two current favourites are these two, lot's of memory and lot's of peripherals, and (most importantly) they both include the SMT timer module, which I use a lot. The new enhanced 16/18 devices are pretty impressive.
movlw 250 ;total scale = 1:20 x 250 = 5000
movwf PR2
movlw b'00100101' ;1:4 prescale, 1:5 postscale
movwf T2CON ;NB:TMR2 runs continuously
TMR2_Beat
bcf PIR1,1
clrf TMR2
btfss PIR1,1
bra $-1
bra TMR2_Beat ;do whatever you need to
putData macro data ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
movlw data ; |
call data2LCD ; |
endm ;
putCmd macro data ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
movlw data ; |
call cmnd2LCD ; |
endm ;
putStr macro string ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
call putStrx ; print in-line string to LCD |
dt string,0 ; null terminated string |
endm ;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; display LCD 'spash' screen for 2 seconds. ~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
radix dec
splash ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
putCmd (128+0) ; LCD line 1, htab 0 |
putStr "VAR RATE V0.01 "
putCmd (192+0) ; LCD line 2, htab 0 |
putStr "ENCODER TEST "
return ; |
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; 'putStrx' - print string embedded in-line with code. ~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
putStrx
banksel TOSL ; bank 31 |31
movf TOSL,W ; copy return address to FSR1 |31
movwf FSR1L ; " |31
movf TOSH,W ; " |31
movwf FSR1H ; " |31
bsf FSR1H,7 ; required for program memory |31
incf TOSL,F ; bump return/string address |31
skpnz ; " |31
incf TOSH,F ; " |31
movlb 0 ; bank 00 |00
movf INDF1,W ; end-of-string (0)? |00
skpnz ; no, skip (send char), else |00
return ; exit (end-of-string) |00
call data2LCD ; send character |00
bra putStrx ; branch (next character) |00
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setup
banksel OSCCON
movlw b'01101000' ;select 4MHz clock = 1MHz instruction cycle
movwf OSCCON ; Set PIC oscillator frequency
banksel T1CON
movlw b'00000001' ;timer 1 on
movwf T1CON
banksel CCP1CON
movlw b'00001011' ;Special Events Trigger
movwf CCP1CON
banksel CCPR1L ;set timer 1 to repeat
movlw low(5000) ;every 500 clock cycles
movwf CCPR1L ;equals 5mS
banksel CCPR1H
movlw high(5000)
movwf CCPR1H
loop
banksel PIR1
btfss PIR1,CCP1IF ;wait for interrupt flag
goto loop ;to be set
;5mS has passed
bcf PIR1,CCP1IF ;clear it
goto loop
Is it because you've got a combination of spaces and tabs?, and the formatting here is slightly different to MPLABX?. I've always presumed that when it messes my formatting upAs promised above, the Special Events code,
Code:setup banksel OSCCON movlw b'01101000' ;select 4MHz clock = 1MHz instruction cycle movwf OSCCON ; Set PIC oscillator frequency banksel T1CON movlw b'00000001' ;timer 1 on movwf T1CON banksel CCP1CON movlw b'00001011' ;Special Events Trigger movwf CCP1CON banksel CCPR1L ;set timer 1 to repeat movlw low(5000) ;every 500 clock cycles movwf CCPR1L ;equals 5mS banksel CCPR1H movlw high(5000) movwf CCPR1H loop banksel PIR1 btfss PIR1,CCP1IF ;wait for interrupt flag goto loop ;to be set ;5mS has passed bcf PIR1,CCP1IF ;clear it goto loop
Mike.
Edit, why does the forum STILL mess up the formatting of code!!!!
I assumed it was and so I copied it into Notepad++ which removes the tabs but it still messes up.Is it because you've got a combination of spaces and tabs?
I also use Notepad++, nice editor, and interesting to hear that it only replaces tabs when you edit a line.I assumed it was and so I copied it into Notepad++ which removes the tabs but it still messes up.
Mike.
Edit, just found out that Notepad++ only replaces tabs when you edit a line.
Spaces and Tabs test using NotePad++
No Tab
One Tab
Spaces instead
Two Tabs
Spaces and Tab
Tab and Spaces
Just Spaces
Back to none.
setup
banksel OSCCON
movlw b'01101000' ;select 4MHz clock = 1MHz instruction cycle
movwf OSCCON ; Set PIC oscillator frequency
banksel T1CON
movlw b'00000001' ;timer 1 on
movwf T1CON
banksel CCP1CON
movlw b'00001011' ;Special Events Trigger
movwf CCP1CON
banksel CCPR1L ;set timer 1 to repeat
movlw low(5000) ;every 500 clock cycles
movwf CCPR1L ;equals 5mS
banksel CCPR1H
movlw high(5000)
movwf CCPR1H
loop
banksel PIR1
btfss PIR1,CCP1IF ;wait for interrupt flag
goto loop ;to be set
;5mS has passed
bcf PIR1,CCP1IF ;clear it
goto loop
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?