Variable Delay by Interrupt in Assembly

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

Hello,

I am using a Tiny11L and I am trying to use a rising edge on INT0 to perform a set value addition to a variable. I would like to use the variable to increase a delay to "loop1" via ldi. I've tried .def a pair of registers and adding them, but that register name cannot be used as a value in my ldi statement. I realize that I am doing something wrong but haven't been able to figure it out.

ldi loop1,variablehere

and in the interrupt i want to do the equivalent of

EXT_INT0:

inc variablehere

reti

or

EXT_INT0:

variablehere = variablehere + x

reti

Any help appreciated, thanks.

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

To transfer a value from one register to another you use MOV not LDI. LDI can only be used for loading a constant (0..255) into a register.

BTW you seem happier with:

a = a + b

ever thought of exploring C? ;-)

(OK, I know, I know!)

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

Thanks for reply. Usually I do use C with a Mega88. I kind of passed up Assembly and have always had this little Tiny11 chip sitting around that doesn't play well with C. So, I am trying to work my way through some Assembly for once, both to get some understanding and to give this little chip a chance in the world.

Also, the project I am working on benefits from using the physically smallest chip I can for the time being. I will probably end up back with C and another chip in the end but I am hoping to at least get to the point where I can get this portion working.

:wink:

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

Quote:

Tiny11 chip sitting around that doesn't play well with C.

Hmmm--my toolchain works cor me. Of course, I program in a "flat" model to start with and a 1k program is even flatter.

Anyway, Tiny25 costs pennies more and is a lot more fun.

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

Declare your variablehere as data, something like this

  .dseg  $60 ;start of RAM
variablehere:  .byte  1

  .cseg ... ;code

EXT_INT0:
;may need to push and pop temp, you decide
  lds temp, variablehere
  subi temp, -somevalue  ;no addi...
..or..
  inc temp
....
  sts  variablehere, temp
  reti

main_code:
  lds  loop1, variablehere

Or if variablehere is a register

  subi variablehere, -somevalue
..or..
  inc variablehere

main_code:
  mov  loop1, variablehere
Last Edited: Tue. Feb 16, 2010 - 06:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK well to get you started why not sketch out the program in C and build for a Tiny that GCC does support for C, then take the Asm that the C compiler generates and use that as a starting point for what you want to do here. If nothing else it'll give you a feel for which opcodes are used for which kinds of tasks (that is the various addressing modes)

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

Thanks for the suggestions! I'll try them out.