Hi !!
I was trying to program the LCD and i got pretty far. But i have a problem.
Im using PORDT to send data and PORTB [4-2] for control. im using ADC, channel 0. im simulating the proyect in proteus and making a comparation with 0x02 just to prove that everythings ok.
So the value that the ADC converts im comparing it with 0x02 to see if the ADC value is greater or lower than 2, if its lower its supposed to print on the LCD the number "5" an then go to an endles loop, but my program stays printing "5" endlesly and i dont know what i am doing wrong.
Can you help me figure this out ?
thanks.
my code.
;***** VARIABLE DEFINITIONS (examples)
; example of using Shared Uninitialized Data Section
INT_VAR UDATA_SHR
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
; example of using Uninitialized Data Section
TEMP_VAR UDATA ; explicit address specified is not required
temp_count RES 1 ; temporary variable (example)
; example of using Overlayed Uninitialized Data Section
; in this example both variables are assigned the same GPR location by linker
G_DATA UDATA_OVR ; explicit address can be specified
flag RES 2 ; temporary variable (shared locations - G_DATA)
G_DATA UDATA_OVR
count RES 2 ; temporary variable (shared locations - G_DATA)
;****************************** VARIABLES **********************************
cblock 0x20
Result
d1
d2
d3
Cont1
Cont2
Lcdval
endc
;***************************************************************************
RESET_VECTOR CODE 0x000 ; processor reset vector
movlw high start ; load upper byte of 'start' label
movwf PCLATH ; initialize PCLATH
goto start ; go to beginning of program
INT_VECTOR CODE 0x004 ; interrupt vector location
goto INTERRUPT
MAIN CODE
INTERRUPT
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
;***************************** FUNCTIONS **************************** ; ;
;********************************************************************
Delay_15ms
movlw 0x6E
movwf d1
movlw 0x18
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
goto $+1
nop
return
Delay_Acquisition
movwf Cont2
Again1 movlw 0xFF
movwf Cont1
Again2 nop
decfsz Cont1,f
goto Again2
decfsz Cont2,f
goto Again1
return
Delay_45us
movlw 0x1C
movwf d1
Delay_1
decfsz d1, f
goto Delay_1
nop
return
ENABLE_H
bsf PORTB,4
return
ENABLE_L
bcf PORTB,4
return
lcd_init
bcf PORTB,2
bcf PORTB,3
nop
call ENABLE_H
nop
movlw b'00001111'
movwf PORTD
call Delay_45us
call ENABLE_L
nop
nop
call ENABLE_H
nop
movlw b'00111000'
movwf PORTD
call Delay_45us
call ENABLE_L
nop
nop
return
;***********************************************************************
start
nop ; code starts here (example)
banksel count ; example
clrf count ; example
;************************* PIC INICIALIZATION **********************
;***********************************************************************
bsf STATUS,RP0 ; Bank1
bcf STATUS,RP1
movlw 0xff
movwf TRISA
movlw 0x00
movwf TRISD
movlw 0x00
movwf TRISB
movlw b'01000000' ; Left just, PORTA ANALOG INPUTS[0-7]
movwf ADCON1
bcf STATUS,RP0 ; Bank0
clrf PORTA
clrf PORTB
clrf PORTC
clrf PORTD
clrf PORTE
movlw b'01000001' ; Fosc/16, channel 0, ADC ON
movwf ADCON0
call Delay_15ms
call lcd_init
;********************************************************************
begin
movlw b'01000001' ; Fosc/16, channel 0, ADC ON
movwf ADCON0
movlw 0x01
call Delay_Acquisition ; ADC delay for acquisition
bsf ADCON0,2 ; Start conv
loop
btfsc ADCON0,2
goto loop ; Test if conv ended
movf ADRESH,w
movwf Result ; Mov result of conv to var Result
movlw 0x02
subwf Result,w
btfss STATUS,C ; if result > 2 goto begin, else keep going
goto begin
bsf PORTB,2
nop
call ENABLE_H
nop
movlw b'00110101'
movwf PORTD
call Delay_45us
call ENABLE_L
nop
nop
begin1
goto begin1
END