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.

Pic18f4550 adc

Status
Not open for further replies.
Ok adrianvon.... The command IS btfsc however.. The call is a two word instruction so the btfsc doesn't work.. you'll have to branch using BNZ

The other fault is MOVLW REG1...... this moves the address into W not the value of REG1... You must use MOVF REG1,W
Code:
STOP
	MOVLW .1                                    
	MOVWF REG1 
	MOVF REG1,W
	SUBLW .3
	BNZ  lp1
	CALL LCD_ARROW_3 
lp1	MOVF REG1,W
	SUBLW .2
	BNZ lp2
	CALL LCD_ARROW_2 
lp2	MOVF REG1,W
	SUBLW .1
	BNZ lp3
	CALL LCD_ARROW_1
lp3	GOTO STOP
 
Hi Ian Rogers, can you please explain to me how the bin2bcd routine you gave me (post number 112) works?

Thanks in advance.
 
I'm not entirely sure.... I have analyzed the code and discovered that the first three shifts, will end up in the tens (our hundreds) by using 0x3 we can identify any digit that may breach the number 9, before shifting, and deal with it... The end result is a packed BCD..... (A packed BCD has thou's, hund's, tens and units packed as nibbles in a two byte number...

So the number 154 ends up 0x01 and 0x54, Then sending the correct nibble and adding 0x30 we have an ascii character to display.
 
Last edited:
Hi,

Since i cannot understand what is happening in the routine, i decided to try and make one myself.
The coding i did is the one below, but for some reason its not working :(

Can someone help me in trouble-shooting?

Thanks

Code:
CLRF tens                   ;clear registers
CLRF ones

CONVERT_TENS    ;convert the hundreds into ascii value routine

MOVF ADRESH                 ;move the a2d result to the working register
SUBLW .10                      ;subtract by 10
BTFSS STATUS,C              ;is the result still a positive number
GOTO CONVERT_ONES    ;if its a negative, go to convert the ones
MOVWF ADRESH           ;if still positive, move the new subtracted result to the ADRESH register
INCF tens                        ;and increment the tens register by 1 
BRA CONVERT_TENS       ;keep looping until the result is a negative value


CONVERT_ONES

MOVF ADRESH
SUBLW .1
BTFSS STATUS,C
GOTO READY
MOVWF ADRESH
INCF ones
BRA CONVERT_ONES


READY

MOVF tens                   ;add 48 to huns and ones to convert them to ASCII
ADDLW .48
MOVWF tens

MOVF ones
ADDLW .48
MOVWF ones
 
Last edited:
OK... firstly SUBLW .10 doesn't work like that.... "Subtract W from Literal" secondly.. BTFSS... You want to skip when clear ( BTFSC )... The carry flag is SET if an overflow occurs..
Thirdly.. I don't think you can write to the ADRESH register.

So
Code:
   CLRF ONES          ; ready registers
   CLRF TENS
   MOVF  ADRESH,W   ; Get adc result
   MOVWF TMP          ; store
CONVERT_TENS
   MOVF TMP,W         ; retrieve here
   SUBLW .10            ; is it bigger than 10
   BC CONVERT_ONES  ; No.
   MOVLW .10           ; Yes load w with 10
   SUBWF TMP          ;  Subtract 10 from temp
   INCF TENS            ;  increase tens
   BRA CONVERT_TENS   ; Again

This code is not useful for numbers over 99
 
Hi,

I have a value in REG1 which i want to subtract by 5 without changing the value of the same register. Can someone tell me what instruction set to use please?

If i use SUBWF, the value in REG1 is changing.

Thanks
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top