PROCESSOR 16F877A
LIST P=16f877A
INCLUDE <P16F877A.INC>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
;:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:*:
;DECLARE VARIABLES
CNT EQU 0X28
;START PROGRAM
ORG 0 ;START @ ADDRESS 0
MAIN:
;CONFIGURE I/O PINS
BSF STATUS,RP0 ;SELECT BANK1 TO
BCF STATUS,RP1; ACCESS SFRs IN BANK1
CLRF TRISB ;CONGIGURE PORTB AS OUTPUT O/P
CLRF TRISD
;CLRF TRISC
BSF TRISA,0
MOVLW b'00000111'
MOVWF OPTION_REG
BCF STATUS,RP0 ; Selection of memory bank 0
CLRF PORTB ; Setting PORTB to "0000000"
CLRF PORTD ; Setting PORTD to "0000000"
CALL InitiateLCD
BCF STATUS,RP1; ACCESS SFRs IN BANK1
MOVLW B'00001110'
MOVWF ADCON1
BCF STATUS,RP0 ;RETURN BACK TO BANK0
MOVLW B'11000001'
MOVWF ADCON0
BEGIN:
;CALL InitiateLCD
MOVLW .28 ; load counter
MOVWF CNT
LOOP
DECFSZ CNT,f ; and delay 20us
GOTO LOOP
BSF ADCON0,GO ; start ADC..
wait
BTFSC ADCON0,GO ; ..and wait for finish
GOTO wait
MOVF ADRESH,W
SUBLW D'11' ;15=30c 13=27c
BTFSS STATUS,C
goto More
;LESS
BCF STATUS,RP0 ;RETURN BACK TO BANK0
BCF PORTD,2
;MOVLW B'00000000'
;MOVWF PORTC
BCF PORTD,RD0 ; Setting RS as 0 (Sends commands to LCD)
MOVLW b'00000010' ; Set cursor home
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
BSF PORTD,RD0 ; Setting RS as 1 (Sends information to LCD)
CALL DELAY_5ms
MOVLW d'67' ; Print character "C"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'79' ; Print character "O"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'76' ; Print character "L"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'68' ; Print character "D "
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'32' ; Print character " "
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'60' ; Print character "< "
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'50' ; Print character "2"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'48' ; Print character "0"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'67' ; Print character "C"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
;BCF STATUS,RP0 ;RETURN BACK TO BANK0
GOTO BEGIN
More
BCF STATUS,RP0 ;RETURN BACK TO BANK0
BCF PORTD,2
; MOVLW B'01000000'
;MOVWF PORTC
BCF PORTD,RD0 ; Setting RS as 0 (Sends commands to LCD)
MOVLW b'00000010' ; Set cursor home
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
BSF PORTD,RD0 ; Setting RS as 1 (Sends information to LCD)
CALL DELAY_5ms
MOVLW d'87' ; Print character "W"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'65' ; Print character "A"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'82' ; Print character "R"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'77' ; Print character "M"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'32' ; Print character " "
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'62' ; Print character ">"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'50' ; Print character "2"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'48' ; Print character "0"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW d'67' ; Print character "C"
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
GOTO BEGIN
Enable BSF PORTD,1 ; E pin is high, (LCD is processing the incoming data)
NOP
BCF PORTD,1 ; E pin is low, (LCD does not care what is happening)
RETURN
DELAY_5ms
MOVLW .5 ; Delay of 5 ms
MOVWF TMR0
LOOP3 BTFSS INTCON,2
GOTO LOOP3
BCF INTCON,2
RETURN
InitiateLCD
BCF PORTD,RD0 ; Setting RS as 0 (Sends commands to LCD)
CALL DELAY_5ms
MOVLW b'00000001' ; Clearing display
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW b'00111000' ; Funtion set
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW b'00001100' ; Display on off
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW b'00000110' ; Entry mod set
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
RETURN
END