+ Post New Thread
Results 1 to 10 of 10
  1. #1
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    126 / 126
    Points
    5,417
    Level
    17

    Why this works in Arduino but not in C ?

    Why this works in Arduino (C++) but not in C (mikroC) ?

    Code:
    void writeDisplay(char* msg)
    {
      for (byte i=0; i < NUM_DISPLAYS; i++)
      {
        if (i < strlen(msg))
          writeMAX6955(0x25-i, msg[i]);
        else
          writeMAX6955(0x25-i, ' ');
      }
    }
    The strlen(msg) doesn't return string length in mikroC.

  2. #2
    Super Moderator
    Points: 251,591, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    43,812
    Helped
    13322 / 13322
    Points
    251,591
    Level
    100

    Re: Why this works in Arduino but not in C ?

    Without further information, it's a pretty useless post.

    So far, you have written legal C code which can work in any C enviroment. But we neither know what writeMAX6955() does nor how the msg parameter is actually supplied in your program.

    I feel that the below Forum rules quote describes the information content of your post quite well
    Only you know what "doesn't work" means
    Please tell us what your circuit or code is supposed to do and why it "doesn't work".When you come in and say "it doesn't work" or just "it has errors", that means NOTHING. There could be a million things wrong and no one will know where to look.



    •   AltAdvertisment

        
       

  3. #3
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    126 / 126
    Points
    5,417
    Level
    17

    Re: Why this works in Arduino but not in C ?

    I am referring this. I have tested this in Arduino and it works. In mikroC it doesn't work.

    http://timewitharduino.blogspot.in/2...h-max6955.html



  4. #4
    Super Moderator
    Points: 251,591, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    43,812
    Helped
    13322 / 13322
    Points
    251,591
    Level
    100

    Re: Why this works in Arduino but not in C ?

    Stlll doesn't answer the question. How have the Arduino GPIO commands in writeMAX6955() been translated to mikroC?



    •   AltAdvertisment

        
       

  5. #5
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    126 / 126
    Points
    5,417
    Level
    17

    Re: Why this works in Arduino but not in C ?

    This is the mikroC PRO PIC project. I am using mikroC PRO PIC's I2C1 Library. mikroC PRO PIC project and Proteus file are attached.

    It woks but in reverse. I have to make modifications to it so that data is not reverse.

    This is the code.

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    
    #define MAX6955BaseAddress 0b11000000
     
    #define reg_noOp            0x00
    #define reg_decodeMode      0x01
    #define reg_globalIntensity 0x02
    #define reg_scanLimit       0x03
    #define reg_configuration   0x04
    #define reg_displayTest     0x07
    #define reg_digitType       0x0C
     
    #define reg_intensity10  0x10
    #define reg_intensity32  0x11
    #define reg_intensity54  0x12
    #define reg_intensity76  0x13
    #define reg_intensity10a 0x14
    #define reg_intensity32a 0x15
    #define reg_intensity54a 0x16
    #define reg_intensity76a 0x17
     
    #define USE_GLOBAL   0x00
    #define USE_DISCRETE 0x40
    #define RUN          0x01
    #define SHUTDOWN     0x00
     
    #define reg_digit0  0x60
    #define reg_digit1  0x61
    #define reg_digit2  0x62
    #define reg_digit3  0x63
    #define reg_digit4  0x64
    #define reg_digit5  0x65
    #define reg_digit6  0x66
    #define reg_digit7  0x67
    #define reg_digit0a 0x68
    #define reg_digit1a 0x69
    #define reg_digit2a 0x6A
    #define reg_digit3a 0x6B
    #define reg_digit4a 0x6C
    #define reg_digit5a 0x6D
    #define reg_digit6a 0x6E
    #define reg_digit7a 0x6F
     
    #define NUM_OF_DISPLAYS 8
     
    void Delay_MilliSec(int mSec) {
         while(mSec) {
            Delay_ms(1);
            mSec--;
         }
    }
     
    void MAX6955_Write(unsigned char command, unsigned char data_) {
        I2C1_Start();
        I2C1_Wr(MAX6955BaseAddress);
        I2C1_Wr(command);
        I2C1_Wr(data_);
        I2C1_Stop();
        Delay_ms(5);
    }
     
    void MAX6955_Init() {
        I2C1_Init(100000);
        Delay_ms(200);
        
        MAX6955_Write(reg_decodeMode, 0xFF);
        MAX6955_Write(reg_scanLimit, 0x07);
        MAX6955_Write(reg_configuration, 0x01);
        MAX6955_Write(reg_globalIntensity, 0xFF);
        MAX6955_Write(reg_digitType, 0x00);
    }
     
    void MAX6955_Write_Display(char* msg) {
        char i;
     
        for(i = 0; i < NUM_OF_DISPLAYS; i++) {
            if(i < strlen(msg))
              MAX6955_Write((0x27 - i), msg[i]);
            else
              MAX6955_Write((0x27 - i), ' ');
        }
    }
     
    void MAX6955_Write_Char(char pos, char letter, char dotLit) {
        MAX6955_Write((0x27 - pos), (dotLit? 0x80 : 0) | letter);
    }
     
    void MAX6955_Clear() {
        char i;
        
        for(i = 0; i < NUM_OF_DISPLAYS; i++)
            MAX6955_Write((0x27 - i), ' ');
    }
     
    void MAX6955_Scroll_Display(char* msg, int mSec) {
        int i;
        
        for(i = 0; i <= strlen(msg); i++) {
            MAX6955_Write_Display(msg + i);
            Delay_MilliSec(mSec);
        }
    }
                                  
    void main() {
     
        CMCON = 0x07;
     
        ADCON0 = 0x40;
        ADCON1 = 0b10001110;
        
        TRISA = 0x01;
        TRISB = 0x00;
        TRISC = 0x00;
        TRISD = 0x00;
        TRISE = 0x00;
        
        PORTA = 0x00;
        PORTB = 0x00;
        PORTC = 0x00;
        PORTD = 0x00;
        PORTE = 0x00;
     
        MAX6955_Init();
        Delay_ms(200);
     
        while(1) {
     
              MAX6955_Write_Char(0, 'A', 0);
              Delay_ms(2000);
              MAX6955_Write_Char(0, 'A', 1);
              Delay_ms(2000);
              MAX6955_Clear();
              Delay_ms(2000);
              MAX6955_Write_Display("MAXIM");
              Delay_ms(2000);
              MAX6955_Scroll_Display("Hello", 1000);
              Delay_ms(2000);
        }
    }



  6. #6
    Super Moderator
    Points: 69,659, Level: 64
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    14,229
    Helped
    3251 / 3251
    Points
    69,659
    Level
    64

    Re: Why this works in Arduino but not in C ?

    Hi,

    And it doesn't answer what you expect...and what exactely does not work as expected.

    What debugging have you done so far..and what are the results?

    Klaus



  7. #7
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    126 / 126
    Points
    5,417
    Level
    17

    Re: Why this works in Arduino but not in C ?

    I modified the code and it is working but still doesn't work if string like 234.26 is sent. Decimal point doesn't work.

    And it doesn't answer what you expect...and what exactely does not work as expected.
    In modified code scrolling doesn't work as needed. I need scroll display which scrolls from left to right and another right to left.

    The left most display address is 0x20 and right most display address is 0x27.

    I have 8 digits.

    If I reduce displays to 3 digits then how should I consider the circuit ? Should I use displays with address 0x20, 0x21 and 0x22 or should I use displays with address 0x27, 0x26 and 0x25 ?

    I want to make a universal library which works with any number of displays (0 to 8).

    With my modified code scrolling is not working.

    Florin's code prints in reverse. Maybe Florin's MAX6955 circuit is different from mine.
    Last edited by Okada; 30th October 2016 at 11:18.



    •   AltAdvertisment

        
       

  8. #8
    Super Moderator
    Points: 251,591, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    43,812
    Helped
    13322 / 13322
    Points
    251,591
    Level
    100

    Re: Why this works in Arduino but not in C ?

    It works but in reverse. I have to make modifications to it so that data is not reverse.
    That's a bit different from "not working" claimed in post #1. However you're slowly approaching reasonable problem reports.

    The segment addressing seems to refer to reversed order at first sight.
    Code:
    MAX6955_Write((0x27 - i), msg[i]);
    I'm not sure what's different in the Arduino design, may be different hardware connection?


    1 members found this post helpful.

  9. #9
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    126 / 126
    Points
    5,417
    Level
    17

    Re: Why this works in Arduino but not in C ?

    That's a bit different from "not working" claimed in post #1
    Actually I had done a mistake in porting the Florin's code and only Character displaying was working but string display was not working. I fixed it and it solved the problem and so the original question of this thread is solved but I have other problems.

    I need a code which works for any no of displays (0 to 8). Also I need a function for scrolling from left to right and another for scrolling from right to left.

    How can I implement them ?

    I have not done any debugging.
    Last edited by Okada; 30th October 2016 at 11:37.



  10. #10
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    126 / 126
    Points
    5,417
    Level
    17

    Re: Why this works in Arduino but not in C ?

    I am still trying. Not able to some scrolling method working.

    Strings like ".M.A.X" doesn't work in current scrolling methods. I have to do more thinking and make one function for sending string to MAX6955 which can be used for all kinds of scrolling like

    left to right
    right to left
    left to right mirror
    right to left mirror



--[[ ]]--