Split from: OPERAND 1 OUT OF RANGE: 0x7A

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
CONVERSION:

LDI R17, 0x00

MOV R0, R17

MOV R1, R17

CPI R16, 0x0A

BRBS H1

H0:

SUBI R16, 0x0A

INC R1

CPI R16, 0x0A

BRSH H0

LDI R17, 0x30

OR R1, R17

H1:

MOV R0, R16

LDI R17, 0x30

OR R0, R17

RET

MSGDISP:

LDI R31, HIGH(MSG<<1)

LDI R30, LOW(MSG<<1)

LOOP:

LPM R16, Z+

CPI R16, 0

BREQ HERE1

CALL DATAWRT

RJMP LOOP

HERE1:

RET

;***************************************************************************

CMNDWRT:

  MOV  R27, R16

  ANDI R27, 0xF0

  IN  R26, LCD_PRT

  ANDI R26, 0x0F

  OR  R26, R27

  OUT  LCD_PRT, R26

  CBI  LCD_PRT, LCD_RS

  CBI  LCD_PRT, LCD_RW

  SBI  LCD_PRT, LCD_EN

  CALL SDELAY

  CBI  LCD_PRT, LCD_EN

  CALL DELAY_100us 

  MOV  R27, R16

  SWAP R27

  ANDI R27, 0xF0

  IN  R26, LCD_PRT

  ANDI R26, 0x0F

  OR  R26, R27

  OUT  LCD_PRT, R26

  SBI  LCD_PRT, LCD_EN

  CALL SDELAY

  CBI  LCD_PRT, LCD_EN

  CALL DELAY_100us

  RET

DATAWRT:

  MOV  R27, R16

  ANDI R27, 0xF0

  IN  R26, LCD_PRT

  ANDI R26, 0x0F

  OR  R26, R27

  OUT  LCD_PRT, R26

  SBI  LCD_PRT, LCD_RS //RS=1 for data write else it is 0

  CBI  LCD_PRT, LCD_RW

  SBI  LCD_PRT, LCD_EN

  CALL SDELAY

  CBI  LCD_PRT, LCD_EN

  MOV  R27, R16

  SWAP R27

  ANDI R27, 0xF0

  IN  R26, LCD_PRT

  ANDI R26, 0x0F

  OR  R26, R27

  OUT  LCD_PRT, R26

  SBI  LCD_PRT, LCD_EN

  CALL SDELAY

  CBI  LCD_PRT, LCD_EN

  CALL DELAY_100us

  RET

 

 

 

Somebody can explain me this code?? What function realize?

 

Formatted code - Moderator

 

 

Last Edited: Wed. Oct 11, 2017 - 11:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

torresuao wrote:
Somebody can explain me this code?? What function realize?

1)  Use the <> (code tags) to post formatted source code.

2)  Use indentation to make it easier to read.

3)  Tell more about your mission.  Why should we decipher this block of uncommented source code?  Where did you get it?  Why do you need to explore it?

4)  For any complete answer, a complete program is needed. 

5)  What have you done so far?  Which line in particular might have you "stuck"?  Have you used the AVR Instruction Set document to help?

http://www.atmel.com/images/Atme...

6)  It puts a message to a character LCD display.

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

torresuao wrote:
Somebody can explain me this code?? What function realize?

1)  Use the <> (code tags) to post formatted source code.

2)  Use indentation to make it easier to read.

3)  Tell more about your mission.  Why should we decipher this block of uncommented source code?  Where did you get it?  Why do you need to explore it?

4)  For any complete answer, a complete program is needed. 

5)  What have you done so far?  Which line in particular might have you "stuck"?  Have you used the AVR Instruction Set document to help?

http://www.atmel.com/images/Atme...

6)  It puts a message to a character LCD display.

 

 

I need to show in LCD display the values that contain the register ADCH and ADCL, but I don't know how to convert this values from binary to ASCII to show in LCD. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

torresuao wrote:
Somebody can explain me this code?? What function realize?

1)  Use the <> (code tags) to post formatted source code.

2)  Use indentation to make it easier to read.

3)  Tell more about your mission.  Why should we decipher this block of uncommented source code?  Where did you get it?  Why do you need to explore it?

4)  For any complete answer, a complete program is needed. 

5)  What have you done so far?  Which line in particular might have you "stuck"?  Have you used the AVR Instruction Set document to help?

http://www.atmel.com/images/Atme...

6)  It puts a message to a character LCD display.

 

<

CONVERSION:

LDI R17, 0x00

MOV R0, R17

MOV R1, R17

CPI R16, 0x0A

BRBS H1

H0:

SUBI R16, 0x0A

INC R1

CPI R16, 0x0A

BRSH H0

LDI R17, 0x30

OR R1, R17

H1:

MOV R0, R16

LDI R17, 0x30

OR R0, R17

RET

 

MSGDISP:

 

LDI R31, HIGH(MSG<<1)

LDI R30, LOW(MSG<<1)

LOOP:

LPM R16, Z+

CPI R16, 0

BREQ HERE1

CALL DATAWRT

RJMP LOOP

HERE1:

RET

;***************************************************************************

CMNDWRT:

  MOV  R27, R16

  ANDI R27, 0xF0

  IN  R26, LCD_PRT

  ANDI R26, 0x0F

  OR  R26, R27

  OUT  LCD_PRT, R26

  CBI  LCD_PRT, LCD_RS

  CBI  LCD_PRT, LCD_RW

  SBI  LCD_PRT, LCD_EN

  CALL SDELAY

  CBI  LCD_PRT, LCD_EN

 

  CALL DELAY_100us 

 

  MOV  R27, R16

  SWAP R27

  ANDI R27, 0xF0

  IN  R26, LCD_PRT

  ANDI R26, 0x0F

  OR  R26, R27

  OUT  LCD_PRT, R26

  SBI  LCD_PRT, LCD_EN

  CALL SDELAY

  CBI  LCD_PRT, LCD_EN

 

  CALL DELAY_100us

  RET

 

DATAWRT:

  MOV  R27, R16

  ANDI R27, 0xF0

  IN  R26, LCD_PRT

  ANDI R26, 0x0F

  OR  R26, R27

  OUT  LCD_PRT, R26

  SBI  LCD_PRT, LCD_RS //RS=1 for data write else it is 0

  CBI  LCD_PRT, LCD_RW

  SBI  LCD_PRT, LCD_EN

  CALL SDELAY

  CBI  LCD_PRT, LCD_EN

 

 

  MOV  R27, R16

  SWAP R27

  ANDI R27, 0xF0

  IN  R26, LCD_PRT

  ANDI R26, 0x0F

  OR  R26, R27

  OUT  LCD_PRT, R26

  SBI  LCD_PRT, LCD_EN

  CALL SDELAY

  CBI  LCD_PRT, LCD_EN

 

  CALL DELAY_100us

  RET

>  I need the comments of this code because I am amateur programming in ASM. I don't understand. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

torresuao wrote:
convert this values from binary to ASCII

See:

http://www.avrfreaks.net/comment/264489#comment-264489

 

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
1)  Use the <> (code tags) to post formatted source code.

See http://www.avrfreaks.net/comment... full, illustrated examples of what this means & how to do it

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note the OP here was originally a hijack of this thread: http://www.avrfreaks.net/forum/o...

 

This comment applies:

 

In the original thread, Kartman wrote:

torresuao wrote:
>  I need the comments of this code because I am amateur programming in ASM. I don't understand. 

It would be a good learning exercise for you to work through the code and add your comments. I learn of lot of my asm skills from reverse engineering code. Also, note that just about anything you need to ask has been asked before and example code provided. The AVR has been around nearly 20 years, so there’s very few new questions. Use keywords like avr asm bin to dec etc when googling.

 

http://www.avrfreaks.net/comment...

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To the general question of showing on LCD. You need to keep dividing by 10 and storing the remainders. Then use them is reverse order, adding 0x30 to each one.
.
So if ADC is 735. Divide 10. Store remainder 5. Divide 73 that is left by 10. Store remainder 3. Divide by 10 again. Store remainder 7. You have reached 0 so stop converting. Now use the 7 then the 3 then the 5 that you stored (stack can be a good place for this). To each add 0x30 so 0x37, 0x33, 0x35. The LCD will show "735".
.
The key to all this is a divide 16 bit value by 8 bit value routine to do the /10 operations. Atmel have an application note with such routines.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PS in hex 10 is 0x0A. Wonder if that fact and the original code in #1 are in any way related?