;******************************************************************************************
;   Program Name : 
;   Programer    :
;   Create date  :
;   History      :
;   Description  :
;******************************************************************************************

	LIST	P=PIC10F200
	INCLUDE	"P10F200.inc"
	__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC 

LP0	EQU	10H
LP1	EQU	11H
LP2	EQU	12H
CNTER	EQU	13H
LPCNT	EQU	14H
LPM0	EQU	15H

	ORG	0
	GOTO	START

; =======================================
;  1.Initialized Segment
; =======================================
START
	MOVLW	B'11000000'	; OPTION_Register (GPWU:GPPU:T0CS:T0SE:PSA:PS2:PS1:PS0)      ==> P.20
	OPTION
	MOVLW	B'11111110'	; OSCCAL_Register (CAL6:CAL5:CAL4:CAL3:CAL2:CAL1:CAL0:FOSC4) ==> P.21
	MOVWF	OSCCAL     	;   Бж [FOSC4]INTOSC/4 Output Enable bit !!!!
	CLRF	GPIO
	MOVLW	B'00001000'
	TRIS	GPIO
	CLRF	CNTER
	CLRF	LPCNT

; =======================================
;  2.Main Program
; =======================================
MAIN
;  (1)Check Push Switch 
	CALL	UP2CNT
	BTFSS	GPIO,3
	GOTO	MAIN

;  (2)Start Program 
;    2-1)Sub loop
	MOVLW	H'14'
	MOVWF	LPM0
MAIN1
	CALL	DSPLED
	CALL	UPCNT
	CALL	WAIT01
	DECFSZ	LPM0,F
	GOTO	MAIN1

;    2-2)Main loop
	MOVFW	LPCNT
	MOVWF	LPM0
MAIN2
	CALL	DSPLED
	CALL	UPCNT
	CALL	WAIT01
	DECFSZ	LPM0,F
	GOTO	MAIN2
;
	CLRF	LPCNT
;
	GOTO	MAIN

;*******************************************************************************************
;   Function Name   : DSPLEDБ@Б@Б@Б@
;   Function        : 
;   Input           :
;   Output          :
;   Description     :  
;*******************************************************************************************
DSPLED
	MOVFW	CNTER
	XORLW	H'00'
	BTFSC	STATUS,Z
	GOTO	DSPLED0
	MOVFW	CNTER
	XORLW	H'01'
	BTFSC	STATUS,Z
	GOTO	DSPLED1
	MOVLW	H'04'
	MOVWF	GPIO
	RETLW	H'00'
DSPLED0
	MOVLW	H'01'
	MOVWF	GPIO
	RETLW	H'00'
DSPLED1
	MOVLW	H'02'
	MOVWF	GPIO
	RETLW	H'00'

;*******************************************************************************************
;   Function Name   : LP2CNTБ@Б@Б@Б@
;   Function        : UP Counter (0-FF)
;   Input           : LPCNT
;   Output          : LPCNT
;   Description     : 
;*******************************************************************************************
UP2CNT
	MOVFW	LPCNT
	XORLW	H'0C'
	BTFSC	STATUS,Z
	GOTO	UP2CNT1
	MOVLW	H'01'
	ADDWF	LPCNT,F
	RETLW	H'00'
UP2CNT1
	MOVLW	H'00'
	MOVWF	LPCNT
	RETLW	H'00'

;*******************************************************************************************
;   Function Name   : UPCNTБ@Б@Б@Б@
;   Function        : UP Counter (0-2)
;   Input           : CNTER
;   Output          : CNTER
;   Description     : 
;*******************************************************************************************
UPCNT
	MOVFW	CNTER
	XORLW	H'02'
	BTFSC	STATUS,Z
	GOTO	UPCNT1
	MOVLW	H'01'
	ADDWF	CNTER,F
	RETLW	H'00'
UPCNT1
	MOVLW	H'00'
	MOVWF	CNTER
	RETLW	H'00'

;*******************************************************************************************
;   Function Name   : WAIT01Б@Б@Б@Б@
;   Function        : About 0.1 Second
;   Input           :
;   Output          :
;   Description     : Internal OSC 4MHz 
;*******************************************************************************************
WAIT01
	MOVLW	H'0A'
	MOVWF	LP2
WAIT01C
	MOVLW	H'64'
	MOVWF	LP1
WAIT01B
	MOVLW	H'64'
	MOVWF	LP0
WAIT01A
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	DECFSZ	LP0,F
	GOTO	WAIT01A
	DECFSZ	LP1,F
	GOTO	WAIT01B
;	DECFSZ	LP2,F
;	GOTO	WAIT01C
;
	RETLW	H'00'

	END


