Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Urgent help needed, thanks!

Status
Not open for further replies.

apricot_star

New Member
Hi all,

Anyone know how to change "0A" on LCD to "10"?
Becos the LCD only recognise ASCII character so in order for me to display number more than 09, what should i do?
I want it to display from 09 then 10 not 0A, in other words the number should be able to display as per normal when it is exceeding 9.(ex 09,10, 11,12...etc not 09,0A,0B,0C...)

Thanks!

Regards
 
From a character 'c' you convert it to a string as follows
Code:
dh = c / 100
r1 = c % 100
dt = r1 / 10
du = r1 % 10
dh is the hundreds digit, dt is the tens digit, and du is the units digit. To convert the digits to characters add the value of the character '0'.

Let's do an example
Code:
c = 240
dh = c / 100 = 2
r1 = c % 100 = 40
dt = 40 / 10 = 4
du = 40 % 10 = 0

dh + '0' = 0x02 + 0x30 = 0x32
dt + '0' = 0x04 + 0x30 = 0x34
du + '0' = 0x00 + 0x30 = 0x30
 
You don't state which language but, assuming it's asm, I use this
Code:
PutDecimal	clrf	Decimal100	;clear hundreths
Count100s	incf	Decimal100,F	;will inc once too many times
		addlw	0x100-.100	;add-100 (sub 100)
		btfsc	STATUS,C	;gone negative?
		goto	Count100s	;no, keep counting
		addlw	.100		;add back 100
		clrf	Decimal10	;clear tens digit
Count10s	incf	Decimal10,F	;waii also inc once too many
		addlw	0x100-.10	;add-10 (sub 10)
		btfsc	STATUS,C	;gone negative?
		goto	Count10s	;no, keep counting
		movwf	Units		;keep units count -10
		movfw	Decimal100	;get hundredths
		addlw	"0"-1		;convert to ascii and correct for extra inc
		call	PutChar		;print it
		movfw	Decimal10	;same for
		addlw	"0"-1		;tens
		call	PutChar
		movfw	Units		;do units
		addlw	"0"+0ah		;conv to ascii and add back the -10
		goto	PutChar

Mike.
 
Use the method posted by Papabrave or lookup the function itoa().

Mike.
 
What size are your variables and what do you call BCD? An example would be nice. I.E 0b0110010 goes to 0x98.

Mike.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top