'Проект Часовник еден мал проект и од мене
'**************************************************
'* Name : Sample Clock.pbp *
'* Author : kill *
'* Date : 10.10.2007 г. *
'* Version : 1.0 *
'* Notes : PIC16LF628 *
'**************************************************
'
@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT
@ DEVICE pic16F628A, WDT_OFF
@ DEVICE pic16F628A, PWRT_ON
@ DEVICE pic16F628A, BOD_OFF
@ DEVICE pic16F628A, MCLR_OFF
@ DEVICE pic16F628A, LVP_OFF
@ DEVICE pic16F628A, CPD_OFF
@ DEVICE pic16F628A, PROTECT_OFF
' Подключение ЖКИ:
' LCD PIC
' DB4 PortB.0
' DB5 PortB.1
' DB6 PortB.2
' DB7 PortB.3
' RS PortB.5
' EN PortB.4
' RW GND
' Vdd +5V
' Vss GND
' Vo
' DB0-3 не е приклучен
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 5
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
DEFINE NO_CLRWDT 1
Define OSC 4
wsave var byte $20 system
wsave1 var byte $a0 system
wsave2 var byte $120 system
ssave var byte bank0 system
psave var byte bank0 system
asave var byte bank0 system
csave var byte bank0 system
seconds var byte bank0
minutes var byte bank0
hours var byte bank0
myflags var byte bank0
mode var byte
anybutton var byte
event var myflags.0
j var word
b1 var byte
goto init
'**************************************************
define INTHAND refresh
asm
refresh
movwf wsave
swapf STATUS,W
clrf STATUS
movwf ssave
movf PCLATH,W
movwf psave
bsf TMR1H.7
incf _seconds,F
movlw 60
xorwf _seconds,W
btfss STATUS.Z
goto exit
clrf _seconds
incf _minutes
movlw 60
xorwf _minutes,W
btfss STATUS.Z
goto exit
clrf _minutes
incf _hours
movlw 24
xorwf _hours,W
btfsc STATUS.Z
clrf _hours
exit bsf _myflags.0
bcf PIR1,TMR1IF
movf psave,W
movwf PCLATH
swapf ssave,W
movwf STATUS
swapf wsave,F
swapf wsave,W
retfie
endasm
'**************************************************
init:
porta = 0 : TRISA = %11111111 : high porta.6
portb = 0 : TRISB = %11000000
T1CON = %00001110 ' Асинхрон такт T1OSC
CCP1CON = %00000000 ' CCP/PWM - вклучен
INTCON = %01000000
PIR1 = %00000000
PIE1 = %00000001 ' интерапт TMR1
CMCON = %00000111
seconds = 0
minutes = 0
hours = 12
mode = 2
pause 1000
lcdout $FE,1 ' Бриши LCD
lcdout $FE,128," by KILL ",_
$FE,192," V 1.0 "
pause 2000
TMR1H = $80 ' TMR1 = 32768
TMR1L = 0
T1CON.0 = 1 ' Старт TMR1
INTCON.7 = 1 ' Интерапт
goto begin
'**************************************************
' Подпрограма:
display: ' Прикажиго моменталното време
lcdout $FE,128," ",dec2 hours,":",dec2 minutes,_
":",dec2 seconds," "
event = 0
return
pwrdoun:
TRISA = %11111111
TRISB = %11111111
sleep_:
@ sleep
@ nop
if porta.0 = 0 then sleep_
porta = 0 : TRISA = %10111111 : porta.6 = 1
portb = 0 : TRISB = %11000000
for j = 0 to 1000
if porta.0 = 0 then
j = 0 : goto pwrdoun
endif
pause 1
next j
portb = %00000011
high portb.4 : low portb.4
pause 5
portb = %00000010
high portb.4 : low portb.4
lcdout $EF,40 : lcdout $FE,8 : lcdout $FE,12
lcdout $FE,6 : lcdout $FE,1
return
buttontest:
anybutton = porta & %00111000
select case anybutton
case %00110000
select case mode
case 0
while hours < 23
button porta.3,0,100,50,b1,0,continue
hours = hours + 1
wend
case 1
while minutes < 59
button porta.3,0,100,50,b1,0,continue
minutes = minutes + 1
wend
end select
case %00011000
select case mode
case 0
while hours > 0
button porta.5,0,100,50,b1,0,continue
hours = hours - 1
wend
case 1
while minutes > 0
button porta.5,0,100,50,b1,0,continue
minutes = minutes - 1
wend
end select
case %00101000
button porta.4,0,255,0,b1,0,continue
select case mode
case 0
mode = 1
case 1
mode = 2
case 2
mode = 0
end select
case else
b1 = 0
end select
continue:
return
'**************************************************
' Основен циклус:
begin:
lcdout $FE,192," "
' час:мин:сек
while mode = 2
if event then gosub display
gosub buttontest
if porta.0 = 0 then gosub pwrdoun
wend
T1CON.0 = 0
INTCON.7 = 0
' ...час...
lcdout $FE,192," ^set "
while mode = 0
gosub buttontest
gosub display
wend
' ...мин...
lcdout $FE,192," ^set "
while mode = 1
gosub buttontest
gosub display
wend
' Нулирај
seconds = 0
TMR1H = $80
TMR1L = 0
T1CON.0 = 1
INTCON.7 = 1
goto begin
'**************************************************
end