Hi everyone,i am seeking your help.
I am trying to program the PIC 16f877 microcontroller to accept multiple analog inputs and give readouts on the 7-seg display. the conversion is of a 10 bit resolution. my problems are that i cannot seem to get the pic to correctly display the adresh and adresl registers simultaneously. when i display the adresl anone,it is ok because i have tested it using the leds.CAN someone please help me with the codes to display both registers. in addition,i do not know how to measure multiple inputs.

lastly,when i send my codes to the lcd, nothing is displayed. can anyone help me with the correct assembly codes for this pic (16f877).

IF ANYONE HAS CODES I WOULD BE VERY GRATEFUL IF YOU POST THEM.

THANKS!

Hi

Unfortunately, I don't know that microcontroller. However, there are things in common among mcs.

As for example, how do you make your program wait until a/d conversion is completed? Usually you will get the low a/d result first, later follows high result. Therefore you need to wait until conversion is completed, what for example can be signaled by an interrupt or be determined by polling a status register/channel.

I thing, posting in your assembly code previously programmed is good idea, so we can examine it.

-- tesu

There is another aspect to consider:

Your a/d converting result is 10 bits long but with some certainty your mc has 8 bit long registers or 8 bit data bus width (what is more likely).

Therefore, low part of analog result may fill bit 0 up to 7 of low result register. The remaining 3 bits may be stored in bit position 0,1 and 2 of high result register.

So depending on what you are to convert, the high result register will mostly contains zeros. You may test this by a/d converting of the maximum analog value.

If you need a whole number for sending it to LCD display you can put together the contains of high and low result register by SHIFT and AND/OR instructions: whole_number = high * 10H + low

-- tesu

thanks for your response.
Here is my codes. note that this code is working on my 16f877 pic.the codes only displays the values of the adresl register(0-255) although it is a 10 bit conversion. i do not know to how to combine the two registers.please help with this.

also the adc is only responding to inputs to RAO/ANO.i have tried changing the adcon0 register's bits 5-3 to convert various channels inputs but it has not worked.

how may i display multiple inputs on the sev seg display one after the other.

;project to do analog to digital conversion
;done by jwebbo
;2010-07-13

;declearations
porta equ 05
portb equ 06
trisa equ 85
trisb equ 86
portd equ 08
trisd equ 88
porte equ 09
trise equ 89
status equ 03
pclath equ 0A
disreg equ 20
pcl equ 02
r1 equ 26
r2 equ 21
r3 equ 22
r4 equ 23
r5 equ 24
r6 equ 25
r7 equ 27
r8 equ 28
r9 equ 29
r10 equ 30
r11 equ 31
r12 equ 32
r13 equ 33
adresh equ 1E
adresl equ 9E
adcon0 equ 1F
adcon1 equ 9F
pir1 equ 0C
pie1 equ 8C
intcon equ 0B
org 00
clrf status
movlw 00
movwf pclath
goto start

init clrf r1
clrf r2
clrf r3
clrf r4
clrf r5
clrf r6
clrf r7
clrf r8
clrf r9
clrf r10
clrf r11
clrf r12
clrf r13
clrf adresh ;clear a/d result high register.
clrf adresl

bsf status,5
movlw b'11111111'
movwf trisa
movlw b'00000000'
movwf trisb
movlw b'00000000'
movwf trisd
movlw b'00000000'
movwf trise
bcf status,5
movlw b'10000010'
movwf adcon1
movlw b'01000011'
movwf adcon0
retlw 00

delay1 movlw d'24' ;this delay loop is to allow for a correct reading (wait acquisition time).The delay is 24 micro seconds.
movwf r10
loop1 decfsz r10,1
goto loop1
retlw 00

DELAY movlw d'1'
movwf r11
LOOP3 movlw d'1'
movwf r12
LOOP2 movlw d'250'
movwf r13
LOOP1 NOP
DECFSZ r13
GOTO LOOP1
DECFSZ r12
GOTO LOOP2
DECFSZ r11
GOTO LOOP3
RETLW 00

sevseg addwf pcl,f
retlw 3F
retlw 06
retlw 5B
retlw 4F
retlw 66
retlw 6D
retlw 7D
retlw 07
retlw 7F
retlw 6F

start call init
clrf porte

;-----------Initiate a/d conversion----------------
main bcf adcon0,2
bsf adcon0,2 ;this instruction starts the a/d conversion progress.
call delay1 ;waiting for the acquisition time

;once the conversion is completed,the go/done bit is automatically cleared and we need to check for the this.

test btfsc adcon0,2
goto test

;clrf portd,0
clrf r1
clrf r2
clrf r3
clrf r4
clrf r5
clrf r6

movf adresl,w
movwf r1
con_1 movf r1,w
movwf r2 ; will contain 10s and 1s
incf r3,f
movlw d'100'
bcf status,0
subwf r1,f
btfss status,0
goto next
goto con_1
next
decf r3,f
con_2
movf r2,w
movwf r4
incf r5,f
movlw d'10'
bcf status,0
subwf r2,f
btfss status,0
goto next_1
goto con_2

next_1
decf r5,f
goto display

display

movf r3,w
call sevseg
movwf portb
bsf portd,1
call DELAY
bcf portd,1
movf r5,w
call sevseg
movwf portb
bsf portd,2
call DELAY
bcf portd,2

movf r4,w
call sevseg
movwf portb
bsf portd,3
call DELAY
bcf portd,3


movlw d'0' ;these codes displays '0' on the leftmost digit on the sevseg display.
call sevseg
movwf portb
bsf portd,0
call DELAY
bcf portd,0
goto main
end

Are you trying to display numbers 0 - 5 or 0 - 1023? Anyhow, here's the general idea.

If you want to display 0 - 5, I think that you want to treat ADRESH:ADRESL as a 2 byte number. Multiply it by 5 and then divide by 1023. You can get your result in volts by subtracting 1 until you can without getting a negative.

If you want to send a value between 0 - 1023 to the LCD: if you can subtract 1000 from it (2 byte math), then write a 1 in the thousands place of your number on the LCD or a zero if you can't. Then subtract the 100, 10, and 1 from the other positions and write the values to the LCD.

There's a program called MicroCGL (www.microcgl.com) that uses icons to generate a lot of the assembly code for you. The LCD that it uses isn't what you have specified (it generates code for a New Haven LCD) but you may get an idea from it - specifically - how to display numbers. It does AtoD, too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.