Continue to Site

# A/D display result to LCD

Status
Not open for further replies.

#### winsthon

##### New Member
Hi everyone I have a problem about PIC16F877 A/D...I want to display the digital output of the analog input signal and convert it as HEX value and display it on the LCD.

I have a code using BASIC but I dont know how to display the HEX equivalent instead I get decimal value. can anyone help me how to do this...Here's my code...

Define ADC_CLOCK = 3 'default value is 3
Define ADC_SAMPLEUS = 10 'default value is 20
Define LCD_BITS = 8 'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTB
Define LCD_DBIT = 0 '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTD
Define LCD_RSBIT = 1
Define LCD_EREG = PORTD
Define LCD_EBIT = 3
Define LCD_RWREG = PORTD 'set to 0 if not used, 0 is default
Define LCD_RWBIT = 2 'set to 0 if not used, 0 is default

Dim an0 As Word
Dim an1 As Word
Dim an2 As Word

TRISA = 0xff 'set all PORTA pins as inputs
Lcdinit 'initialize LCD module; cursor is off

loop:
Lcdcmdout LcdClear 'clear LCD display
Lcdout "Hex Value:" 'text for the line 1
Lcdcmdout LcdLine2Home 'set cursor at the beginning of line 2
Lcdout #an0,#an1,#an2 'formatted text for line 2
WaitMs 2000 'larger value should be used in real device
Goto loop 'loop forever

by the way Im using 3 analog inputs...I want to know the HEX value each of the input and display them on the LCD like FF FF FF 2 bytes only per input and display them together on the LCD. Anyone I appreaciate your help.

#### Nigel Goodwin

##### Super Moderator
I can't help you with PIC BASIC (I don't use it), but it's very easy in assembler. The following routine uses a simple HEX table to look up the ASCII value for each digit and calls the LCD display routine. The rest of it seperates the byte into two nibbles.

Code:
LCD_HEX		movwf	tmp1
swapf	tmp1,	w
andlw	0x0f
call	HEX_Table
call	LCD_Char
movf	tmp1, w
andlw	0x0f
call	HEX_Table
call	LCD_Char
retlw	0x00

RETLW   0x30
RETLW   0x31
RETLW   0x32
RETLW   0x33
RETLW   0x34
RETLW   0x35
RETLW   0x36
RETLW   0x37
RETLW   0x38
RETLW   0x39
RETLW   0x41
RETLW   0x42
RETLW   0x43
RETLW   0x44
RETLW   0x45
RETLW   0x46

#### winsthon

##### New Member
Nigel thanks for replying...I have a question about the code you gave me sorry Im not so familiar with Assembly. I didnt see any LCD initialization on the code can you help me with it...Please kindly include comments. Thanks.

#### Nigel Goodwin

##### Super Moderator
winsthon said:
Nigel thanks for replying...I have a question about the code you gave me sorry Im not so familiar with Assembly. I didnt see any LCD initialization on the code can you help me with it...Please kindly include comments. Thanks.

It's only the HEX section of the code, the complete LCD routines (where I took this section from) are in my tutorials at http://www.winpicprog.co.uk

Status
Not open for further replies.

Replies
12
Views
6K
Replies
3
Views
1K
Replies
4
Views
2K
Replies
1
Views
318
Replies
0
Views
386