Code:
list p=16F88
#include <p16f88.inc>
__CONFIG _CONFIG1, _CP_OFF & _LVP_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _HS_OSC
; variables
copyw Equ 0x20
copys Equ 0x21
LcdDaten Equ 0x22
LcdStatus Equ 0x23
loops Equ 0x24
loops2 Equ 0x25
stde Equ 0x27
stdz Equ 0x2C
mine Equ 0x2D
minz Equ 0x30
seke Equ 0x31 ; einerstelle sekunden
sekz Equ 0x32 ;zehnerstelle sekunden
Flags Equ 0x40
charge Equ 0x41
; constants
PORTC Equ PORTB
PORTD Equ PORTB
;pins LCD
#define LcdE PORTB, 0
#define LcdRw PORTB, 3
#define LcdRs PORTB, 2
#define UPDLCD Flags, 0
org 0x00
goto Main
org 0x04
ISR ;interupt service routine
movwf copyw
swapf STATUS, W
bcf STATUS, RP0
movwf copys
incf charge, f
movfw charge
sublw .10
btfss STATUS, Z
goto ISRendCharge
incf seke, f ;seke +1
movfw seke
sublw .10 ;seke -10 ;result negativ => z=0
btfss STATUS, Z ;test z, if z=1 => skip next order
goto ISRend
clrf seke
incf sekz, f
movf sekz, w
sublw .6
btfss STATUS, Z
goto ISRend
clrf sekz
incf mine, f
movf mine, w
sublw .10
btfss STATUS, Z
goto ISRend
clrf mine
incf minz, f
movf minz, w
sublw .6
btfss STATUS, Z
goto ISRend
clrf minz
incf stde, f
movf stde, w
sublw .10
btfss STATUS, Z
goto ISRend
clrf stde
incf stdz, f
movf stdz, w
sublw .10
btfss STATUS, Z
goto ISRend
clrf stdz
goto ISRend
ISRend ;interupt end routine
bcf STATUS, RP0
bcf PIR1, TMR1IF ;clear interupt flag
swapf copys, w
movwf STATUS
swapf copyw, f
swapf copyw, w
bsf UPDLCD
retfie
ISRendCharge ;interupt end routine
bcf STATUS, RP0
bcf PIR1, TMR1IF ;clear interupt flag
swapf copys, w
movwf STATUS
swapf copyw, f
swapf copyw, w
retfie
Init
bcf INTCON, GIE
bcf INTCON, PEIE
bsf STATUS, RP0
movlw B'00000000'
movwf TRISB
movlw B'00000000'
movwf ANSEL
bcf STATUS, RP0
clrf stde
clrf stdz
clrf mine
clrf minz
clrf seke
clrf sekz
clrf LcdDaten
clrf LcdStatus
return
InitTimer
bcf STATUS, RP0
movlw B'00110101' ;prescaler: 1:8; internal clock; no synchronize; Timer1 enabled
movwf T1CON
bsf STATUS, RP0
bsf PIE1, TMR1IE
bcf STATUS, RP0
bsf INTCON, GIE
bsf INTCON, PEIE
return
Main
btfsc UPDLCD
goto WriteLcd
call Init
call InitLCD
call InitTimer
WriteLcd
bcf UPDLCD
call printseke
call printsekz
call printmine
call printminz
call printstde
call printstdz
movlw D'10'
movwf loops
call WAIT
goto WriteLcd
WAIT
wai movlw .249
movwf loops2
wai2 nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
decfsz loops2, F
goto wai2
decfsz loops, F
goto wai
return
InitLCD
movlw D'15'
movwf loops
call WAIT
movlw B'00110000'
movwf PORTB
bsf LcdE
nop
bcf LcdE
movlw D'5'
movwf loops
call WAIT
movlw B'00110000'
call Control8Bit
movlw B'00110000'
call Control8Bit
movlw B'00100000'
call Control8Bit
movlw B'00000001'
call OutLcdControl
movlw B'00101000'
call OutLcdControl
movlw B'00001000'
call OutLcdControl
movlw B'00000110'
call OutLcdControl
movlw B'00000011'
call OutLcdControl
movlw B'00001111'
call OutLcdControl
movlw B'11000100'
call OutLcdControl
movlw '0'
call OutLcdDaten
movlw '0'
call OutLcdDaten
movlw ':'
call OutLcdDaten
movlw '0'
call OutLcdDaten
movlw '0'
call OutLcdDaten
movlw ':'
call OutLcdDaten
movlw '0'
call OutLcdDaten
movlw '0'
call OutLcdDaten
return
Control8Bit
movwf PORTB
bsf LcdE
nop
bcf LcdE
movlw D'10'
movwf loops
call WAIT
return
LcdBusy
bsf STATUS, RP0
movlw B'11110000'
iorwf TRISB, f
bcf STATUS, RP0
BusyLoop
bcf LcdRs
bsf LcdRw
bsf LcdE
nop
movf PORTD, w
movwf LcdStatus
bcf LcdE
nop
bsf LcdE
nop
bcf LcdE
btfsc LcdStatus, 7
goto BusyLoop
bcf LcdRw
bsf STATUS, RP0
movlw B'00001111'
andwf TRISB, f
bcf STATUS, RP0
return
OutLcdControl
movwf LcdDaten
;call LcdBusy
movf LcdDaten, w
andlw H'F0'
movwf PORTD
bsf LcdE
nop
bcf LcdE
swapf LcdDaten, w
andlw H'F0'
movwf PORTD
bsf LcdE
nop
bcf LcdE
return
OutLcdDaten
movwf LcdDaten
;call LcdBusy
movf LcdDaten, w
andlw H'F0'
movwf PORTD
bsf LcdRs
bsf LcdE
nop
bcf LcdE
swapf LcdDaten, w
andlw H'F0'
movwf PORTD
bsf LcdRs
bsf LcdE
nop
bcf LcdE
bcf LcdRs
return
printseke ; ausgabe von seke
movlw b'11001011'
call OutLcdControl
movfw seke
addlw '0'
call OutLcdDaten
return
printsekz
movlw b'11001010'
call OutLcdControl
movfw sekz
addlw '0'
call OutLcdDaten
return
printmine
movlw b'11001000'
call OutLcdControl
movfw mine
addlw '0'
call OutLcdDaten
return
printminz
movlw b'11000111'
call OutLcdControl
movfw minz
addlw '0'
call OutLcdDaten
return
printstde
movlw b'11000101'
call OutLcdControl
movfw stde
addlw '0'
call OutLcdDaten
return
printstdz
movlw b'11000100'
call OutLcdControl
movfw stdz
addlw '0'
call OutLcdDaten
return
end
Ich habe jetzt weiter noch eine "Warteschelife" mit Faktor 10 eingeführt. (zu Beginn der ISR)
Lesezeichen