MAX7219 KÜTÜPHANESİ

Başlatan alfurkan1064, 07 Haziran 2021, 12:51:53

alfurkan1064

İnternette uzun araştırmalarım sonucunda bulduğum max7219 cascad kullanımında dahil olduğu kütüphane.
Takıldığınız yer olur ise bu konu altından iletişime geçebilirsiniz yardımcı olmaktan memnuniyet duyarım.

https://www.hizliresim.com/gcjw3fp

KULLANIMI:
#define N_MAX   2 // Kaç adet max7219 kullanılacagı En üste eklenecek 

write7219(MAX7219SAYISI,Hangi digite veri yazılacagı,yazılacak deger);

main kısmına eklenecek :
init7219(0xFF);




KÜTÜPHANE:
/*
Autor: Freddy Quispe Tello
Fecha: 02/02/2015

Es una libreria que cree y comparto con ustedes
Espero que la aprovechen! 

*/

#define MAX_DIN  PIN_A2 
#define MAX_CS   PIN_A3
#define MAX_CLK  PIN_A4


void SPI_MAX72xx(unsigned char data);     //      
void command_MAX72xx(unsigned char direc,unsigned char data ); // 
void init7219(unsigned char decode);//
void write7219(unsigned char num,unsigned char direc,unsigned char data );

Void SPI_MAX72xx( unsigned  char data){
   int con;
     for(con=8;con>0;con--){
         output_low(MAX_CLK);
         if(bit_test(data,con-1)==0)
            output_low(MAX_DIN);
            
         else
            output_high(MAX_DIN);
            
         output_high(MAX_CLK);
      }

}
void command_MAX72xx(unsigned char direc,unsigned char data ){
   unsigned char cont;
   output_low(MAX_CS);  
   for(cont=0; cont<N_MAX;cont++){
   SPI_MAX72xx(direc);
   SPI_MAX72xx(data);
   }
   output_high(MAX_CS); 

}
void init7219(unsigned char decode){
   output_low(MAX_DIN);
   output_low(MAX_CLK);
   output_high(MAX_CS);
   command_MAX72xx(0x09,decode);  // Decoder ayarı 
   command_MAX72xx(0x0A,0x0F);  // Parlaklık ayarı
   command_MAX72xx(0x0c,0x00);  // Ekran açıp kapama ayarı
   
   command_MAX72xx(0x0B,0x0E);  // Ekran tarama limiti 0-7 digit
   command_MAX72xx(0x0c,0x01);  // Ekran açıp kapama ayarı ön tanımı 1-sürekli açık
   command_MAX72xx(0x0F,0x00);  // Test modu kapalı

}
void write7219(unsigned char num,unsigned char direc,unsigned char data ){
    unsigned char MAX_DATA[10]={0,0,0,0,0,0,0,0,0,0};  
    unsigned char rep;
    unsigned char cont;
    rep = N_MAX*2;
    MAX_DATA[num*2-1]=direc;
    MAX_DATA[num*2-2]=data;
    output_low(MAX_CS); 
    for(cont=rep; cont>0;cont--){
      SPI_MAX72xx(MAX_DATA[cont-1]);
    }
    output_high(MAX_CS); 
}



ergin

5 adet max7219 dotmatrix e nasıl yazarım

mehmet

Bir tanesi ile çalıştırdınız mı?
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr

ergin

#3
#include <18f2520.h>
#device ADC=10
#fuses INTRC_IO,NOWDT,NOPROTECT,NOMCLR 
#use delay(clock = 8MHz)

#define    DATA      PIN_C2
#define    LOAD      PIN_c1
#define    CLK        PIN_C0

#include <MAX7219.C>



void main()
{
display_init(0);
//unsigned char n[10]={'1','2','3','4','5','6','7','8','9','0'};
unsigned char k[10]={'a','b','c','d','e','f','g','h','i','j',};

        while(true)
        
        {
            for (int i=0;i<10;i++)
            {
            display_char(k[i]);
            delay_ms(500);
            
            }
        
        
        }
        }

[size=1][i][time]14 Nisan 2024, 17:06:02[/time][/i][/size]
///max7219 kütphanesi


#include <string.h>
#include <STDLIBM.H>

#define clk_delay 1
#byte    SSPCON1  =    0xFC6
#bit    SSPEN    =    SSPCON1.5

#define FIRST_CHAR 32
#define LAST_CHAR 125
#define char_spacing 1
unsigned int8 cur_scroll_position=0;
unsigned int16 cur_letter_position=0;
unsigned int16 cur_letter_end_position=0;
unsigned int8 temp_char_spacing=0;
char* scroll_chars;
BYTE cur_char_data[8]={0,0,0,0,0,0,0,0};
unsigned int8 scroll_text_len=0;
BYTE const font_width[]={
    0x07, 0x01, 0x03, 0x05, 0x05, 0x07, 0x07, 0x01, 0x03, 0x03, 
    0x05, 0x07, 0x02, 0x05, 0x02, 0x03, 
    0x05, 0x03, 0x05, 0x05, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 
    0x02, 0x02, 0x07, 0x06, 0x07, 0x05, 0x08, 
    0x07, 0x05, 0x05, 0x05, 0x05, 0x04, 0x06, 0x05, 0x01, 0x04,
    0x06, 0x05, 0x07, 0x05, 0x06, 0x05, 0x06, 0x05, 0x05, 0x05,
    0x05, 0x07, 0x07, 0x07, 0x07, 0x06,
    0x03, 0x03, 0x03, 0x05, 0x06, 0x02, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x03, 0x04, 0x04, 0x01, 0x03, 0x04, 0x01, 0x07, 0x04, 
    0x04, 0x04, 0x04, 0x03, 0x04, 0x03, 0x04, 0x05, 0x07, 0x05, 
    0x05, 0x05, 0x03, 0x01, 0x03,
};

BYTE const font[]={
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 32
    0x7D, // 33
    0x70, 0x00, 0x70, // 34
    0x14, 0x7F, 0x14, 0x7F, 0x14, // 35
    0x24, 0x6B, 0x2A, 0x6B, 0x12, // 36
    0x40, 0x23, 0x13, 0x08, 0x64, 0x62, 0x01, // 37
    0x09, 0x36, 0x49, 0x49, 0x49, 0x49, 0x36, // 38
    0x70, // 39
    0x41, 0x22, 0x1C, // 40
    0x1C, 0x22, 0x41, // 41
    0x11, 0x0A, 0x1F, 0x0A, 0x11, // 42
    0x08, 0x08, 0x08, 0x7F, 0x08, 0x08, 0x08, // 43
    0x40, 0x20, // 44
    0x10, 0x10, 0x10, 0x10, 0x10, // 45
    0x03, 0x03, // 46
    0x60, 0x1C, 0x03, // 47
    0x3E, 0x41, 0x41, 0x41, 0x3E, // 48
    0x7F, 0x20, 0x10, // 49
    0x31, 0x49, 0x45, 0x43, 0x21, // 50
    0x36, 0x49, 0x49, 0x41, 0x22, // 51
    0x04, 0x7F, 0x44, 0x24, 0x14, 0x0C, // 52
    0x4E, 0x51, 0x51, 0x51, 0x72, // 53
    0x26, 0x49, 0x49, 0x49, 0x3E, // 54
    0x60, 0x50, 0x48, 0x44, 0x43, // 55
    0x36, 0x49, 0x49, 0x49, 0x36, // 56
    0x3E, 0x49, 0x49, 0x49, 0x32, // 57
    0x66, 0x66, // 58
    0xA6, 0x66, // 59
    0x08, 0x08, 0x14, 0x14, 0x22, 0x22, 0x41, // 60
    0x24, 0x24, 0x24, 0x24, 0x24, 0x24, // 61
    0x41, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, // 62
    0x0C, 0x02, 0xA2, 0x12, 0x0C, // 63
    0x38, 0x44, 0x82, 0x99, 0x99, 0xA1, 0x22, 0x1C, // 64  
    0x00, 0x1F, 0x28, 0x48, 0x48, 0x28, 0x1F, // 65
    0x36, 0x49, 0x49, 0x49, 0x7F, // 66
    0x22, 0x41, 0x41, 0x41, 0x3E, // 67
    0x1C, 0x22, 0x41, 0x41, 0x7F, // 68
    0x49, 0x49, 0x49, 0x49, 0x7F, // 69
    0x48, 0x48, 0x48, 0x7F, // 70
    0x4E, 0x49, 0x49, 0x41, 0x41, 0x3E, // 71
    0x7F, 0x08, 0x08, 0x08, 0x7F, // 72
    0x7F, // 73
    0x7E, 0x01, 0x01, 0x02, // 74
    0x41, 0x22, 0x14, 0x08, 0x08, 0x7F, // 75
    0x01, 0x01, 0x01, 0x01, 0x7F, // 76
    0x7F, 0x20, 0x10, 0x08, 0x10, 0x20, 0x7F, // 77
    0x7F, 0x08, 0x10, 0x20, 0x7F, // 78
    0x3E, 0x41, 0x41, 0x41, 0x41, 0x3E, // 79
    0x30, 0x48, 0x48, 0x48, 0x7F, // 80
    0x3D, 0x42, 0x45, 0x41, 0x41, 0x3E, // 81
    0x37, 0x48, 0x48, 0x48, 0x7F, // 82
    0x46, 0x49, 0x49, 0x49, 0x31, // 83
    0x40, 0x40, 0x7F, 0x40, 0x40, // 84
    0x7E, 0x01, 0x01, 0x01, 0x7E, // 85
    0x78, 0x04, 0x02, 0x01, 0x02, 0x04, 0x78, // 86
    0x7F, 0x02, 0x04, 0x08, 0x04, 0x02, 0x7F, // 87
    0x41, 0x22, 0x14, 0x08, 0x14, 0x22, 0x41, // 88
    0x40, 0x20, 0x10, 0x0F, 0x10, 0x20, 0x40, // 89
    0x61, 0x51, 0x49, 0x45, 0x43, 0x41, // 90
    0x7F, 0x41, 0x41, // 91
    0x03, 0x1C, 0x60, // 92
    0x41, 0x41, 0x7F, // 93
    0x08, 0x06, 0x01, 0x06, 0x08, // 94
    0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 95
    0x04, 0x03, // 96
    0x0F, 0x15, 0x15, 0x12, // 97
    0x06, 0x09, 0x09, 0x7F, // 98
    0x0A, 0x11, 0x11, 0x0E, // 99
    0x7F, 0x09, 0x09, 0x06, // 100
    0x0D, 0x15, 0x15, 0x0E, // 101
    0x48, 0x3F, 0x08, // 102
    0x3E, 0x49, 0x49, 0x31, // 103
    0x07, 0x08, 0x08, 0x7F, // 104
    0x5F, // 105
    0x5E, 0x01, 0x02, // 106
    0x1B, 0x04, 0x04, 0x7F, // 107
    0x7F, // 108
    0x1F, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x3F, // 109
    0x1F, 0x20, 0x20, 0x3F, // 110
    0x1E, 0x21, 0x21, 0x1E, // 111
    0x30, 0x48, 0x48, 0x7F, // 112
    0x7F, 0x48, 0x48, 0x30, // 113
    0x10, 0x08, 0x1F, // 114
    0x12, 0x15, 0x15, 0x09, // 115
    0x09, 0x7F, 0x8, // 116
    0x1F, 0x01, 0x01, 0x1E, // 117
    0x1C, 0x02, 0x01, 0x02, 0x1C, // 118
    0x1E, 0x01, 0x02, 0x04, 0x02, 0x01, 0x1E, // 119
    0x11, 0x0A, 0x04, 0x0A, 0x11, // 120
    0x1E, 0x05, 0x05, 0x05, 0x19, // 121
    0x11, 0x19, 0x15, 0x13, 0x11, // 122
    0x41, 0x36, 0x08, // 123
    0xFF, // 124
    0x08, 0x36, 0x41, // 125    
    };
BYTE const numbers[]={0x3F,0x30,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int1 nd;
unsigned int8 pos1;
//concat two 8bit int and gives a 16 bit int
//helper function
unsigned int16 concat(unsigned int8 d1,unsigned int8 d2)
{
  unsigned int16 temp;
  temp=0x0000;
  temp=d1;
  shift_left(&temp,2,0);
  shift_left(&temp,2,0);
  shift_left(&temp,2,0);
  shift_left(&temp,2,0);
  shift_left(&temp,2,0);
  shift_left(&temp,2,0);
  shift_left(&temp,2,0);
  shift_left(&temp,2,0);
  //temp=temp&0x0111;
  temp=temp|d2;
  return temp;
}
//since the segment sequence of MAX7219 is
//D7 D6 D5 D4 D3 D2 D1 D0
//DP  A  B  C  D  E  F  G  while according to convention it is
//DP  G  F  E  D  C  B  A
//One may avoide this my doing the proper changes in the circuit wiring but
//it will again lead to more complication because in CODE B decode mode the
//segment are just opposit to what u see in no decode mode. so in any case
//one need to use this helper function if he wants to use the chip in both
//no decode and decode modes.
unsigned int8 reverse(unsigned int8 nd_data)
{
  int1 D[8];
  unsigned int8 i;
  unsigned int8 temp;
  for(i=0;i<8;i++)
  {
      if(shift_left(&nd_data, 1, 0))
        D[i]=1;
      else
        D[i]=0;
  }
  temp=D[1];
  D[1]=D[7];
  D[7]=temp;

  temp=D[2];
  D[2]=D[6];
  D[6]=temp;

  temp=D[3];
  D[3]=D[5];
  D[5]=temp;

  temp=0x00;
  for(i=0;i<8;i++)
      shift_left(&temp,1,D[i]);

  return temp;
}
//Quite self explanatory
//it displays a data at the address given
//1 -> 1st digit
//8 -> 8th digit
//and dis_data is the data that is to be displayed there
void display(char adresse,char dis_data)
{
 char x;
 unsigned int16 dout;
 SSPEN=0;
 if(nd==0)
  dis_data=reverse(dis_data);
 dout=concat(adresse,dis_data);
 output_low(LOAD);

 for (x=16;x>0;x--)
 {
  if (bit_test(dout,x-1)) output_high(DATA);
  else output_low(DATA);
  output_high(CLK);
  delay_cycles(clk_delay);
  output_low(CLK);
  delay_cycles(clk_delay);
 }
 SSPEN=1;
 output_high(LOAD);
}
//another variant of the display function if you use the hardware SPI
/*void display(char adresse,char dis_data)
{
output_low(LOAD);
spi_write(adresse);
delay_us(25);
spi_write(dis_data);
output_high(LOAD);
}*/
//use this function to continously put data in the digits
//without bothering about incremanting the address
//the address increment is done automatically
void seg_putc(unsigned int8 c)
{
  display(pos1,c);
  if(pos1>=8)
      pos1=1;
  else
      pos1++;
}

//Takes an array of 8 datas and put them on the digits
//the dp decides the position of the decimal point
//1 -> decimal point on 1st digit
//8 -> decimal point on 8th digit
void display_digits(unsigned int8 arr[],unsigned int8 dp)
{
      unsigned int8 i;
      //int decimal;
      if(dp>8 || dp<1)
        dp=0;
      for(i=1;i<=8;i++)
      {
        if(dp==i)
            display(i,arr[i-1]+0x80);
        else
            display(i,arr[i-1]+0x00);
      }
      pos1=1;
}
//Takes a character as argument and displays it on a 8x8
//Dot matrix display. Works only in mode 0 i.e. No decode
void display_char(char ch)
{
  int char_offset=0;
  int8 char_width=0;
  int8 char_data[8]={0,0,0,0,0,0,0,0};
  int8 j=0;
  unsigned int16 i=0;
  unsigned int16 sum=0;
  if(ch>=FIRST_CHAR && ch<=LAST_CHAR)
  {
      char_offset=ch-FIRST_CHAR;
      char_width=font_width[char_offset];
      for(i=0;i<char_offset;i++)
      {
        sum=sum+font_width[i];
        //printf("%d+",font_width[i]);
      }
      //printf("\r\n\r\n%ld\r\n",sum);
      j=((8-char_width)/2);
      for(i=sum;i<sum+char_width;i++)
      {
        char_data[j]=font[i];
        //printf("(%d, %X), "i,font[i]);
        j++;
      }
      //display_digits(char_data,0);
      for(i=8;i>=1;i--)
      {
        //printf("%X, ",char_data[i-1]);
        display(9-i,char_data[i-1]);
      }        
  }
}
//Sets the text for scrolling. Call it to change the
//scrolling text.
void scroll_text(unsigned char* str)
{
  int len=0;
  len=strlen(str);
  scroll_text_len=len;
  scroll_chars=malloc(len+1);
  strcpy(scroll_chars,str);
}
//keep on calling this function repetedly to scroll text
void start_scroll()
{
  int char_offset=0;
  int8 char_width=0;
  int1 interspace=0;
  unsigned int16 i=0;
  unsigned int16 sum=0;
  char ch=0;
  ch=scroll_chars[cur_scroll_position];
  if(ch>=FIRST_CHAR && ch<=LAST_CHAR)
  {
      if(cur_letter_position==cur_letter_end_position)
      {

        if(temp_char_spacing<char_spacing)
        {
              interspace=1;
              temp_char_spacing++;
        }
        else
        {
              interspace=0;
              temp_char_spacing=0;
              char_offset=ch-FIRST_CHAR;
              char_width=font_width[char_offset];
              for(i=0;i<char_offset;i++)
                sum=sum+font_width[i];
              cur_letter_position=sum;
              cur_letter_end_position=cur_letter_position+char_width;              
              cur_scroll_position++;
              if(cur_scroll_position>=scroll_text_len)
                  cur_scroll_position=0;            
        }
      }
      for(i=7; i>0; i--)
          cur_char_data[i] = cur_char_data[i-1];      
      if(interspace==0)
      {
        cur_char_data[/i]
[/i][/i][/i][/i][/i][/i][/i][/i][/i][o][i][i][i][i][i][i][i][i][i][i]=font[cur_letter_end_position-1];
        cur_letter_end_position--;
      }
      else
      {
        cur_char_data[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]
[o][i][i][i][i][i][i][i][i][i][i]=0x00;;
      }
      for(i=1;i<=8;i++)
      {
        //printf("%X, ",cur_char_data[i-1]);
        display(9-i,cur_char_data[i-1]);
      }  
      //printf("\r\n");
  }
}
void put_number(unsigned char* str,int1 align=0,int1 pad_zeros=0)
{
  unsigned int8 len=0;
  int8 i=0,j=0;
  unsigned int8 char_data[8]={0,0,0,0,0,0,0,0};
  len=strlen(str);
  if(align==0)
  {
      for(i=0;i<len;i++)
      {
        if(str[i]=='.')
        {
            char_data[j-1]+=0x80;
        }
        else
        {
            if(str[i]>=48 && str[i]<=57)
            {
              char_data[j]=numbers[(str[i]-48)];
              j++;
            }
        }
      }
  }
  else
  {
      j=7;
      //printf("%d",i);
      for(i=len-1;;i--)
      {
        //printf("%d\r\n",i);
        if(i==-1)  break;
        if(str[i]=='.')
        {
            char_data[j]=numbers[(str[i-1]-48)]+0x80;
            i--;
            j--;
        }
        else
        {
            if(str[i]>=48 && str[i]<=57)
            {
              char_data[j]=numbers[(str[i]-48)];
              j--;
            }
        }
      }  
      if(pad_zeros)
      {
        if(j!=-1)
        for(i=0;i<=j;i++)
            char_data[i]=0x3F;
      }
  }
  display_digits(char_data,0);
}
//intialize the display driver chip
//it takes the argument decode that decides whether the digits are
//decoded using CODE B scheme or they are not decoded at all
//0 -> No decode
//1 -> Decode
void display_init(int1 decode)
{
 output_low(CLK);
 delay_us(1);
 output_high(LOAD);
 nd=1;
 display(0x0B,0x07);  // scan limit - 8 columnas
 display(0x0C,0x01);  // Shutdown - normal mode
 if(!decode)
  display(0x09,0x00);  // decode mode = 0
 else
  display(0x09,0xFF);  // decode mode = 1
 display(0x0A,0x07);  // intensity
 nd=decode;
 pos1=1;
 //display(0x0F,0x00);  // test
}
[/i]
[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]