AnsweredAssumed Answered

Assembler delay subroutine in c program

Question asked by chop on Dec 5, 2010
Latest reply on Dec 6, 2010 by bigmac

I'm using the s08SH32 , I have  a program  I wrote to display temperature from a DS1820 one wire thermo on a 20x2 character display.  It  works well using a standard asm subroutine for the short delays needed in my "one_wire.c) section  :- 

void delay_2us(unsigned int n)
{
 
  asm {
       LDHX (n)
LOOP1: AIX  #-1    ;[2]
//       NOP         ;[1]
       CPHX #0     ;[3]
       BNE  LOOP1  ;[3]
  }
}

 

However I've tried to modify the program to write to a graphics display ( Nokia 5110 and that's working well ) the delays for the one wire routine go adrift , instead of getting approx  500uS from a "delay_2uS (250) " call I get about 1.6 mS and changing the value of n makes no difference , If I change LDHX (n) to LDHX #2,  LDHX #2 etc I get the expected result , so it appears that the value "n" is not being transferred to the routine .

I'm far more at hime with assembly than "C"  , but I'm trying to get up to speed with "C" so I'd appreciate any ( non obscene ) suggestions , I'm obviously doing something pretty basically wrong , but I'm confused as to why changing a display routine should screw up what was a working one wire routine !!

Outcomes