
list		p=16f84A	; list directive to define processor
	#include	<p16f84A.inc>	; processor specific variable definitions
	__CONFIG _CP_OFF & _WDT_OFF &  _PWRTE_ON & _XT_OSC   
w EQU 0
f EQU 1

DISP_ON 	EQU		 H'0C'
DISP_ON_C	EQU		 H'0E'
DISP_0N_B	EQU 	 H'0F'
DISP_OFF	EQU		 H'08'
CLR_DISP 	EQU 	 H'01'
ENTRY_INC	EQU		 H'06'
ENTRY_INC_S EQU		 H'07'
ENTRY_DEC   EQU 	 H'04'
ENTRY_DEC_S EQU		 H'05'
DD_RAM_ADDR1 EQU 	 H'80'
DD_RAM_ADDR2 EQU	 H'C0'

CBLOCK H'0C'
Counter 
Counter_1
Counter_2
Counter_3
Counter_4
LCD_temp 
BF_temp
Temp
ENDC
#define E PORTA,0
#define RS PORTA,1
#define datchik PORTA,2
ORG H'0000'
goto start
;*******************************************************
start
		BSF STATUS,RP0 
		movlw B'10010001'
		movwf OPTION_REG	
		movlw	B'11111100'
		movwf 	TRISA
		clrf 	TRISB
		bcf 	STATUS,RP0
		clrf	PORTA
		clrf	PORTB
		clrf	Counter
		clrf	Counter_1
		clrf	Counter_2
		clrf	Counter_3
		clrf	Counter_4
		clrf 	LCD_temp
		clrf	BF_temp
		clrf	Temp
		call 	Init_LCD
		call 	send_message
		goto 	main
;********************************************************
Check 	movlw	D'2'
		movwf	Counter 
		call 	Wait 
		return
;**********************************************************
Init_LCD
		movlw	D'200'
		movwf 	Counter
		call 	Wait 
		movlw 	B'00100000'
		movwf 	PORTB
		call 	clock
		movlw	D'40'
		movwf	Counter 
		call 	Wait 
		movlw 	B'00001100'
		call 	Send_command
		call 	clock
		movlw	D'40'
		movwf	Counter 
		call	 Wait
		movlw 	CLR_DISP 
		call 	Send_command
		movlw	B'00000110'
		call 	Send_command
		return 
;**************************************************************
Wait	clrf 	TMR0
again 	bcf		INTCON,T0IF
loop	btfss	INTCON,T0IF
		goto 	loop
		decfsz	Counter,f
		goto 	again 
		return
;****************************************************************	
Send_command 

	movwf 	LCD_temp
	call	Check
	movf	LCD_temp,w
	andlw	H'F0'
	movwf	PORTB
	bcf		RS
	call 	clock
	swapf 	LCD_temp,w
	andlw	H'F0'
	movwf	PORTB
	call 	clock
	return
;******************************************************************
Send_char 

	movwf	LCD_temp
	call 	Check
	movf	LCD_temp,w
	andlw	H'F0'
	movwf	PORTB
	bsf		RS
	call 	clock
	swapf 	LCD_temp,w
	andlw	H'F0'
	movwf	PORTB
	call 	clock
	return


;*********************************************
del     movlw	D'3'		
		movwf	Counter 
		call Wait
		return
;********************************************
clock			bsf 	E
				bcf		E
				return 
;*********************************************
D_1				movf Counter_1,w
             	andlw  0x0F
             	iorlw 0x30
             	return
;*********************************************
D_2				movf Counter_2,w
             	andlw  0x0F
             	iorlw 0x30
             	return
;*********************************************
D_3				movf Counter_3,w
             	andlw  0x0F
             	iorlw 0x30
             	return
;********************************************
D_4				movf Counter_4,w
             	andlw  0x0F
             	iorlw 0x30
             	return
;*********************************************
Up		   		incf  Counter_4,f
				call check_broiach_4
             	return
;********************************************
 check_broiach_4  		movlw D'10'
						xorwf Counter_4,w
						btfss STATUS,Z
						return 
						clrf Counter_4
						incf Counter_3,f
						call check_broiach_3
						return  
;*********************************************
check_broiach_3 		movlw D'10'
						xorwf Counter_3,w
						btfss STATUS,Z
						return 
						clrf Counter_3
						incf Counter_2,f
						call check_broiach_2
						return  
;*********************************************
check_broiach_2  		movlw D'10'
						xorwf Counter_2,w
						btfss STATUS,Z
						return 
						clrf Counter_2
						incf Counter_1,f
						call check_broiach_1
						return  
;*********************************************
check_broiach_1 		movlw D'10'
						xorwf Counter_1,w
						btfss STATUS,Z
						return 
						clrf Counter_1
						clrf Counter_2
						clrf Counter_3
						clrf Counter_4
						return  
;*********************************************
	del_1	
			bsf STATUS,RP0
			movlw B'10010110'
			movwf OPTION_REG	
			bcf 	STATUS,RP0
			call del 
			bsf STATUS,RP0
			movlw B'10010001'
			movwf OPTION_REG	
			bcf 	STATUS,RP0
			return
;*************************************************
main		btfsc	datchik
			goto 	main
			call 	Check
			btfsc	datchik
			goto 	main
			call 	Up
			call 	second_line
	a_d		btfss	datchik
			goto 	a_d
			goto 	main
;*************************************************	
send_message
		movlw 	CLR_DISP 
		call 	Send_command
		movlw 	DD_RAM_ADDR1
		call	Send_command
		movlw	H'A0'
		call	Send_char
		movlw	'P'
		call	Send_char
		movlw	'O'
		call	Send_char
		movlw	H'B1'
		call	Send_char
		movlw	H'AB'
		call	Send_char
		movlw	'H'
		call	Send_char
		movlw	'A'
		call	Send_char
		movlw	' '
		call	Send_char
  		movlw	'C'
		call	Send_char
		movlw	H'A5'
		call	Send_char
		movlw	'C'
		call	Send_char
		movlw	'T'
		call	Send_char
		movlw	'E'
		call	Send_char
		movlw	'M'
		call	Send_char
		movlw	'A'
		call	Send_char
		movlw	' '
		call	Send_char
second_line
		movlw	DD_RAM_ADDR2
		call 	Send_command
		movlw	'H'
		call	Send_char
		movlw	'A'
		call	Send_char
		movlw	'B'
		call	Send_char
		movlw	H'A5'
		call	Send_char
		movlw	'B'
		call	Send_char
		movlw	'K'
		call	Send_char
		movlw	H'A5'
		call	Send_char
		movlw	':'
		call	Send_char
		call 	D_1
		call	Send_char
		call 	D_2
		call	Send_char
		call 	D_3
		call	Send_char
		call 	D_4
		call	Send_char
		movlw	' '
		call	Send_char
		movlw	' '
		call	Send_char
		movlw	' '
		call	Send_char
		movlw	' '
		call	Send_char
		return 
	END
