Смекни!
smekni.com

Разработка многофункциональных астрономических часов (стр. 11 из 12)

movf DISP,w

movwf VAL

movf DISP+1,w

movwf VAL+1

movf DISP+2,w

movwf VAL+2

movf DISP+3,w

movwf VAL+3

movf DISP+4,w

movwf VAL+4

movf DISP+5,w

movwf VAL+5

возврат

M_CLR ; очистите запись

movwf FSR

ТОЧНОСТЬ movlw

movwf REG_COUNTER

M_CLR_loop

clrf INDF

incf FSR,f

decf REG_COUNTER,f

btfss STATUS,Z

goto M_CLR_loop

возврат

M_ROL ; вращайтесь запись влево

movwf FSR

M_StorStatus REG_STATUS

clrf REG_COUNTER

M_ROL_loop

M_RetrStatus REG_STATUS

rlf INDF,f

M_StorStatus REG_STATUS

incf FSR,f

incf REG_COUNTER,f

ТОЧНОСТЬ movlw

subwf REG_COUNTER,w

btfss STATUS,Z

goto M_ROL_loop

возврат

M_ROR ; вращается запись вправо

movwf FSR

ТОЧНОСТЬ-1 movlw

addwf FSR,f

M_StorStatus REG_STATUS

clrf REG_COUNTER

M_ROR_loop

M_RetrStatus REG_STATUS

rrf INDF,f

M_StorStatus REG_STATUS

decf FSR,f

incf REG_COUNTER,f

ТОЧНОСТЬ movlw

subwf REG_COUNTER,w

btfss STATUS,Z

goto M_ROR_loop

возврат

M_CMP ; Z <=> X СТАТУСА(C,Z)->

; Набор STATUS,C, если Z => X;

; Набор STATUS,Z, если Z == X

clrf REG_COUNTER

M_CMP_loop

movf REG_COUNTER,w

sublw REG_Z+PRECISION-1

movwf FSR

movf INDF,w

movwf REG_T1

movf REG_COUNTER,w

sublw REG_X+PRECISION-1

movwf FSR

movf INDF,w

subwf REG_T1,f

btfss STATUS,Z

возврат

incf REG_COUNTER,f

ТОЧНОСТЬ movlw

subwf REG_COUNTER,w

btfss STATUS,Z

goto M_CMP_loop

возврат

M_INC ; приращение запись

movwf FSR

ТОЧНОСТЬ movlw

movwf REG_COUNTER

M_INC_loop

incf INDF,f

btfss STATUS,Z

возврат

incf FSR,f

decf REG_COUNTER,f

btfss STATUS,Z

goto M_INC_loop

возврат

M_ADD ; Z + X -> Z

bcf STATUS,C

clrf REG_STATUS

clrf REG_COUNTER

M_ADD_loop

clrf REG_T1

btfsc REG_STATUS,C

incf REG_T1,f

clrf REG_STATUS

movlw REG_X

addwf REG_COUNTER,w

movwf FSR

movf INDF,w

addwf REG_T1,f

btfsc STATUS,C

bsf REG_STATUS,C

movlw REG_Z

addwf REG_COUNTER,w

movwf FSR

movf INDF,w

addwf REG_T1,f

btfsc STATUS,C

bsf REG_STATUS,C

movf REG_T1,w

movwf INDF

incf REG_COUNTER,f

ТОЧНОСТЬ movlw

subwf REG_COUNTER,w

btfss STATUS,Z

goto M_ADD_loop

возврат

M_SUB ; Z - X -> Z

clrf REG_COUNTER

bsf REG_STATUS,C

M_SUB_loop

bsf REG_T2,C

movlw REG_Z

addwf REG_COUNTER,w

movwf FSR

movf INDF,w

movwf REG_T1

movlw REG_X

addwf REG_COUNTER,w

movwf FSR

movf INDF,w

subwf REG_T1,f

btfss STATUS,C

bcf REG_T2,C

btfsc REG_STATUS,C

goto M_SUB_no_carry

movlw 0x01

subwf REG_T1,f

btfss STATUS,C

bcf REG_T2,C

M_SUB_no_carry

movlw REG_Z

addwf REG_COUNTER,w

movwf FSR

movf REG_T1,w

movwf INDF

bsf REG_STATUS,C

btfss REG_T2,C

bcf REG_STATUS,C

incf REG_COUNTER,f

ТОЧНОСТЬ movlw

subwf REG_COUNTER,w

btfss STATUS,Z

goto M_SUB_loop

btfss REG_STATUS,C

bcf STATUS,C

возврат

M_MUL ; X * Y -> Z

movlw REG_Z

вызовите M_CLR

movlw PRECISION*8+1

movwf REG_ROT_COUNTER

LCD_Init

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

movlw 0x00

movwf PORTE

movlw b'00110000'

movwf PORTC

вызовите LCD_PulseZ

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

movlw b'00111000'

movwf PORTC

вызовите LCD_PulseZ

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

movlw b'00111000'

movwf PORTC

вызовите LCD_PulseZ

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

вызовите LCD_Wait

movlw b'00111000'

movwf PORTC

вызовите LCD_PulseZ

movlw b'00001000'

movwf PORTC

вызовите LCD_PulseZ

movlw b'00000001'

movwf PORTC

вызовите LCD_PulseZ

movlw b'00000110'

movwf PORTC

вызовите LCD_PulseZ

movlw b'00001000'

movwf PORTC

вызовите LCD_PulseZ

movlw b'00000010'

movwf PORTC

вызовите LCD_PulseZ

;movlw b'10000000'

;movwf PORTC

;call LCD_PulseZ

;movlw b'00010100'

;movwf PORTC

;call LCD_PulseZ

;movlw b'10000000'

;movwf PORTC

;call LCD_PulseZ

bsf PORTE,0

movlw b'00001100'

вызовите LCD_SendCMD

movlw MSG_ID_Clear

movwf MSG_ID

movwf MSG_ID_CURRENT

возврат

LCD_SendDAT

movwf PORTC

bsf PORTE,0

вызовите LCD_PulseZ

возврат

LCD_SendCMD

movwf PORTC

bcf PORTE,0

вызовите LCD_PulseZ

bsf PORTE,0

возврат

MSG_NextChar_second

banksel EEDATA

movf EEDATA,w

banksel MSGDAT

movwf MSGDAT

bcf MSGDAT,7

incf MSGL,f

btfsc STATUS,Z

incf MSGH,f

bcf MSGH,7

movf MSGDAT,w

возврат

SPK_Delay

movlw 0x0F

movwf TMP

decf TMP,f

btfss STATUS,Z

goto $-2

возврат

SPK_Pip

movlw 0xFF

movwf TMP2

SPK_Pip_0

movlw 0x20

movwf TMP1

SPK_Pip_1

lcall SPK_Delay

decf TMP1,f

btfss STATUS,Z

goto SPK_Pip_1

movlw 0x01<<B_SPK

xorwf PORTA,f

decf TMP2,f

btfss STATUS,Z

goto SPK_Pip_

bcf PORTA,B_SPK

возврат

SPK_Peep

movlw 0x10

movwf TMP3

SPK_Peep_0

вызовите SPK_Pip

decf TMP3,f

btfss STATUS,Z

goto SPK_Peep_0

возврат

SPK_Whip

clrf TMP2

movlw 0xC0

SPK_Whip_0

movf TMP2,w

addlw 0x38

movwf TMP1

SPK_Whip_1

lcall SPK_Delay

decf TMP1,f

btfss STATUS,Z

goto SPK_Whip_1

movlw 0x01<<B_SPK

xorwf PORTA,f

decf TMP2,f

btfss STATUS,Z

goto SPK_Whip_0

возврат

org 0x1000

S00_TimerSelectLoop

clrf LCD_CURSOR_POSITION

SetMsg MSG_ID_Clear

IfJump VK_MENU_NEXT,S00_NextTmr

IfJump VK_MENU_PREV,S00_PrevTmr

IfState VK_MENU_ENTER,S10_AdjustTimer

lgoto SM_Rtn

S00_NextTmr

incf SEL_TMR,f

movlw 0x0F

andwf SEL_TMR,f

bsf FLAGS,F_TMR_LABEL_DIRTY

bsf FLAGS,F_TICK

lgoto SM_Rtn

S00_PrevTmr

decf SEL_TMR,f

movlw 0x0F

andwf SEL_TMR,f

bsf FLAGS,F_TMR_LABEL_DIRTY

bsf FLAGS,F_TICK

lgoto SM_Rtn

S10_AdjustTimer

clrf LCD_CURSOR_POSITION

SetMsg 0x00

IfState VK_MENU_EXIT,S00_TimerSelectLoop

IfState VK_MENU_NEXT,S20_AdjustClock

IfState VK_MENU_PREV,S20_AdjustClock

;IfState VK_MENU_PREV,S30_ThermometerSetup

IfState VK_MENU_ENTER,S11_SetTimer

IfJump VK_START_STOP,S10_StartStopTimer

IfJump VK_DIRECTION,S10_ToggleTimerDirection

lgoto SM_Rtn

S10_StartStopTimer

movlw 0x01<<TMR_ON

lcall ToggleTimerSettings

lgoto SM_Rtn

S10_ToggleTimerDirection

movlw 0x01<<TMR_DIR

lcall ToggleTimerSettings

lgoto SM_Rtn

S11_SetTimer

SetMsg 0x01 ; MSG_SetTimer

IfState VK_MENU_EXIT,S10_AdjustTimer

IfState VK_MENU_NEXT,S12_SetAlarm

IfState VK_MENU_PREV,S13_SetLength

IfState VK_MENU_ENTER,S15_SetTimerValue

lgoto SM_Rtn

S12_SetAlarm

SetMsg 0x07

IfState VK_MENU_EXIT,S10_AdjustTimer

IfState VK_MENU_NEXT,S13_SetLength

IfState VK_MENU_PREV,S11_SetTimer

IfState VK_MENU_ENTER,S21_SetAlarmTime

lgoto SM_Rtn

S13_SetLength

SetMsg 0x04 ; MSG_SetLength

IfState VK_MENU_EXIT,S10_AdjustTimer

IfState VK_MENU_NEXT,S11_SetTimer

IfState VK_MENU_PREV,S12_SetAlarm

IfState VK_MENU_ENTER,S16_SetLengthValue

lgoto SM_Rtn

S15_SetTimerValue

SetMsg 0x06 ; MSG_Set

movlw D_SEL_TIMER

movwf VAL_STAT

GoToState S_EnterValueHMS

lgoto SM_Rtn

S16_SetLengthValue

SetMsg 0x06 ; MSG_Set

movlw D_SEL_TIMER_LENGTH

movwf VAL_STAT

GoToState S_EnterLongValue

lgoto SM_Rtn

S20_AdjustClock

SetMsg 0x02

IfState VK_MENU_EXIT,S00_TimerSelectLoop

IfState VK_MENU_NEXT,S10_AdjustTimer

;IfState VK_MENU_NEXT,S30_ThermometerSetup

IfState VK_MENU_PREV,S10_AdjustTimer

IfJump VK_START_STOP,S20_StartStopClock

IfJump VK_SKIP_FORWARD,S20_StartStopClock

lgoto SM_Rtn

S20_StartStopClock

movlw 0x01<<F_CLOCK_STOPPED

xorwf FLAGS,f

lgoto SM_Rtn

S20_SkipForward

movlw (0x01<<F_CLOCK_STOPPED) % 0xFF

andwf FLAGS,f

incf INT_PULSECTR,f

incf INT_PULSECTR,f

incf INT_PULSECTR,f

incf INT_PULSECTR,f

lgoto SM_Rtn

;S30_ThermometerSetup

; SetMsg 0x03

; IfState VK_MENU_EXIT,S00_TimerSelectLoop

; IfState VK_MENU_NEXT,S10_AdjustTimer

; IfState VK_MENU_PREV,S20_AdjustClock

; lgoto SM_Rtn

S21_SetAlarmTime

SetMsg 0x08

IfState VK_MENU_EXIT,S12_SetAlarm

IfState VK_MENU_NEXT,S22_SetSound

IfState VK_MENU_PREV,S23_AlarmAction

IfState VK_MENU_ENTER,S21_EnterAlarmValue

lgoto SM_Rtn

S21_EnterAlarmValue

SetMsg 0x06 ; MSG_Set

movlw D_SEL_TIMER_ALARM

movwf VAL_STAT

movf SEL_TMR,w

movwf CTR1

lcall LoadSelTmrSettingsAndLen

movlw REG_Z

lcall M_CLR

movlw REG_X

lcall M_CLR

bsf STATUS,IRP ; TUK E PROBLEMAT!!!

lcall MC_Normalize_NO_CLR

bcf STATUS,IRP

lcall MC_NormalizedTo86400

lcall MC_86400toHMS

GoToState S_EnterValueHMS

lgoto SM_Rtn

S22_SetSound

SetMsg 0x09

IfState VK_MENU_EXIT,S12_SetAlarm

IfState VK_MENU_NEXT,S23_AlarmAction

IfState VK_MENU_PREV,S21_SetAlarmTime

IfState VK_MENU_ENTER,S40_SoundSelect

lgoto SM_Rtn

S23_AlarmAction

SetMsg 0x0A

IfState VK_MENU_EXIT,S12_SetAlarm

IfState VK_MENU_NEXT,S21_SetAlarmTime

IfState VK_MENU_PREV,S22_SetSound

IfState VK_MENU_ENTER,S51_SelectAction

lgoto SM_Rtn

S40_SoundSelect

movlw 0x03

andwf SEL_TMR_SETTINGS,w

movwf TMP

btfss STATUS,Z

goto S40_SoundSelect_0

; звук Безмолвен

GoToState S44_SoundSilent

lgoto SM_Rtn

S40_SoundSelect_0

movlw SND_PIP

subwf TMP,w

btfss STATUS,Z

goto S40_SoundSelect_1

; звук - это Косточка

GoToState S41_SoundPip

lgoto SM_Rtn

S40_SoundSelect_1

movlw SND_PEEP

subwf TMP,w

btfss STATUS,Z

goto S40_SoundSelect_2

; звук - это Чирикание

GoToState S42_SoundPeep

lgoto SM_Rtn

S40_SoundSelect_2

; звук - это Кнут

GoToState S43_SoundWhip

lgoto SM_Rtn

lgoto SM_Rtn

S41_SoundPip

SetMsg 0x0B

movlw SND_PIP

вызовите SetSound

IfState VK_MENU_ENTER,S22_SetSound

IfState VK_MENU_EXIT,S22_SetSound

IfState VK_MENU_NEXT,S42_SoundPeep

IfState VK_MENU_PREV,S44_SoundSilent

lgoto SM_Rtn

S42_SoundPeep

SetMsg 0x0C

movlw SND_PEEP

вызовите SetSound

IfState VK_MENU_ENTER,S22_SetSound

IfState VK_MENU_EXIT,S22_SetSound

IfState VK_MENU_NEXT,S43_SoundWhip

IfState VK_MENU_PREV,S41_SoundPip

lgoto SM_Rtn

S43_SoundWhip

SetMsg 0x0D

movlw SND_WHIP

вызовите SetSound

IfState VK_MENU_ENTER,S22_SetSound

IfState VK_MENU_EXIT,S22_SetSound

IfState VK_MENU_NEXT,S44_SoundSilent

IfState VK_MENU_PREV,S42_SoundPeep

lgoto SM_Rtn

S44_SoundSilent

SetMsg 0x0E

movlw SND_SILENT

вызовите SetSound

IfState VK_MENU_ENTER,S22_SetSound

IfState VK_MENU_EXIT,S22_SetSound

IfState VK_MENU_NEXT,S41_SoundPip

IfState VK_MENU_PREV,S43_SoundWhip

lgoto SM_Rtn

Action_SetAddress ; ПРЕДУПРЕЖДЕНИЕ: Это наборы STATUS,IRP! Очистите это после сделанного с INDF

movf SEL_TMR,w

addlw низкий TMR_SETTINGS

movwf FSR

bsf STATUS,IRP

bcf INDF,TMR_ON_ALARM_STOP

bcf INDF,TMR_ON_ALARM_RESET

возврат

S51_SelectAction

btfss SEL_TMR_SETTINGS,TMR_ON_ALARM_RESET

goto S51_SelectAction_ResetOff

S51_SelectAction_ResetOn

btfss SEL_TMR_SETTINGS,TMR_ON_ALARM_STOP

goto S51_SelectAction_GoToReset

S51_SelectAction_GoToBoth

GoToState S54_ActionBoth

lgoto SM_Rtn

S51_SelectAction_GoToReset

GoToState S52_ActionReset

lgoto SM_Rtn

S51_SelectAction_ResetOff

btfss SEL_TMR_SETTINGS,TMR_ON_ALARM_STOP

goto S51_SelectAction_GoToNone

S51_SelectAction_GoToStop

GoToState S53_ActionStop

lgoto SM_Rtn

S51_SelectAction_GoToNone

GoToState S51_ActionNone

lgoto SM_Rtn

S51_ActionNone

SetMsg 0x0F

movf SEL_TMR,w

вызовите Action_SetAddress

movf INDF,w

bcf STATUS,IRP

movwf SEL_TMR_SETTINGS

IfState VK_MENU_ENTER,S23_AlarmAction

IfState VK_MENU_EXIT,S23_AlarmAction

IfState VK_MENU_NEXT,S52_ActionReset

IfState VK_MENU_PREV,S54_ActionBoth

lgoto SM_Rtn

S52_ActionReset

SetMsg 0x10

вызовите Action_SetAddress

bsf INDF,TMR_ON_ALARM_RESET

movf INDF,w

bcf STATUS,IRP

movwf SEL_TMR_SETTINGS

IfState VK_MENU_ENTER,S23_AlarmAction

IfState VK_MENU_EXIT,S23_AlarmAction

IfState VK_MENU_NEXT,S53_ActionStop

IfState VK_MENU_PREV,S51_ActionNone

lgoto SM_Rtn

S53_ActionStop

SetMsg 0x11

вызовите Action_SetAddress

bsf INDF,TMR_ON_ALARM_STOP

movf INDF,w

bcf STATUS,IRP

movwf SEL_TMR_SETTINGS

IfState VK_MENU_ENTER,S23_AlarmAction

IfState VK_MENU_EXIT,S23_AlarmAction

IfState VK_MENU_NEXT,S54_ActionBoth

IfState VK_MENU_PREV,S52_ActionReset

lgoto SM_Rtn

S54_ActionBoth

SetMsg 0x12

вызовите Action_SetAddress

bsf INDF,TMR_ON_ALARM_STOP

bsf INDF,TMR_ON_ALARM_RESET

movf INDF,w

bcf STATUS,IRP

movwf SEL_TMR_SETTINGS

IfState VK_MENU_ENTER,S23_AlarmAction

IfState VK_MENU_EXIT,S23_AlarmAction

IfState VK_MENU_NEXT,S51_ActionNone

IfState VK_MENU_PREV,S53_ActionStop

lgoto SM_Rtn

SetSound

movwf TMP

movlw низкий TMR_SETTINGS

movwf FSR

movf SEL_TMR,w

addwf FSR,f

bsf STATUS,IRP

movlw 0xFC

andwf INDF,f

movf TMP,w

iorwf INDF,f

bcf STATUS,IRP

возврат

S_CopyFromTimer

movlw D_SEL_TIMER_COPY

movwf VAL_STAT

GoToState S_EnterLongValue

lgoto SM_Rtn

S_EnterLongValue ; введите длинное значение

movlw REG_Z

lcall M_CLR

lcall M_MOV_Z_TO_VAL

clrf VAL_IND

addlw 0x80 | 0x44

movwf LCD_CURSOR_POSITION

bsf FLAGS,F_CURSOR_DIRTY

bcf FLAGS,F_VAL_DISPLAY_DIRTY ; НЕ обновите показ VAL - это не используется здесь

GoToState S_EnterLongValue_Digit

lgoto SM_Rtn

S_EnterLongValue_Digit

pagesel $

IfState VK_MENU_EXIT,S_EnterLongValue_End

IfState VK_MENU_ENTER,S_EnterLongValue_Accept

pagesel $

btfsc BTN_ID,7

goto S_EnterLongValue_DigitRTN

movf BTN_ID,w

andlw 0x0F

lcall LOOKUP_DigitFromKeyID

movwf VAL_DIGIT

pagesel $

btfss VAL_DIGIT,7

goto S_EnterLongValue_Digit_1

lgoto SM_Rtn

S_EnterLongValue_Digit_1

movlw REG_Y

lcall M_CLR

movlw .10

movwf REG_Y

lcall M_MOV_VAL_TO_X

lcall M_MUL

movlw REG_X

lcall M_CLR

movf VAL_DIGIT,w

movwf REG_X

lcall M_ADD

lcall M_MOV_Z_TO_VAL

movf VAL_IND,w

addlw LCDCMD_SET_DD_RAM | 0x44