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.

[SOLVED] MAX7219 as a Digit Blinker

Status
Not open for further replies.

imranahmed

Advanced Member level 3
Advanced Member level 3
Joined
Dec 4, 2011
Messages
822
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Karachi,Pakistan
Visit site
Activity points
6,533
Please let me know that I am making MAX7219 using Arduino UNO based ammeter.

and want to blink second digit for 500ms delay but how to configure MAX7219.

Using MAX7219 Arduino Library LedControlMS.
 

Clear the second digit then a 100 ms delay and then write to second digit and repeat.
 

What are you trying to display ? int or float ? Are you doing a matrix scrolling display ? How many displays do you have ?
 

I am using 3 digits 7-segment display and displaying integer value 0-200.

but I want to switch on and off any digit I want.
 

Did you use my C Code for MAX7219 ? If yes, all you have to do to turn OFF a digit is write 0 to it. Just display say 240 and then write 0 to digit 2 and a 500 ms delay and then write the whole display.
 

Now I am using Arduino Library , and still not using your code I will use your code in another project for float values,

your code would work but I need for this LedControl Library to switch on and off each digit.
 

mikroC PRO PIC code + Proteus Simulation attached. You can easily use my C code and make a Library for Arduino. You have to pass values 1 to 8 for Blink_Digit() function and the corresponding digit will blink at 500 ms rate.


Zip and attach your Arduino MAX7219 library and sketch.
 

Attachments

  • MAX7219 Integer.rar
    85.3 KB · Views: 119
Last edited:
Thank you I am using it.

Dear your code consist of assembly language but I do not program using

assembly.

I found CPP file.
 
Last edited:

Where is asm language ? My code is C 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
/*
8 X 7-Segment MAX7219 Driver C Code
Author Jayanth Devarayanadurga
Data    02/03/2015
*/
 
sbit Data7219 at LATD0_bit;
sbit Load7219 at LATD1_bit ;
sbit Clk7219 at LATD2_bit;
 
sbit Data7219_Direction at LATD0_bit;
sbit Load7219_Direction at LATD1_bit;
sbit Clk7219_Direction at LATD2_bit;
 
const unsigned char Font_B[16] = {0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,
                                  0x7f,0x7b,0x77,0x1f,0x4e,0x3d,0x4f,0x47
};
 
void Send7219 (char,char);
void Send7219byte(char);
void MAX7219init();
void Display(float);
 
unsigned int value = 0;
 
void MAX7219init() {
 
    Data7219_Direction = 0;
    Load7219_Direction = 0;
    Clk7219_Direction = 0;
    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(unsigned int val) {
 
        unsigned char dispskip;         // add 1 if "." found within string
        unsigned char i, str[17];
 
        IntToStr(val, str);     //Convert float value to string
        Ltrim(str);                     //remove spaces padded to left of string
        
        dispskip = strlen(str) - 1;
        if(dispskip >= 8)dispskip = 7;
 
        i = 0;
        while(i <= dispskip) {
 
                if((str[dispskip-i] >= 0x30) && (str[dispskip - i] <= 0x39)) {
                      Send7219(i+1, (Font_B[str[dispskip-i] - 0x30])); //0-9
                }
                
                i++;
        }
        
        i++;
        while(i <= 8) {
              Send7219(i, 0);
              i++;
        }
}
 
void Blink_Digit(unsigned char digit) {
     Delay_ms(500);
     Send7219(digit, 0);
     Delay_ms(500);
}
 
void main() {
 
        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;
 
        MAX7219init();
 
        while(1) {
        
              unsigned char i;
              
              value = 1023;
 
              Display(value);
              Blink_Digit(2);
        }
}

 

Please find attachment.

and sketch below.

Code:
//We always have to include the library
#include "LedControlMS.h"
#include "math.h"


/*
 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 12 is connected to the DataIn 
 pin 11 is connected to the CLK 
 pin 10 is connected to LOAD 
 We have only a single MAX72XX.
 */
LedControl lc=LedControl(12,11,10,1); 


unsigned int temp_var=0, ones=0 , tens=0 , hundreds=0;

void setup() {
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,15);
  /* and clear the display */
  lc.clearDisplay(0);
 
}


void loop()
{ 
   
    temp_var = 123;
    
    ones     = (temp_var%10 );
    tens     = (temp_var/10 )%10;
    hundreds = (temp_var/100)%10; 
      
    lc.setDigit(0,2,(byte)ones,false);
    lc.setDigit(0,1,(byte)tens,false);
    lc.setDigit(0,0,(byte)hundreds,false);
}
 

Attachments

  • LedControlMS.rar
    9.4 KB · Views: 84

Working Arduino Sketch + Proteus Simulation attached. Use .hex from attached file for Proteus Simulation. Use Sketch for testing in hardware.

If Arduino has to do any other thing other than displaying on 7 Segment then timer interrupt has to be used for 7 Segment displaying and blinking.
 

Attachments

  • Arduino MAX7219.rar
    248.3 KB · Views: 103
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top