AnsweredAssumed Answered

Codewarrior 6.0 for Microcontrollers & 9S08AW60

Question asked by Dave Miller on Feb 20, 2008
Latest reply on Feb 22, 2008 by CompilerGuru
Hello All,
 
For those that have seen my previous posts you know I have been working with a third party GUI library for graphic LCDs.  Part of the idea behind these GUI libs is compatibility with any compiler so there is not any processor specific calls made in the lib itself.  I have to provide all the low level (the actual writes\reads from the MCU to the LCD controller) which is no problem since the LCD Controller is setup for SPI.
 
Anyways I keep sending random 0x00 command or data bytes to the LCD controller out the SPI port and I couldn't figure out why.  Well I think I hve narrowed down the problem but I am not sure if it's a bug in the compiler or with the GUI libs.
 
Here is a snippet of the code along with the ASM info from the listing file:
Code:
// This is important since it redifines the function sgwrby()#define  sgwrby(a,d) simwrby((a),(d))#define  sgrdby(a)   simrdby((a))// Here is my function that inits the LCD by using the ghw_cmd() function109:  void Display_init(void)   //UC1601  AVC1  110:  {                                       Function: Display_initSource  : C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\CODE\UA_Disp_A.cOptions : -Cs08 -D__NO_FLOAT__ -Env"GENPATH=C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\bin;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\prm;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\Sources;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\src;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\lib;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\src;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\cmd;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\CODE;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\DOC;C:\Projects\Universal Actuator\Software\UA_Disp_A;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\asm_include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\HC08c\include" -Env"LIBPATH=C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\asm_include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\HC08c\include" -Env"OBJPATH=C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\bin" -Env"TEXTPATH=C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\bin" -Lasm=%n.lst -Ll=logfile.txt -Ms -ObjN="C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\UA_Disp_A_Data\Standard\ObjectCode\UA_Disp_A.c.o" -OiLib -WmsgSd1106  111:      ghw_cmd(0xe2);          //SET RESET  0000 aee2     [2]             LDX   #-30   // this is loading 0xe2 into the X register  0002 ad45     [5]             BSR   L49 ;abs = 0049// This is the actual function// SGUCHAR = unsigned char 8-bits of course 247:  void ghw_cmd( SGUCHAR cmd )  248:     {Function: ghw_cmdSource  : C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\CODE\ghwinit.cOptions : -Cs08 -D__NO_FLOAT__ -Env"GENPATH=C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\bin;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\prm;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\Sources;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\src;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\lib;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\src;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\cmd;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\CODE;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\DOC;C:\Projects\Universal Actuator\Software\UA_Disp_A;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\asm_include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\HC08c\include" -Env"LIBPATH=C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\asm_include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\HC08c\include" -Env"OBJPATH=C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\bin" -Env"TEXTPATH=C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\bin" -Lasm=%n.lst -Ll=logfile.txt -Ms -ObjN="C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\UA_Disp_A_Data\Standard\ObjectCode\ghwinit.c.o" -OiLib  249:     #ifdef GHW_PCSIM  250:     ghw_cmd_KS07XXsim( cmd );  251:     #endif  252:    253:     #ifndef GHW_NOHDW  254:     ghw_wait();  255:     sgwrby(GHWCMD, cmd);  0000 5f       [1]             CLRX  // remember we loaded the variable we were passing                                      // now we just cleared X register so we lost the data                                       // we are trying to send  0001 cc0000   [4]             JMP   simwrby  // this is calling the redefined sgwrby()  256:     #endif  257:     }// here is the simwrby()    56:  void simwrby(SGUCHAR adr, SGUCHAR dat)   57:     {Function: simwrbySource  : C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\CODE\bussim.cOptions : -Cs08 -D__NO_FLOAT__ -Env"GENPATH=C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\bin;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\prm;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\Sources;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\src;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\lib;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\src;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\cmd;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\CODE;C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\DOC;C:\Projects\Universal Actuator\Software\UA_Disp_A;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\asm_include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\HC08c\include" -Env"LIBPATH=C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\hc08c\device\asm_include;C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.0\lib\HC08c\include" -Env"OBJPATH=C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\bin" -Env"TEXTPATH=C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\bin" -Lasm=%n.lst -Ll=logfile.txt -Ms -ObjN="C:\Projects\Universal Actuator\Software\UA_Disp_A\UA_Disp_A\UA_Disp_A_Data\Standard\ObjectCode\bussim.c.o" -OiLib -WmsgSd1106  0000 89       [2]             PSHX     58:     register SGUCHAR tmp,msk;   59:     /* 1. Read state of unused bits and initiate used bits for chipselect */   60:    // tmp = (sgrdby(_PTFD) & (~(A0|SCLK|SDA|CS))) | ((adr & 0x1) — A0 : 0);   61:     62:     /* 2. Set chip select (and clock) low, update address bit */   63:    // sgwrby(_PTFD, tmp);   64:     65:     /* 3. Loop while clocking data out, msb first */   66:  //   msk=0x80;   67:  //   do   68:  //      {   69:  //      if (((dat & msk) != 0))   70:  //         {   71:           //sgwrby(_PTFD,tmp|SDA);           /* 4.a Set data high  (other bits is unchanged) */   72:           //sgwrby(_PTFD,tmp|SDA|SCLK);      /* 5.a Set clock high (other bits is unchanged) */   73:           //sgwrby(_PTFD,tmp|SDA);           /* 6.a Set clock low  (other bits is unchanged) */   74:  //         }   75:  //      else   76:  //         {   77:           //sgwrby(_PTFD,tmp);               /* 4.b Set data low   (other bits is unchanged)*/   78:          // sgwrby(_PTFD,tmp|SCLK);          /* 5.b Set clock high (other bits is unchanged)*/   79:          // sgwrby(_PTFD,tmp);               /* 6.b Set clock low  (other bits is unchanged)*/   80:  //         }   81:  //      msk >>= 1;   82:  //      }   83:  //   while(msk != 0);   84:     85:     /* 7. Set chip select high (SCLK must remain low here) */   86:     //sgwrby(_PTFD,tmp|CS);   87:     88:          if(!adr)  0001 95       [2]             TSX     0002 7d       [3]             TST   ,X  0003 2602     [3]             BNE   L7 ;abs = 0007   89:              LCD_CD_ClrVal();  0005 1d00     [5]             BCLR  6,_PTFD  0007          L7:        90:          LCD_SPI_SendChar(dat);  0007 cd0000   [6]             JSR   LCD_SPI_SendChar  000a          LA:        91:          while(LCD_SPI_GetCharsInTxBuf());  000a cd0000   [6]             JSR   LCD_SPI_GetCharsInTxBuf  000d 650000   [3]             CPHX  #0  0010 26f8     [3]             BNE   LA ;abs = 000a   92:          LCD_CD_SetVal();  0012 1c00     [5]             BSET  6,_PTFD   93:     }  0014 8a       [3]             PULH    0015 81       [6]             RTS   // I think I see the issue// the first var passed is stored in the X register// so when we make the second function call the adr var is equal to 0x00 so it clrs the X register// but that is actually erasing the original data we are passing.

 
As you can see if it wasn't for the ASM stepping function I would still be spinning my wheels trying to figure out why I am transmiting 0x00 all the time.  Now I think I know why but I am unsure of how to best fix it.
 
Any ideas?

Outcomes