Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] ADC result display in LCD PIC 18F4550 in ASSEMBLY

Status
Not open for further replies.

neo_one

Junior Member level 2
Joined
Oct 26, 2011
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,445
I have an ADC result which varies from 0 to 249 in binary. I want to convert this to 00 to 30 which is to be displayed in LCD display. I have already programmed the LCD display in assembly language and is displaying whatever I transfer to it. Just stuck with this conversion. Can anyone please help? I am coding in assembly language. Or just give me the idea if possible. I can work on the coding myself
 

you should multiply the ADC result by 30 and divide by 249
 

Code:
CONV:	BCF STATUS,C
		RRCF 0XFF3,1
		BCF STATUS,C
		RRCF 0XFF3,1
		BCF STATUS,C
		RRCF 0XFF3,1              ; divide by 8 by shifting result to right thrice
TNS:	MOVLW 0X0A
		SUBWF 0XFF3,1
		BN ONS
		INCF TENS                  ; tens place digit obtained
		GOTO TNS
ONS:	MOVLW 0X01
		SUBWF 0XFF3,1
		BN LST
		INCF ONES                  ; ones place digit obtained		
LST:	NOP

Can anyone tell me what is wrong in this code? I have the data in 0xff3. what i want to do is divide it by 8, and then get the decimal equivalent of the result. Divide by 8 is done by shifting result to right.
 

after the last time you substruct 10 from 0xFF3, its value is negative and is NOT the ones value, therefore you will get a wrong result on the ones.
 

if the ADC of controller is producing Binary output then you have to convert the the binary out put of adc to ASCII format and then feed it to the LCD because LCD can only understand the ASCII coads. for conversion you have to add 48 with each binary number produced by ADC of the controller.

suppose for binary 1; you must add 48 (Ascii code for decimal 0) to 1 to make it 49 (Ascii code for decimal 1) that will make your LCD capable to display 1 on the screen.
 

can anyone tell me what is wrong with this code??

Code:
                MOVFF RCREG, 0XFF3 ; binary result of ADC in RCREG
		CALL CONV ; CONVERT RESULT TO ASCI FOR DISPALY IN LCD
		CALL LCDInit
		goto back
;**************************************************************************
; LCD INITIALIZATION

LCDInit:     BCF PORTA,0; CONTROL SIGNAL TO RS
		BCF PORTA,1; CONTROL SIGNAL TO R/W
		BSF PORTA,2; CONTROL SIGNAL TO 'E'
		MOVLW 0x0F
		MOVWF PORTB
		CALL DISPLAY
		MOVLW 'P'
		CALL DISPLAY
		MOVLW 'R'
		CALL DISPLAY
		MOVLW 'E'
		CALL DISPLAY
		MOVLW 'S'
		CALL DISPLAY
		MOVLW 'S'
		CALL DISPLAY
		MOVLW 'U'
		CALL DISPLAY
		MOVLW 'R'
		CALL DISPLAY
		MOVLW 'E'
		CALL DISPLAY
		MOVLW ':'
		CALL DISPLAY
		MOVFF TENS,WREG 
		CALL DISPLAY
		MOVFF ONES, WREG
		CALL DISPLAY
		MOVLW 'p'
		CALL DISPLAY
		MOVLW 's'
		CALL DISPLAY
		MOVLW 'i'
		CALL DISPLAY
		BCF PORTA,0;LCD INPUT=>INSTRUCTION
 		MOVLW 0x01
 		MOVWF PORTB
		CALL DISPLAY
		RETURN
DISPLAY:   
   		MOVWF PORTB
		BCF PORTA,2
		BSF PORTA,2
		BSF PORTA,0
		RETURN

DELAY1:	
		MOVLW	D'13'	 ;DELAY 10ms
		MOVWF	0XFF1
		MOVLW	D'251'
		MOVWF	0XFF2


LOOP:	DECFSZ	0XFF2
		GOTO	LOOP
		DECFSZ	0XFF1
		GOTO	LOOP
		RETURN

CONV:	
	;DIVIDE BY 8 ROUTINE
		BCF STATUS,C
		RRCF 0XFF3,1
		BCF STATUS,C
		RRCF 0XFF3,1
		BCF STATUS,C
		RRCF 0XFF3,1
		BCF STATUS,C
	;OBTAINING TENS PLACE 
TNS:	MOVLW 0X0A
		SUBWF 0XFF3,1
		BN ONS
		INCF TENS
		GOTO TNS
		MOVLW 0X48
		ADDWF TENS,0
	;OBTAINING ONES PLACE
ONS:	MOVLW 0X01
		SUBWF 0XFF3,1
		BN LST
		INCF ONES
		MOVLW 0X48
		ADDWF ONES,0
				
LST:	;NOP
		
RETURN		
 
END

the result is divided by 8 and the result is displayed using a 16x1 LCD display. The result after division is split into tens place and ones place, both of which are called seperately and displayed. I am getting junk values with this program. Please help...

Thanks in advance....
 

can anyone tell me what is wrong with this code??


the result is divided by 8 and the result is displayed using a 16x1 LCD display. The result after division is split into tens place and ones place, both of which are called seperately and displayed. I am getting junk values with this program. Please help...

Thanks in advance....

Hi,

Assume you have done an ADC conversion and are wanting to display the value on a lcd , yes ?

Again assuming you are using just the low 8 bits from ADRESL from the 10 bit result.
Not sure why you need to divide it by 8 ?

Anyway, you simple pass the result though an Ascii converter routine- there are many examples out there.

This site has many that will produce 2 ,3 ,4 or more ascii digits from your 8 or 16 bit result
MPASM, PIC C code, Microchip PIC

Here is a working 8 bit to 2 character routine.
Code:
ascii		nop							; conversion to ASCII
disp_asc:   movwf   	temp			; save W to to "temp"
			clrf   		DIGIT			; clear "digit"

disp_asc_lp movlw   	d'10'		    ; insert 10 decimal in W
           	subwf   	temp,w			; "temp" minus W 
          	btfss   	STATUS,C		; skip next if carry bit set
           	goto    	disp_asc_2
           	movwf   	temp			; move W(temp) to F
           	incf    	DIGIT,f 		; increment "digit" and save in F
           	goto    	disp_asc_lp
disp_asc_2  swapf   	DIGIT,f			; swap "digit: nibbles
           	movf    	temp,w			; move "temp" to W
           	xorwf   	DIGIT,f			; exclusive OR "temp" with "digit"
           	swapf   	DIGIT,w			; swap nibbles of "digit"
           	andlw   	0x0F			; add 15 to W
           	iorlw   	0x30			; OR 8bit litiral 0x30 with W
           	movwf		DIGITHI 		; move W to digitup
           	movf    	DIGIT,w			; move "digit" to W
           	andlw   	0x0F			; add 15 to "digit" (W)
           	iorlw   	0x30			; OR 8bit litiral 0x30 with W
           	movwf		DIGITLO	   		; move W to digitlo


What does confuse me is your first line of code.
MOVFF RCREG, 0XFF3 ; binary result of ADC in RCREG

You use this just before your conversion.
The RCREG is used by the USART, how come you are using that ?
Then you are placing it in 0xFF3 which is the PRODL register , why not address it by name ? - its much better to use your own work register such as WORK1 etc rather than hijack system registers which could cause problems in more complex coding.
 

What does confuse me is your first line of code.
MOVFF RCREG, 0XFF3 ; binary result of ADC in RCREG

You use this just before your conversion.
The RCREG is used by the USART, how come you are using that ?
Then you are placing it in 0xFF3 which is the PRODL register , why not address it by name ? - its much better to use your own work register such as WORK1 etc rather than hijack system registers which could cause problems in more complex coding.

Thanks for your response. I will try this routine you have sent.

Yes. I am using UART. I am using wireless transmission in my system. There is an amplifier in the transmitter ckt. The result received in the other side when divided by 8, i get the binary equivalent of the sending side data (got this experimentally). To display this in LCD, I have to convert it to ASCII. This was where I got stuck.
 

Thanks!!! the program is working...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top