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
zehn Equ 0x41
; constants
PORTD Equ PORTB
#define LcdE PORTA, 2
#define LcdRw PORTA, 0
#define LcdRs PORTA, 1
#define UPDLCD Flags, 0
#define UPDRBI Flags, 1
org 0x00
goto Main
org 0x04
ISR ;interupt service routine
movwf copyw
swapf STATUS, W
bcf STATUS, RP0
movwf copys
btfsc PIR1, TMR1IF ;Test TMR1 Interrupt-Flag
goto TMR1ISR
btfsc INTCON, RBIF ;Test PORTB Interrupt-Flag
goto RBInt
goto ISRend
TMR1ISR
bcf STATUS, RP0
bcf PIR1, TMR1IF ;clear interupt flag
nop
nop
nop
nop
nop
nop
nop
nop
movlw 0x0B
movwf TMR1H
movlw 0xDA
movwf TMR1L
incf zehn, f
movfw zehn
sublw .10
btfss STATUS, Z
goto ISRend
clrf zehn
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
RBInt
bcf INTCON, RBIF
bsf UPDRBI
goto ISRend
ISRend ;interupt end routine
swapf copys, w
movwf STATUS
swapf copyw, f
swapf copyw, w
bsf UPDLCD
retfie
Init
bcf INTCON, GIE
bcf INTCON, PEIE
bcf INTCON, RBIE
bsf STATUS, RP0
movlw B'11110000'
movwf TRISB
movlw B'00000000'
movwf TRISA
movlw B'00000000'
movwf ANSEL
bcf STATUS, RP0
clrf stde
clrf stdz
clrf mine
clrf minz
clrf seke
clrf sekz
clrf zehn
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
bcf PIE1, TMR1IE
bcf STATUS, RP0
bsf INTCON, RBIE
bsf INTCON, PEIE
bsf INTCON, GIE
return
Main
btfsc UPDLCD
goto WriteLcd
call Init
call InitLCD
call InitTimer
WriteLcd
bcf UPDLCD
btfsc UPDRBI
goto TestRBI
call printzehn
call printseke
call printsekz
call printmine
call printminz
call printstde
call printstdz
movlw b'11001111'
call OutLcdControl
movlw D'10'
movwf loops
call WAIT
goto WriteLcd
TestRBI
bcf UPDRBI
goto StartTMR
StartTMR
bsf STATUS, RP0
bsf PIE1, TMR1IE
bcf STATUS, RP0
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'10'
movwf loops
call WAIT
movlw B'00000010'
call OutLcdControl
movlw B'00101000'
call OutLcdControl
movlw B'00001101'
call OutLcdControl
movlw B'00000001'
call OutLcdControl
movlw B'00000110'
call OutLcdControl
movlw 'C'
call OutLcdDaten
movlw 'l'
call OutLcdDaten
movlw 'o'
call OutLcdDaten
movlw 'c'
call OutLcdDaten
movlw 'k'
call OutLcdDaten
movlw ':'
call OutLcdDaten
movlw ' '
call OutLcdDaten
movlw 'r'
call OutLcdDaten
movlw 'u'
call OutLcdDaten
movlw 'n'
call OutLcdDaten
movlw B'11000011'
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
movlw '.'
call OutLcdDaten
movlw '0'
call OutLcdDaten
return
LcdBusy
bsf STATUS, RP0
movlw B'11111111'
movwf TRISB
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, 3
goto BusyLoop
bcf LcdRw
bsf STATUS, RP0
movlw B'11110000'
movwf TRISB
bcf STATUS, RP0
return
OutLcdControl
movwf LcdDaten
call LcdBusy
swapf LcdDaten, w
andlw H'0F'
movwf PORTD
bsf LcdE
nop
bcf LcdE
movf LcdDaten, w
andlw H'0F'
movwf PORTD
bsf LcdE
nop
bcf LcdE
return
OutLcdDaten
movwf LcdDaten
call LcdBusy
swapf LcdDaten, w
andlw H'0F'
movwf PORTD
bsf LcdRs
bsf LcdE
nop
bcf LcdE
movf LcdDaten, w
andlw H'0F'
movwf PORTD
bsf LcdRs
bsf LcdE
nop
bcf LcdE
bcf LcdRs
return
printzehn
movlw b'11001100'
call OutLcdControl
movfw zehn
addlw '0'
call OutLcdDaten
return
printseke ; ausgabe von seke
movlw b'11001010'
call OutLcdControl
movfw seke
addlw '0'
call OutLcdDaten
return
printsekz
movlw b'11001001'
call OutLcdControl
movfw sekz
addlw '0'
call OutLcdDaten
return
printmine
movlw b'11000111'
call OutLcdControl
movfw mine
addlw '0'
call OutLcdDaten
return
printminz
movlw b'11000110'
call OutLcdControl
movfw minz
addlw '0'
call OutLcdDaten
return
printstde
movlw b'11000100'
call OutLcdControl
movfw stde
addlw '0'
call OutLcdDaten
return
printstdz
movlw b'11000011'
call OutLcdControl
movfw stdz
addlw '0'
call OutLcdDaten
return
end
Was kann hier nur so falsch sein?
Lesezeichen