Code:
list P=16F84a.inc
; PORTA: 0 -
; 1 -
; 2 -
; 3 -
; 4 -
; PORTB: 0 LCD Display E
; 1
; 2 LCD Display RS
; 3 LCD Display R/W
; 4-7 LCD Display D4 .. D7
#include <P16f84.INC>
__CONFIG _PWRTE_ON & _WDT_OFF & _XT_OSC
w_copy Equ 0x20
s_copy Equ 0x21
LcdDaten Equ 0x22
LcdStatus Equ 0x23
loops EQU 0x24
loops2 EQU 0x25
; Constanten festlegen
PORTControl equ PORTB
PORTData equ PORTB
LcdEnable equ 0
LcdRw equ 3
LcdRs equ 2
Ini_con Equ B'00000000'
Ini_opt Equ B'00000010'
Init bsf STATUS, RP0
movlw Ini_opt
movwf OPTION_REG
movlw B'11111000'
movwf TRISA
movlw B'00000000'
movwf TRISB
bcf STATUS, RP0
clrf PORTA
clrf PORTB
movlw Ini_con
movwf INTCON
BSF TRISA, 0
bsf TRISA, 1
bsf TRISA, 2
bsf TRISA, 3
bsf TRISA, 4
call InitLCD
goto Main
InitLCD
movlw D'255'
movwf loops
call WAIT
movlw B'00110000'
movwf PORTB
bsf PORTB, LcdEnable
nop
bcf PORTB, LcdEnable
movlw D'50'
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
return
Control8Bit
movwf PORTB
bsf PORTB, LcdEnable
nop
bcf PORTB, LcdEnable
movlw D'10'
movwf loops
call WAIT
return
OutLcdControl
movwf LcdDaten
call LcdBusy
movf LcdDaten, w
andlw H'F0'
movwf PORTData
bsf PORTControl, LcdEnable
nop
bcf PORTControl, LcdEnable
swapf LcdDaten, w
andlw H'F0'
movwf PORTData
bsf PORTControl, LcdEnable
nop
bcf PORTControl, LcdEnable
return
WAIT
top movlw .110
movwf loops2
top2 nop
nop
nop
nop
nop
nop
decfsz loops2, F
goto top2
decfsz loops, F
goto top
retlw 0
LcdBusy
bsf PORTA, 1
bsf STATUS, RP0
movlw B'11110000'
iorwf TRISB, f
bcf STATUS, RP0
BusyLoop
bcf PORTControl, LcdRs
bsf PORTControl, LcdRw
bsf PORTControl, LcdEnable
nop
movf PORTData, w
movwf LcdStatus
bcf PORTControl, LcdEnable
nop
bsf PORTControl, LcdEnable
nop
bcf PORTControl, LcdEnable
btfsc LcdStatus, 7
goto BusyLoop
bcf PORTControl, LcdRw
bsf STATUS, RP0
movlw B'00001111'
andwf TRISB, f
bcf STATUS, RP0
bcf PORTA, 1
return
OutLcdDaten
bsf PORTA, 2
movwf LcdDaten
call LcdBusy
movf LcdDaten, w
andlw H'F0'
movwf PORTData
bsf PORTControl, LcdRs
bsf PORTControl, LcdEnable
nop
bcf PORTControl, LcdEnable
swapf LcdDaten, w
andlw H'F0'
movwf PORTData
bsf PORTControl, LcdRs
bsf PORTControl, LcdEnable
nop
bcf PORTControl, LcdEnable
bcf PORTControl, LcdRs
bcf PORTA, 2
return
Bereit
movlw 'B'
movwf LcdDaten
call OutLcdDaten
movlw 'e'
movwf LcdDaten
call OutLcdDaten
movlw 'r'
movwf LcdDaten
call OutLcdDaten
movlw 'e'
movwf LcdDaten
call OutLcdDaten
movlw 'i'
movwf LcdDaten
call OutLcdDaten
movlw 't'
movwf LcdDaten
call OutLcdDaten
goto Maintop
Main
CALL clrdisplay
goto Bereit
Maintop
BTFSC PORTA,0
goto Alarm1
btfsc PORTA,1
goto Alarm2
btfsc PORTA,2
goto Alarm3
btfsc PORTA,3
goto Alarm4
btfsc PORTA,4
goto Alarm5
goto Maintop
Alarm1
CALL clrdisplay
movlw 'A'
movwf LcdDaten
call OutLcdDaten
movlw 'l'
movwf LcdDaten
call OutLcdDaten
movlw 'a'
movwf LcdDaten
call OutLcdDaten
movlw 'r'
movwf LcdDaten
call OutLcdDaten
movlw 'm'
movwf LcdDaten
call OutLcdDaten
movlw '1'
movwf LcdDaten
call OutLcdDaten
goto check1
Alarm2
call clrdisplay
movlw 'A'
movwf LcdDaten
call OutLcdDaten
movlw 'l'
movwf LcdDaten
call OutLcdDaten
movlw 'a'
movwf LcdDaten
call OutLcdDaten
movlw 'r'
movwf LcdDaten
call OutLcdDaten
movlw 'm'
movwf LcdDaten
call OutLcdDaten
movlw '2'
movwf LcdDaten
call OutLcdDaten
Goto check2
Alarm3
call clrdisplay
movlw 'A'
movwf LcdDaten
call OutLcdDaten
movlw 'l'
movwf LcdDaten
call OutLcdDaten
movlw 'a'
movwf LcdDaten
call OutLcdDaten
movlw 'r'
movwf LcdDaten
call OutLcdDaten
movlw 'm'
movwf LcdDaten
call OutLcdDaten
movlw '3'
movwf LcdDaten
call OutLcdDaten
Goto check3
Alarm4
call clrdisplay
movlw 'A'
movwf LcdDaten
call OutLcdDaten
movlw 'l'
movwf LcdDaten
call OutLcdDaten
movlw 'a'
movwf LcdDaten
call OutLcdDaten
movlw 'r'
movwf LcdDaten
call OutLcdDaten
movlw 'm'
movwf LcdDaten
call OutLcdDaten
movlw '4'
movwf LcdDaten
call OutLcdDaten
Goto check4
Alarm5
call clrdisplay
movlw 'A'
movwf LcdDaten
call OutLcdDaten
movlw 'l'
movwf LcdDaten
call OutLcdDaten
movlw 'a'
movwf LcdDaten
call OutLcdDaten
movlw 'r'
movwf LcdDaten
call OutLcdDaten
movlw 'm'
movwf LcdDaten
call OutLcdDaten
movlw '5'
movwf LcdDaten
call OutLcdDaten
Goto check5
check1
btfsc PORTA,0
goto check1
CALL clrdisplay
goto Main
check2
btfsc PORTA,1
goto check2
CALL clrdisplay
goto Main
check3
btfsc PORTA,2
goto check3
CALL clrdisplay
goto Main
check4
btfsc PORTA,3
goto check4
CALL clrdisplay
Goto Main
check5
btfsc PORTA,4
goto check5
CALL clrdisplay
Goto Main
clrdisplay
movlw D'255'
movwf loops
call WAIT
movlw B'00110000'
movwf PORTB
bsf PORTB, LcdEnable
nop
bcf PORTB, LcdEnable
movlw D'50'
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
return
end
Code:
Init bsf STATUS, RP0
movlw Ini_opt
movwf OPTION_REG
movlw B'11111000'
movwf TRISA
movlw B'00000000'
movwf TRISB
bcf STATUS, RP0
clrf PORTA
clrf PORTB
movlw Ini_con
movwf INTCON
BSF TRISA, 0
bsf TRISA, 1
bsf TRISA, 2
bsf TRISA, 3
bsf TRISA, 4
Was hab ich falsch gemacht?
Lesezeichen