Tachometer source code
;=====Tachometer ======27/03/06==
; iic lcd driver: PCF2113 E
; internal clock
; int osc 4.000 MHz - 1us pe instructiune
; Program realizat de Ing. Bergthaller Iulian-Alexandru
;------------------------------------------------------------
list p=12f629 ;controller
#include
__CONFIG _MCLRE_OFF & _CPD_OFF &_CP_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _BODEN_OFF
radix dec
errorlevel -302 ; suppress message 302 from list file
;------------------------------------------------------------
; cpu init
cblock 0x20 ; Beginn General Purpose-Register
count1
count2
count3
count4
transo
buff
LO_TEMP
HI_TEMP
TEMP3
TEMP2
TEMP1
blank
contor
;--------------------------
endc
#DEFINE setu GPIO, GP3
#DEFINE sclk GPIO, GP1
#DEFINE sdta GPIO, GP0
;------------------------------------------------------------
;------------------------------------------------------------
org 0x00
goto init
org 0x04
;
;------------------------------------------------------------
init bcf STATUS,RP0 ; Bank 0
clrf GPIO ; aus!
movlw 0x07
movwf CMCON ; alle Pins digital (nicht Comp)
bcf INTCON,GIE
bsf STATUS,RP0 ; Bank 1
call 0x3FF
movwf OSCCAL ; 4-MHz-Kalibrierung
movlw 0xF8
movwf TRISIO
bcf STATUS,RP0 ; Bank 0
movlw 0x01
movwf contor
call lcd_ini
;***************************************************
loop
;***************************************************
;* Lcd data subroutine *
;***************************************************
call iict
movlw 0x74
call act
movlw 0x40 ; Co=0, RS=1, set instruction register for next data bytes
call act
movlw 0xD2 ; R
call act
movlw 0xD0 ; P
call act
movlw 0xCD ; M
call act
movlw 0xBA ; :
call act
call iicp
call pause
call set_timer
movf contor,W
call halta
bcf T1CON,0
conversie
movf TMR1L,W ; LO -> LO_TEMP
movwf LO_TEMP
movf TMR1H,W ; HI -> HI_TEMP
movwf HI_TEMP
bcf blank,0 ; invalidate flag
movlw 0x27 ; verifica div. cu 10000
movwf TEMP3
movlw 0x10
movwf TEMP2
call convb
movlw 0x03 ; verifica div. cu 1000
movwf TEMP3
movlw 0xE8
movwf TEMP2
call convb
clrf TEMP3 ; verifica div. cu 100
movlw 0x64
movwf TEMP2
call convb
clrf TEMP3 ; verifica div. cu 10
movlw 0x0A
movwf TEMP2
call convb
clrf TEMP3 ; verifica div. cu 1
movlw 0x01
movwf TEMP2
bsf blank,0 ; remove blank checker in case of zero
call convb
call lcd_home
;*****************************************
btfss setu
call timp
homa goto loop
;*****************************************
convb
clrf TEMP1 ; clear counter
conv_high
movf TEMP3,W
subwf HI_TEMP,W ; TEST: HI_TEMP-TEMP3 >0 ?
btfss STATUS,C
goto conv_end ; resultat negativ, exit
btfss STATUS,Z ; TEST: HI_TEMP-TEMP3 = 0 ?
goto conv_low ; test zero, goto if result > 0
movf TEMP2,W ; Precondition: HI-TEST is zero
subwf LO_TEMP,W ; TEST: LO_TEMP-TEMP2 > 0 ?
btfss STATUS,C ; skip, if true
goto conv_end ; result negativ, exit
conv_low
movf TEMP3,W
subwf HI_TEMP,F ; STORE: HI_TEMP = HI_TEMP - TEMP3
movf TEMP2,W
subwf LO_TEMP,F ; STORE: LO_TEMP = LO_TEMP - TEMP2
btfss STATUS,C ; skip, if true
decf HI_TEMP,F ; decrement HI
incf TEMP1,F ; increment counter
bsf blank,0 ; invalidate flag
goto conv_high
conv_end
movlw 0xB0
addwf TEMP1,W ; B0 is ascii offset, add counter
btfss blank,0 ; check flag
movlw 0xA0 ; clear preceeding zeros
movwf buff
call push_lcd
return
;*****************************************
lcd_home
call iict
movlw 0x74
call act
movlw 0x80
call act
movlw 0x02
call act
call iicp
return
;***************************************************
push_lcd
call iict
movlw 0x74
call act
movlw 0x40 ; Co=0, RS=1, set instruction register for next data bytes
call act
movf buff,W
call act
call iicp
return
;***************************************************
set_timer
clrf T1CON
clrf TMR1L
clrf TMR1H
clrf INTCON
bsf STATUS,RP0
clrf PIE1
bcf STATUS,RP0
clrf PIR1
movlw 0x03
movwf T1CON
return
;***************************************************
;* Lcd init commands *
;***************************************************
lcd_ini call iict ; i2c start
movlw 0x74 ; device write address (75h for read)
call act ; i2c send subroutine
movlw 0x00 ; Co,RS=0, set instruction register for multiple next command bytes
call act
movlw 0x01 ; clear DDRAM
call act
movlw 0x21 ; 1 linie mod extins
call act
movlw 0xA0 ; vlcd
call act
movlw 0x07 ; col/row connection
call act
movlw 0x24 ; 2 linii mod normal
call act
movlw 0x0F ; lcd on
call act
movlw 0x06 ; direction
call act
;***************************************************
;* Lcd icon sets off *
;***************************************************
call iict
movlw 0x74
call act
movlw 0x80 ; Co=1, RS=0 just one next command byte
call act
movlw 0x40 ; set CGRAM for icons
call act
movlw 0x40 ; Co=0, RS=1, set instruction register for multiple next data bytes
call act
movlw 0x00 ; erase icons sequence
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
movlw 0x00
call act
call iicp ; i2c stop
;***************************************************
;* Lcd cursor subroutine *
;***************************************************
call iict
movlw 0x74
call act
movlw 0x00
call act
movlw 0x30
call act
movlw 0x01 ; clears entire display and sets DDRAM address to 0 in address counter
call act
movlw 0x0C ; display on, (cursor off, cursor blink off 0C)
call act
call iicp
return
;***************************************************
act movwf transo ; iic data transmission
movlw 0x08
movwf count3
vbit bcf sclk
call pause
btfsc transo,7
bsf sdta
btfss transo,7
bcf sdta
call pause
bsf sclk
call pause
bcf sclk
call pause
rlf transo,f
decfsz count3,f
goto vbit
call ackp
return
;***************************************************
iicp bcf sdta ; stop condition module
call pause
bsf sclk
call pause
bsf sdta ; stop command
call pause
bcf sclk
call pause
return
;***************************************************
iict bsf sdta ; start condition module
bsf sclk
call pause
bcf sdta ; start command
call pause
bcf sclk
call pause
return
;***************************************************
ackp bsf sclk ; one clock step for acknowledge (not read)
call pause
bcf sclk
call pause
return
;***************************************************
timp call iict
movlw 0x74
call act
movlw 0x40 ; Co=0, RS=1, set instruction register for next data bytes
call act
movlw 0xC2 ; B
call act
movlw 0xE1 ; a
call act
movlw 0xFA ; z
call act
movlw 0xE1 ; a
call act
movlw 0xBA ; :
call act
movlw 0xB0
addwf contor,W ; B0 is ascii offset, add counter
call act
movlw 0xF3 ; s
call act
call iicp
call haltb
btfsc setu
goto tset
tset1 movlw 0x01
subwf contor,W
btfss STATUS,Z
goto tset6
movlw 0x06
movwf contor
call iict
movlw 0x74
call act
movlw 0x80
call act
movlw 0x1C
call act
movlw 0x1C
call act
call iicp
call pause
call iict
movlw 0x74
call act
movlw 0x40 ; Co=0, RS=1, set instruction register for next data bytes
call act
movlw 0xB0
addwf contor,W ; B0 is ascii offset, add counter
call act
call iicp
goto tset
tset6
movlw 0x01
movwf contor
call iict
movlw 0x74
call act
movlw 0x80
call act
movlw 0x10
call act
call iicp
call pause
call iict
movlw 0x74
call act
movlw 0x40 ; Co=0, RS=1, set instruction register for next data bytes
call act
movlw 0xB0
addwf contor,W ; B0 is ascii offset, add counter
call act
call iicp
tset call haltb
btfss setu
goto tset1
call haltb
btfss setu
goto tset1
call haltb
btfss setu
goto tset1
return
;***************************************************
pause movlw 0x10
movwf count2
d2 decfsz count2,F
goto d2
return
;***************************************************
haltb movlw 0xFA
movwf count1
j1 movlw 0xFA
movwf count2
j2 nop
decfsz count2,F
goto j2
decfsz count1,F
goto j1
return
;***************************************************
halta
movwf count4
r4 movlw 0x04
movwf count3
r3 movlw 0xFA
movwf count1
r1 movlw 0xFA
movwf count2
r2 nop
decfsz count2,F
goto r2
decfsz count1,F
goto r1
decfsz count3,F
goto r3
decfsz count4,F
goto r4
return
;------------------------------------------------------------
org 0x3FF ;
retlw 0x5C ; !!!! use the read value from chip before erase
;------------------------------------------------------------
end
;============================================================
The hex code can be download from
here.
Back to my home page
Last updated April, 2006
© Copyright 2006 Bergthaller Iulian-Alexandru
|