Symbol Parameter replace the characters in quoted string?

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
calixarene
Posts: 17
Joined: 03 Apr 2012 06:31

Symbol Parameter replace the characters in quoted string?

#1 Post by calixarene » 11 Jun 2015 16:17

I found a problem when using symbol in my code. When I declare a symbol No = 0, the compiler replace the word "No" in a string with "0".

Code:
Symbol No = 0
..
..
..

PrintPCD("No SD is inserted") 'PrintPCD is a function that display the string on a GLCD

...

After compiling my GLCD displays "0 SD is inserted". The symbol No is for other function parameters. Is this problem due to optimization level or a bug?

For the time being, I am using Symbol No_ = 0 as a solution.

User avatar
viktor.milovanovic
Posts: 240
Joined: 08 Jun 2015 10:09

Re: Symbol Parameter replace the characters in quoted string

#2 Post by viktor.milovanovic » 12 Jun 2015 13:51

Hello,

can you post the whole code here?
Regards,

Viktor Milovanovic

calixarene
Posts: 17
Joined: 03 Apr 2012 06:31

Re: Symbol Parameter replace the characters in quoted string

#3 Post by calixarene » 15 Jun 2015 02:46

Since there are several screens and the code is long, I only paste the code that is related. The GLCD is based on PCD8544 (Nokia display)
Here is the code

Code: Select all

module UserInterface

'This module hold all the resources for the GLCD screen and input device
include "GlobalVar"                     'Global variables for project
include "StrngUtils"                     'String utilities module
include "PCD8544Lib"                     'GLCD display module
include "NavSw"
'....
'....
Symbol Yes = 1
Symbol NO = 0
Symbol OK =1
Symbol Cancel =2
,...
Structure ScreenStructure ' This hold the Screen parameters for input and naviagation
 dim TabOrder as byte
 dim ParentScreen as byte
 dim VScroll as short
 dim Mode as byte                           'Determine the mode of screen
end structure
implements
,...

 '**********Show and Hanlde SD Card screen
sub procedure Show_SD_StatusScreen(Dim byref Para as ScreenStructure)
 'SD Card selection
 Dim LongStr as string[10]
 Dim Showstr as string[14]
   ClearScrPCD()
   if SD_Ready then
      PrintPCD("SD is Ready" , A_Left, 0)
      longwordtostr(Fat32_TotalSpace_KB, LongStr)
      ltrim(LongStr)
      strcat2(Showstr,"C=", LongStr)
      strcatx(ShowStr, "KB" , sizeof(showStr))
      PrintPCD(ShowStr, 4 ,8)
      longwordtostr(Fat32_FreeSpace_KB, LongStr)
      ltrim(Longstr)
      strcat2(Showstr, "F=", LongStr )
      strcatx(ShowStr, "KB", sizeof(showStr) )
      PrintPCD(Showstr, 4 ,16)
     Local_SD_Eject = false
   else
       PrintPCD("NO SD insert" , A_Left, 0)     '<----here will show "0 SD insert" in the GLCD
      local_SD_Eject = true
   end if
   if para.TabOrder = SD_Tab_Eject then
      inverttext(Yes)
      PrintPCD(SD_EjectStr, A_LEFT, 24)
     inverttext(NO)  
       ShowButton(SD_EjectStr,A_Center ,24,true)
      else
      PrintPCD(SD_EjectStr, A_LEFT, 24)
      ShowButton(SD_EjectStr,A_Center ,24,False)
   end if
   if para.TabOrder = SD_Tab_InSert then
      inverttext(Yes)
     PrintPCD(SD_InsertStr, A_LEFT, 32)
      inverttext(NO)
       ShowButton(SD_InsertStr,A_Center ,32,true)
      else
      PrintPCD(SD_InsertStr, A_LEFT, 32)
      ShowButton(SD_InsertStr,A_Center ,32,False)
   end if

   if para.TabOrder  = SD_Tab_Exit then
      ShowButton(But_ExitStr,A_CENTER ,LastLinePos,true)
   else
       ShowButton (But_ExitStr,A_CENTER , LastLinePos,false)
   end if
    UpdatePCD()
end sub

sub procedure Handle_SD_Status (Dim EventNum as byte, Dim byref Para as ScreenStructure )
'This procedure handle the user input for the SD_Status_Screen
Dim Error as integer

    Select case EventNum

      case NavSw_Left, NavSw_Up
           if Para.TabOrder = 0   then 'Means   exit
             CurrScreen = OperationScreen
           else
               para.TabOrder = para.TabOrder -1
               if  para.TabOrder < 0 then
                   para.TabOrder  = 0
               end if
           end if
      case NavSw_Right, NavSw_Down
            if  para.TabOrder > SD_Tab_Exit  then
                CurrScreen = SetupScreen
            else
                para.TabOrder = para.TabOrder +1
            end if
      case Button_Enter
           Select case para.TabOrder
              case SD_Tab_Eject
                   SD_Ready = false
                   loggingFlag = false
              case SD_Tab_InSert
                   Error = SD_Bus_Init(SD_BusDivider)
                   if Error <> 0 then
                      ScreenPar[MsgSreen].ParentScreen = SDScreen
                      Currscreen =MsgSreen
                      Show_Msg_Screen("SD card fails to initialized. Please replace another one." ,MsgError)
                      SD_Ready = false
                      LoggingFlag = false
                   end if
              case SD_Tab_Exit
                    CurrScreen = DataScreen
              case else
                   para.TabOrder =1
                   TurnOnBkLite()
           end select
      case else
           exit
       
    end select
   UpdateScreen = True
end sub

'.....
'Here is the code for PrintPCD in the "PCD8544Lib"

sub Procedure PrintChrFast(dim c as char, dim x, y as integer)
 ' This procedure is developed to replace the original _print_char
  dim BuffIdx as integer
  dim Bi, Mask, CopyBit, Cbytes as byte
  dim font_idx, rowcnt, cnt  as integer
  dim cx, cy, LastRow as integer
  dim fontPtr as ^byte

  if ((CurrFont.y_size mod 8) = 0) then
     font_idx = ((c - CurrFont.offset)*(CurrFont.x_size*(CurrFont.y_size div 8)))+4
     Lastrow =  (CurrFont.y_size div 8)-1
  else
      font_idx = ((c - CurrFont.offset)*(CurrFont.x_size*((CurrFont.y_size div 8) +1)))+4
      Lastrow =  (CurrFont.y_size div 8)
  end if
    
  for rowcnt =0 to  LastRow
      for cnt=0 to CurrFont.x_size-1
          fontPtr =  CurrFont.font + font_idx + cnt + (rowcnt*CurrFont.x_size)
          Cbytes = fontptr^
          Cx = x + cnt
          Cy = y + (rowcnt*8)
          if ((cx>=0) and (cx<84) and (cy>=0) and (cy<48)) then
          ' Find the corresponding position in the ScreenBuff of the pixel
            BuffIdx =((cy div 8)*84) + cx
            Bi = cy mod 8  'Find the corresponding Bit in the ScreenBuff byte
            if (CurrFont.inverted = Yes) then
               Cbytes = not Cbytes  'Inverse the bits
            end if
            if Bi = 0 then 'Align exactly to the address
               ScreenBuff[BuffIdx] = Cbytes
            else
                CopyBit = Cbytes << Bi
                'Create a mask that have all one's at lower bit
                Mask = 255 >> (8-Bi)
                'Use the mask to clear the high bits
                ScreenBuff[BuffIdx] = ScreenBuff[BuffIdx] and Mask
                ScreenBuff[BuffIdx] = ScreenBuff[BuffIdx] or CopyBit
                Buffidx =  BuffIdx+84
                if BuffIdx < 503 then  'Buffer size
                   CopyBit = Cbytes >> (8-Bi)
                   'Create a mask that have all one's at lower bit
                   Mask = 255 << Bi
                   'Use the mask to clear the high bits
                   ScreenBuff[BuffIdx] = ScreenBuff[BuffIdx] and Mask
                   ScreenBuff[BuffIdx] = ScreenBuff[BuffIdx] or CopyBit
                end if
            end if
          end if
      next cnt
  next rowcnt
end sub

sub procedure PrintPCD(dim byref st as string, dim x, y as word)
  dim stl, Cnt as integer
  stl = strlen(st)
  if (x = A_RIGHT) then
     x = 84-(stl*CurrFont.x_size)
  end if
  if (x = A_CENTER) then
     x = (84-(stl*CurrFont.x_size))/2
  end if
  for  cnt=0 to stl-1
      ' _print_char(st[Cnt], x + (cnt*(CurrFont.x_size)), y)
       PrintChrFast(st[Cnt], x + (cnt*(CurrFont.x_size)), y)
  next cnt

end sub


sub procedure UpdatePCD()
'Copy the screen buffer to the screen
'Except invert(), this command actually change the physical display while
'other commands only modify the screen buffer without changing the display
  dim BufCnt as word
  WriteToLCD(LCD_SETYADDR, LCD_COMMAND)   ' Set Y address to 0
  WriteToLCD(LCD_SETXADDR, LCD_COMMAND)   'Set X address to 0
  for BufCnt = 0 to  503
      WriteToLCD(ScreenBuff[BufCnt], LCD_DATA)
  next BufCnt
end sub

The "PCD8544Lib" module has a ScreenBuff of byte[504].

I hope the code show some hints on the problem.
Regards

User avatar
viktor.milovanovic
Posts: 240
Joined: 08 Jun 2015 10:09

Re: Symbol Parameter replace the characters in quoted string

#4 Post by viktor.milovanovic » 15 Jun 2015 11:25

Hi,
there's no need to use the symbols. Just print out "No SD is inserted".

Best regards,

Viktor Milovanovic

Post Reply

Return to “mikroBasic PRO for PIC32 General”