Assembly Instructions?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Assembly Instructions?

跳至解决方案
2,295 次查看
CIA_MAN275
Contributor III

Hey Guys!

 

I need help!

 

I want an assembly instruction for those c-commands:

 DDRH |= 0x80;

 and

PORTH ^=0x80;

Aim is to switch the light off an on! I am a rookie yes :smileyvery-happy:

THX!!

标签 (1)
0 项奖励
回复
1 解答
1,734 次查看
kef
Specialist I

A = A -+ 0x80 will toggle bit7 of A. Will it make LED connected to PORTH on or off I don't know, it depends on initial state of PORTH, also on the circuit.

在原帖中查看解决方案

0 项奖励
回复
8 回复数
1,734 次查看
HSW
NXP Employee
NXP Employee

There is a S12 opcode for setting a bit in memory:

 

   BSET DDRH #$80

 

To toggle bit 7 you could implement the following sequence:

 

    LDAA    #$80

    ADDA    PORTH

    STAA     PORTH

0 项奖励
回复
1,734 次查看
CIA_MAN275
Contributor III

Can you also explain me the following code:

 

  ADDA    PORTH

 

why do you this?

 

 

0 项奖励
回复
1,734 次查看
Lundin
Senior Contributor IV

Fundamental Boolean algebra: A + B equals A UNION B equals A OR B

 

 

0 项奖励
回复
1,734 次查看
kef
Specialist I

Why? To be smarter than average, probably :-). ADD isn't faster than EOR, so this trick is as useless as this one

 

   LDAA PORTH   ;// PORTH ^= 0x80

   SUBA  #$80

   STAA  PORTH

 

Your successor will like it..., or maybe not

0 项奖励
回复
1,734 次查看
CIA_MAN275
Contributor III

When you make -> A= A- $80 than you become the led light off or?

 

I mean this explanation also above!

 

THX!!!

0 项奖励
回复
1,735 次查看
kef
Specialist I

A = A -+ 0x80 will toggle bit7 of A. Will it make LED connected to PORTH on or off I don't know, it depends on initial state of PORTH, also on the circuit.

0 项奖励
回复
1,734 次查看
CIA_MAN275
Contributor III

Okay THX!!!!

 

Here is the whole code:

 

include <stdio.h>

#include <mc912d128.h>


void delay1ms(void) {
  asm("ldy #2666"); //2666 in Y-Register laden
  asm("dbne y,.");  // Decrement, bis Y=0 ist /
            //3cyc x 125ns x 2666 = 0,99975ms
}


void wait(int duration)
{
  while(duration--)
  delay1ms();
}

void main(void) {

 asm("LDAA #$80");               //DDRH |= 0x80;
 asm("STAA $002B");


while(1){
  asm("LDAA #$80");           //PORTH ^=0x80;
  asm("ADDA $0029");
  asm("STAA $0029");
  wait(1000);
 
  }

}

 

Program is ICC12!

 

THX to all of you for helping hands! :smileywink:

0 项奖励
回复
1,734 次查看
CIA_MAN275
Contributor III

I have no S12... so the code don't work! :smileysad:

0 项奖励
回复