[SOLVED] ASSEMBLY_ display the content of ADRESH on LCD

Status
Not open for further replies.

kgavionics

Full Member level 3
Joined
Jun 12, 2012
Messages
167
Helped
7
Reputation
14
Reaction score
11
Trophy points
1,298
Location
Alberta.Canada
Visit site
Activity points
2,482
Hi
I want to display the content of ADRESH register (only 8 bits), so i need to convert the binary number to values between 0 to 255 and then display it on lcd.I need to know is there a way to convert the binary number to ASCII or i need to convert it to decimal then to ASCII.
Any help is appreciated
 

Use this routine for char in which u get 2,5,5 data in answer[3] array.

void int_string(unsigned int q)
{
unsigned char j=0,answer_f[5];
answer_f[0] = (unsigned char)('0'+ ((q%100000)/10000)); // ten thousands place digit ASCII value
answer_f[1] = (unsigned char)('0'+ ((q%10000)/1000)); // thousands place digit ASCII value
answer_f[2] = (unsigned char)('0'+ ((q%1000)/100)); // hundreds place digit ASCII value
answer_f[3] = (unsigned char)('0'+ ((q%100)/10)); // tens place digit ASCII value
answer_f[4] = (unsigned char)('0'+ (q%10)); // units place digit ASCII value
}
 


Thank you for help,but i don't use C.I only use assembly
 

Hi,

Its a good job some of us still do Assembler !:smile:

A couple of sites for useful utilities .



Below is a sub routine to convert the 8 bits to ascii 2 digits.

If you look at that site there is a 16 bit converter so you could display the full 10 bits on the lcd.



Calculator for software delays

**broken link removed**

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
           	  
			return
 
Thx wp100,as always you are very helpful
The main reason i use assembler, that i'm an avionics technician and my field of work is mainly electronics.
I'm gonna try the code
 

Thx wp100,as always you are very helpful
The main reason i use assembler, that i'm an avionics technician and my field of work is mainly electronics.
I'm gonna try the code

Hi,

That routine I posted is good ,I use it all the time, just put the ADRESH into W and call that subroutine, then send DIGITLO AND HI to the lcd.

Assembler is a good way to learn both the soft and hardware basics, though doubtless you will progress onto the higher languages as you work involves more complex procedures.
 

hi
here's the analog to digital conversion working



the code is here
Code:
;=================================================  ===========
; File name:analog to digital conversion on LCD
; Date:
; Author:kgavionics
; Processor:pic16f877a
; Reference circuit:
;=================================================  ===========
; Copyright notice:
;=================================================  ===========
; Program Description:
;
;===========================
; configuration switches
;===========================
list		p=16f877A	; list directive to define processor
	#include	<p16f877A.inc>	; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
;=================================================  ====
; constant definitions
;=================================================  ====
;=================================================  ====
; PIC register equates

;=================================================  ====
;=================================================  ====
; variables in PIC RAM

;=================================================  ====
cblock 0x20
BIN : 1
count : 1
huns : 1
tens : 1
ones : 1
counter1 :  1 
counter2  : 1
number   : 1
timer  : 1
endc
;=================================================  ===========
; program
;=================================================  ===========
org 0X00 ; start at address
goto main
; Space for interrupt handlers
org 0x08
BIN2BCD

;in: BIN
;out huns. tens, ones

;uses ADD-3 algoerthm

	movlw 8
	movwf count
	clrf huns
	clrf tens
	clrf ones
	
	BCDADD3
	
	movlw 5
	subwf huns, 0
	btfsc STATUS, C
	CALL ADD3HUNS
	
	movlw 5
	subwf tens, 0
	btfsc STATUS, C
	CALL ADD3TENS
	
	movlw 5
	subwf ones, 0
	btfsc STATUS, C
	CALL ADD3ONES
	
	decf count, 1
	bcf STATUS, C
	rlf BIN, 1
	rlf ones, 1
	btfsc ones,4 ; 
	CALL CARRYONES
	rlf tens, 1
	
	btfsc tens,4 ; 
	CALL CARRYTENS
	rlf huns,1
	bcf STATUS, C
	
	movf count, 0
	btfss STATUS, Z
	GOTO BCDADD3
	
	
	movf huns, 0 ; add ASCII Offset
	addlw h'30'
	movwf huns
	
	movf tens, 0 ; add ASCII Offset
	addlw h'30'
	movwf tens
	
	movf ones, 0 ; add ASCII Offset
	addlw h'30'
	movwf ones
	
	RETURN
	
	ADD3HUNS
	
	movlw 3
	addwf huns,1
	
	RETURN
	
	ADD3TENS
	
	movlw 3
	addwf tens,1
	
	RETURN
	
	ADD3ONES
	
	movlw 3
	addwf ones,1
	
	RETURN
	
	CARRYONES
	bcf ones, 4
	bsf STATUS, C
RETURN

	CARRYTENS
	bcf tens, 4
	bsf STATUS, C
	RETURN
	
	delay
		movlw	0x0b
		movwf	counter2
	loop1
		movlw	0xff
		movwf	counter1
	loop2
	 	nop
		decfsz counter1
		goto loop2
		decfsz counter2
		goto loop1
return

instw  
	movwf	PORTB
	call delay
	bcf	PORTD,4
	call delay
	bsf	PORTD,5
	call delay
	bcf	PORTD,5
	call	delay
return
dataw 
	movwf PORTB
	call delay
	bsf PORTD, 4
	call delay
	bsf PORTD, 5
	call delay
	bcf PORTD, 5 ;Transitional E signal
	call delay
return
sampledelay
	movlw	100
	movwf	timer
	loop12	
	decfsz timer
	goto loop12
return

convert
	call sampledelay ; provide necessary sampling time
	bsf 	ADCON0,GO ; start conversion
	loop14
	btfsc	ADCON0,GO ; is the conversion over?
	goto  	loop14	   ;loop
	movf	ADRESH,W ; STORE conversion value to W
	movwf   BIN
return
main:
bsf STATUS,RP0
	movlw	0x00
	movwf	TRISB
	movwf	TRISD
	movlw	B'00001000'; ADCON1 VALUE
	movwf	ADCON1 ;ADCON1 SET
	bcf STATUS,RP0
	clrf	PORTD
	clrf	PORTB
InitializeAD
	
	movlw	B'10001001' ;  value to be set to ADCON0
	movwf	ADCON0 ; ADCON0 SET
		
	
	;call delay
	;call delay
start
	clrf PORTD ;Here RW is pulled down to ground
;LCD routine starts
	call delay
;give LCD module to reset automatically
;Fundtion for 8-bit, 2-line display, and 5x8 dot matrix
	
	call   BIN2BCD
	movlw 0x38
	call instw
	call delay
	movlw 0x0E
	call instw
	call delay
	movlw 0x01
	call instw
	call delay

	movlw 0x41
	call dataw
	movlw 0x44
	call dataw 
	movlw 0x43
	call dataw
	movlw 0x20
	call dataw
	movlw 0x43
	call dataw 
	movlw 0x4f
	call dataw 
	movlw 0x4e
	call dataw
	movlw 0x56
	call dataw 
	movlw 0x45
	call dataw
	movlw 0x52
	call dataw
	movlw 0x53
	call dataw
	movlw 0x49
	call dataw
	movlw 0x4f
	call dataw
	movlw 0x4e
	call dataw

	
	kais
	movlw 0xc0
	call  instw ; change the cursor to 2nd line
	call  delay
	call convert
	call  BIN2BCD
	movf huns,w
	call dataw
	movf tens,w
	call dataw 
	movf ones,w
	call dataw
	goto kais
;=================================================  ===========
end ; END OF PROGRAM
;=================================================  ===========
 
Last edited:

Hi,

Very good :smile:

Now lets make it a bit harder ! :evil:

Display the full 1024 steps of the adc result !

You will notice that although it does work, there is a potential problem when it displays, you should see it, but how to over come it ?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…