Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me with Max7219 code.

Status
Not open for further replies.

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,524
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
Please help me with MAX7219 code. I want to print floating point values on MAX7219 but it is not printing.


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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// LCD module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
 
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
 
 
#define Data7219 RD0_bit
#define Load7219 RD1_bit
#define Clk7219 RD2_bit
 
const unsigned char Font_B[16] = {0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,
                                  0x7f,0x7b,0x77,0x1f,0x4e,0x3d,0x4f,0x47
};
 
unsigned long value;
unsigned char dpset = 0, dp;
 
void Send7219 (char,char);
void Send7219byte(char);
void MAX7219init();
void Display(float);
 
char myStr[] = "230.14592";
 
double adcVal = 0.0, prevVal = 0.0;
 
void main (void) {
 
        TRISA = 0xFF;
        TRISB = 0x00;
        PORTB = 0x00;
        LATB = 0x00;
        TRISD = 0x00;
        PORTD = 0x00;
        LATD = 0x00;
        ANSELA = 0x01;
        ANSELB = 0x00;
        ANSELC = 0x00;
        ANSELD = 0x00;
        ANSELE = 0x00;
        CM1CON0 = 0x00;
        CM2CON0 = 0x00;
 
        LCD_Init();
        LCD_Cmd(_LCD_CURSOR_OFF);
        LCD_Cmd(_LCD_CLEAR);
        
        MAX7219init();
 
        while(1) {
        
              //adcVal = ADC_Read(0);
              //adcVal = adcVal * 300.0 / 1023.0;
              
              //if(prevVal != adcVal) {
              
                      Display(230.45698);
                      
                      prevVal = adcVal;
              //}
        }
}
 
void MAX7219init()
{
        Data7219 =0;
        Load7219 =0;
        Clk7219 = 0;
        Send7219(0x09,0x00);//Decode Mode
        Send7219(0x0A,0x05);//Brightness
        Send7219(0x0B,0x07);//Scan limit
        Send7219(0x0C,0x01);
        Send7219(0x0F,0x00);
}
 
void Send7219(char Digit,char Data)
{
        Send7219byte(Digit);
        Send7219byte(Data);
        Data7219=0;
        Load7219=1;
        Delay_us(20);
        Load7219=0;
}
 
void Send7219byte(char byte) {
 
    unsigned char i;
 
    for(i=0; i<8; i++)
    {
        if(byte & 0x80)
                Data7219=1;
        else
                Data7219=0;
 
        Clk7219=1;
        Delay_us(20);
        Clk7219=0;
        
        byte<<=1;
    }
}
 
void Display(float My_number)
{
        unsigned char dispskip;         // add 1 if "." found within string
        unsigned char i, j, string[23];
 
        FloatToStr(My_number, string);     //Convert float value to string
        Ltrim(string);                     //remove spaces padded to left of string
 
        
        i = 0;                             //check if there is a decimal point
        while(string[i]) {
             if(string[i] == '.') {dp = 1; break; }
             else dp = 0;
             
             i++;
        }
        
        i = 0;                             //if there is decimal point truncate the string after 2 places after decimal point
        if(dp) {
        
            while(string[i] != '.')i++;
            i++;
            i++;
            i++;
            string[i] = '\0';
        }
        
        LCD_Out(1,1,string);
        
        dispskip = strlen(string) - 1;
 
        if((dispskip >= 8) && (dp))dispskip = 8;
        if(dispskip >= 8)dispskip = 7;
 
        
        for(i = 0; i <= dispskip; i++) {
 
                if((string[dispskip-i] <= 0x39) && (string[dispskip - i] != '.') && (dpSet == 0)) {
                      Send7219(i+1, (Font_B[string[dispskip-i] - 0x30]));//0-9
                      j++;
                }
                if(string[dispskip-i] == '.'){//0x20 is ASCII " "
                       dpSet = 1;
                       i++;
                }
                if(dpSet) {
                      Send7219(i+1, (Font_B[string[dispskip-i + 8] - 0x30]));//0-9
                      j++;
                      dpSet = 0;
                }
                
 
        }
        
        for(i = j + 1; i <= 8; i++) {
              Send7219(i, 0);
        }
        
}

 

but it is not printing
You mean that the LCD is not displaying any characters at all?
And is it a 16 by 2 LCD?
 

Write thousand lines of code and then decided that it is doesn't working. I'm not surprised. Be sure, that you able to print byte variable first.
 

No, the MAX7219 is not related to LCD. I am using LCD just to see adc value on LCD. I am sending the same float value (adc value) to MAX7219 Display function but the decimal points seems to flicker. Here is my new 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
8 X 7-Segment Drived C Code
Author Jayanth Devarayanadurga
Data    01/01/2015
*/
 
// LCD module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
 
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
 
 
#define Data7219 RD0_bit
#define Load7219 RD1_bit
#define Clk7219 RD2_bit
 
const unsigned char Font_B[16] = {0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,
                                  0x7f,0x7b,0x77,0x1f,0x4e,0x3d,0x4f,0x47
};
 
unsigned long value;
unsigned char dpset = 0, dp;
 
void Send7219 (char,char);
void Send7219byte(char);
void MAX7219init();
void Display(float);
 
char myStr[] = "230.14592";
 
double adcVal = 0.0, prevVal = 0.0;
 
void main (void) {
 
        TRISA = 0xFF;
        TRISB = 0x00;
        PORTB = 0x00;
        LATB = 0x00;
        TRISD = 0x00;
        PORTD = 0x00;
        LATD = 0x00;
        ANSELA = 0x01;
        ANSELB = 0x00;
        ANSELC = 0x00;
        ANSELD = 0x00;
        ANSELE = 0x00;
        CM1CON0 = 0x00;
        CM2CON0 = 0x00;
 
        LCD_Init();
        LCD_Cmd(_LCD_CURSOR_OFF);
        LCD_Cmd(_LCD_CLEAR);
        
        MAX7219init();
 
        while(1) {
        
              adcVal = ADC_Read(0);
              adcVal = adcVal * 300.0 / 1023.0;
              adcVal *= 1.002338790511193;
              
              if(prevVal != adcVal) {
              
                      Display(adcVal);
                      
                      prevVal = adcVal;
              }
        }
}
 
void MAX7219init()
{
        Data7219 =0;
        Load7219 =0;
        Clk7219 = 0;
        Send7219(0x09,0x00);//Decode Mode
        Send7219(0x0A,0x05);//Brightness
        Send7219(0x0B,0x07);//Scan limit
        Send7219(0x0C,0x01);
        Send7219(0x0F,0x00);
}
 
void Send7219(char Digit,char Data)
{
        Send7219byte(Digit);
        Send7219byte(Data);
        Data7219=0;
        Load7219=1;
        Delay_us(20);
        Load7219=0;
}
 
void Send7219byte(char byte) {
 
    unsigned char i;
 
    for(i=0; i<8; i++)
    {
        if(byte & 0x80)
                Data7219=1;
        else
                Data7219=0;
 
        Clk7219=1;
        Delay_us(20);
        Clk7219=0;
        
        byte<<=1;
    }
}
 
void Display(float My_number)
{
        unsigned char dispskip;         // add 1 if "." found within string
        unsigned char i, j, k, string[23];
 
        FloatToStr(My_number, string);     //Convert float value to string
        Ltrim(string);                     //remove spaces padded to left of string
 
        
        i = 0;                             //check if there is a decimal point
        while(string[i]) {
             if(string[i] == '.') {dp = 1; break; }
             else dp = 0;
             
             i++;
        }
        
        i = 0;                             //if there is decimal point truncate the string after 2 places after decimal point
        if(dp) {
        
            while(string[i] != '.')i++;
            i++;
            i++;
            i++;
            string[i] = '\0';
        }
        
        LCD_Out(1,1,string);
        
        dispskip = strlen(string) - 1;
 
        if((dispskip >= 8) && (dp))dispskip = 8;
        if(dispskip >= 8)dispskip = 7;
 
                  //0 1 2 3 4 5 6 7 8
                  //2 3 0 . 4 5
        
        for(i = 0; i <= dispskip; i++) {
 
                k = i;
                
                if((string[dispskip-i] <= 0x39) && (string[dispskip - i] != '.') && (dpSet == 0)) {
                      Send7219(i+1, (Font_B[string[dispskip-i] - 0x30]));//0-9
                }
                
                if(string[dispskip-i] == '.'){//0x20 is ASCII " "
                       i++;
                       Send7219(i, (Font_B[string[dispskip-i] - 0x30]) | 0b10000000);//0-9
                       dpSet = 1;
                }
                
                if((string[dispskip-i] <= 0x39) && (dpSet)) {
                      Send7219(i, (Font_B[string[dispskip-i] - 0x30]));//0-9
                }
        }
        
        for(i = i ; i <= 8; i++) {
              Send7219(i, 0);
        }
        
}

 

I am sending the same float value (adc value) to MAX7219 Display function but the decimal points seems to flicker

Do you mean the dot point is flicking alternating at wrong positions or is it just blinking at the same position ?
 

Do it occurs at numbers near to an integer value, such as all digits after dot point being zero ?
 

I don't know that. The strange thing is that the value after the decimal point never changes even though they change on LCD. I am printing ADC value on LCD and 7 Segment.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top