cannot find the reason for such a strange behavior


Results 1 to 18 of 18

Threaded View

  1. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: cannot find the reason for such a strange behavior

    The work around was

    DmyFlg = Door_Lock
    DmyFlg = !DmyFlg
    Report[2] = DmyFlg + 48
    I'M not sure you solution is correct

    I did a few experiments as follows and conclude that,

    if you invert a bit var (or bit alias) wether logical or bitwise only bit 0 in the result is valid , I you go on to use the result mathematically then all the other bits need to be masked off

    for a correct calculation



    D_Lck !D_Lck ~D_Lck D_Flg !D_Flg ~D_Flg R+!L R+~L R+!F R+~F
    WRONG
    0 65535 65535 0 65535 65535 47 47 47 47
    CORRECT
    0 255 65535 0 65535 65535 49 49 49 49
    WRONG
    1 65280 65534 1 65280 65534 48 46 48 46
    CORRECT
    1 0 65534 1 65280 65534 48 48 48 48
    WRONG
    0 65535 65535 0 65535 65535 47 47 47 47
    CORRECT
    0 255 65535 0 65535 65535 49 49 49 49





    Code:
       TRISC = %11101111        ' set PORTC I/O
     
    
     D_Lck var Portc.4
     D_Flg var bit
     Report var byte[4]
     
     
        DEFINE DEBUG_REG PORTA
        DEFINE DEBUG_BIT 0      ;  if not used for pwr  
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0     
        pause 2000
        Debug "Start",13 ,10      
     
     Debug 13 ,10 ,"D_Lck",9 ,"!D_Lck",9, "~D_Lck",9, "D_Flg",9, "!D_Flg",9, "~D_Flg" ,9, "R+!L" ,9, "R+~L" ,9, "R+!F" ,9, "R+~F"
    main:
     PORTC.4=!PORTC.4
     D_Flg=D_Lck 
     Debug 13 ,10 ,"WRONG"
     Report[0] = !D_Lck + 48 
     Report[1] = ~D_Lck + 48 
     Report[2] = !D_Flg + 48 
     Report[3] = ~D_Flg + 48 
     Debug 13 ,10 ,#D_Lck,9 , #!D_Lck,9, #~D_Lck ,9, #  D_Flg ,9,  #!D_Flg, 9,# ~ D_Flg ,9,# Report[0] ,9,# Report[1] ,9,# Report[2] ,9,# Report[3]
     Debug 13 ,10 ,"CORRECT"
     Report[0] = (!D_Lck&1) + 48 
     Report[1] = (~D_Lck&1) + 48 
     Report[2] = (!D_Flg&1) + 48 
     Report[3] = (~D_Flg&1) + 48 
     Debug 13 ,10 ,#D_Lck,9 , #!D_Lck,9, #~D_Lck ,9, #  D_Flg ,9,  #!D_Flg, 9,# ~ D_Flg ,9,# Report[0] ,9,# Report[1] ,9,# Report[2] ,9,# Report[3]
      
     
     
     
      pause 1000
     
      goto main
    Last edited by richard; - 5th November 2016 at 02:47.
    Warning I'm not a teacher

Similar Threads

  1. Strange behavior on PORTB on a PIC18F26K20
    By Dosbomber in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th September 2016, 00:31
  2. Strange Behavior 12F1822
    By nobner in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 3rd February 2012, 09:11
  3. Strange LCD Behavior
    By chips123 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st November 2009, 01:48
  4. Strange behavior - PORTG.2, 18F8720
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th January 2009, 00:30
  5. Strange electrical behavior with PIC16F684
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 28th March 2008, 07:58

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts