![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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 ADCON1 = 0 'set all PORTA pins as analog inputs Lcdinit 'initialize LCD module; cursor is off loop: Adcin 0, an0 Adcin 1, an1 Adcin 2, an2 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. | |
| |
| | (permalink) |
| 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
HEX_Table ADDWF PCL , f
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 | |
| |
| | (permalink) |
| | |
| |
| | (permalink) | |
| Quote:
| ||
| |