Haberler:

Foruma Resim Yükleme ve Boyut Sınırlaması ( ! )  https://bit.ly/2GMFb8H

Ana Menü

max7219.c ve max7219.h

Başlatan Cetinal, 29 Aralık 2006, 01:29:11

Cetinal

bana max7219.c ve max7219.h dosyası lazım
elinde olan varsa burda yayınlayabilirmi
kolay gelsin


Analyzer

Selam,

Bu ve bunun gibi bir çok komponentin CCS sürücülerini bu adreste bulabilirsiniz :

http://www.ccsinfo.com/forum/

Analyzer
Üşeniyorum, öyleyse yarın!

zafzaf82

/*! \file max7221.h
 *  \brief Driver pour le driver d'affichages 7-segments SPI MAX7221
 *
 *    !! MAX7221_CS doit être défini dans le fichier principal  !!
*/

// Addresses des différents registres du MAX7221

#define   NOP            0x00
#define   DIG_0            0x01
#define   DIG_1            0x02
#define   DIG_2            0x03
#define   DIG_3            0x04
#define   DIG_4            0x05
#define   DIG_5            0x06
#define   DIG_6            0x07
#define   DIG_7            0x08
#define   DECODE_MODE      0x09
#define   INTENSITY      0x0A
#define   SCAN_LIMIT      0x0B
#define   SHUTDOWN         0x0C
#define   TEST            0x0F

// Diverses valeurs pour la configuration de ces registes

// Registre SHUTDOWN
#define   SHUTDOWN_MODE   0x00
#define   NORMAL_MODE      0x01         // Valable aussi pour le registre TEST

// Registre DECODE_MODE
#define   NO_DECODE      0x00
#define   BCD_DIG0         0x01
#define   BCD_DIG0to3      0x0F
#define   BCD_ALL         0xFF

// Registre SCAN_LIMIT
#define   DIG0_ONLY      0x00
#define   DIG0to1         0x01
#define   DIG0to2         0x02
#define   DIG0to3         0x03
#define   DIG0to4         0x04
#define   DIG0to5         0x05
#define   DIG0to6         0x06
#define   DIG0to7         0x07

// Registre TEST
#define   TEST_MODE      0x00
//#define   NORMAL_MODE      0x01         // Défini pour le registre Shutdown

///////////////////////////////////////////////////////////////////////////////
/*! \brief Allumage/Extinction de l'affichage
 *
 *
 *  \param booléen, true=on, false=off
 */
///////////////////////////////////////////////////////////////////////////////
void setDisplayOnOffState(short int state)
{

   output_low(MAX7221_CS);
   delay_cycles(4);

   spi_write(SHUTDOWN);

   if(state)
      spi_write(NORMAL_MODE);
   else
      spi_write(SHUTDOWN_MODE);

   output_high(MAX7221_CS);
}
///////////////////////////////////////////////////////////////////////////////
/*! \brief Entrée, sortie du mode de test
 *
 *
 *  \param booléen, true=test, false=std
 */
///////////////////////////////////////////////////////////////////////////////
void setDisplayTest(short int state)
{

   output_low(MAX7221_CS);
   delay_cycles(4);

   spi_write(TEST);

   if(state)
      spi_write(TEST_MODE);
   else
      spi_write(NORMAL_MODE);

   output_high(MAX7221_CS);
}
///////////////////////////////////////////////////////////////////////////////
/*! \brief Setup de l'intensité de l'affichage
 *
 *
 *  \param int, l'intensité, <16
 */
///////////////////////////////////////////////////////////////////////////////
void setDisplayIntensity(int intensity)
{
   if(intensity<16)
   {
      output_low(MAX7221_CS);
      delay_cycles(4);

      spi_write(INTENSITY);
      spi_write(intensity);

      output_high(MAX7221_CS);
   }
}
///////////////////////////////////////////////////////////////////////////////
/*! \brief Setup du mode de décodage pour les digits
 *
 *
 *  \param int, indiquant le mode à utiliser
 */
///////////////////////////////////////////////////////////////////////////////
void setDisplayDecodeMode(int decodeMode)
{

   output_low(MAX7221_CS);
   delay_cycles(4);

   spi_write(DECODE_MODE);
   spi_write(decodeMode);

   output_high(MAX7221_CS);
}
///////////////////////////////////////////////////////////////////////////////
/*! \brief Setup du nombre de digits affichés
 *
 *
 *  \param int, le nombre de digits à afficher, 1-8
 */
///////////////////////////////////////////////////////////////////////////////
void setDisplayDigitsCount(int digitCount)
{

   if(digitCount>0 && digitCount<9)
   {
      output_low(MAX7221_CS);
      delay_cycles(4);

      spi_write(SCAN_LIMIT);
      spi_write(digitCount-1);

      output_high(MAX7221_CS);
   }
}
///////////////////////////////////////////////////////////////////////////////
/*! \brief Envoi d'une valeur au digit considéré
 *           L'affichage dépendra du mode de décodage du digit considéré
 *
 *  \param int, le digit (<8)
 *           int, la valeur à charger
 */
///////////////////////////////////////////////////////////////////////////////
void setDisplayDigit(int digit, int value)
{
   if(digit<8)
   {
      output_low(MAX7221_CS);
      delay_cycles(4);

      spi_write(digit+1);
      spi_write(value);

      output_high(MAX7221_CS);
   }
}


// Digits 0-3 devront être décodés en BCD
   setDisplayDecodeMode(BCD_DIG0to3);
   // On sélectionne une intensité moyenne
   setDisplayIntensity(8);
   // On lui indique que seuls les digits 0-3 seront utilisés
   setDisplayDigitsCount(4);
   // On le met en mode standard
   setDisplayTest(NORMAL_MODE);
   // Et on l'allume
   setDisplayOnOffState(TRUE);


Alıntıdır
Mikroişlemci bi araçtır, amaç değil.....

zafzaf82

////////////////////////////////////////////////////////////////////////////////
//
//   The LOAD/CS of the MAX7219 was LOW Active
//
//
////////////////////////////////////////////////////////////////////////////////




#include <18F452.h>
#device ADC=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
//#use i2c(Master, SDA=PIN_B7, SCL=PIN_B6)
#use i2c(Master, SDA=PIN_B4, SCL=PIN_B3)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
//#use i2c(Master, SDA=PIN_B7, SCL=PIN_B6)
#use i2c(Master, SDA=PIN_c4, SCL=PIN_c3)


#include <max7219_ds1307.c>
#include <ds1307.c>

unsigned char hrh,hrl,minh,minl;

void init_ds1307()
{
   // Put some date and time values into the global date & time array.
   gca_ds1307_regs[DS1307_SECONDS_REG] = 0; // 0 seconds
   gca_ds1307_regs[DS1307_MINUTES_REG] = 14; // 10 minutes
   gca_ds1307_regs[DS1307_HOURS_REG] = 8; // 8 AM
   gca_ds1307_regs[DS1307_DAY_OF_WEEK_REG]= 0; // Skip this.
   gca_ds1307_regs[DS1307_DATE_REG] = 04; // 3 rd
   gca_ds1307_regs[DS1307_MONTH_REG] = 01; // Jan
   gca_ds1307_regs[DS1307_YEAR_REG] = 05; // 2005
   

   // Write these values to the DS1307, for testing.
   ds1307_set_date_time();
 

}






//*********  Main Program Start Here **********/////

void main()       
{
   
   int second;
   int   minute;
   int hours;
   int dates;
   int months;
   int year;

   char sec;
   char min;
   char hrs;
   char day;
   char date;
   char month;
   char yr;


   init_ds1307();

   setup_adc_ports( ALL_ANALOG );
   setup_adc( ADC_CLOCK_INTERNAL );

    output_low(max_clk);                                       // set clk line low     
     output_low(max_din);                                       // set data line in low    
     output_high(max_load);                                     // set load/cs line high    
   output_float(max_din);                                     // set pin as input
   
   setup_spi(SPI_MASTER|SPI_L_TO_H |SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);


      init_7219();                                     // Initialize MAX7219  Value
      
   
   
      hrh =0;
      hrl =0;
      minh=0;
      minl=0;
      
      write_time(hrh,hrl,minh,minl);


   while(1)
   {

      // turn off test mode
         output_low(max_load);                                       // set load line LOW 
      spi_write(0x0C);                                   // shutdown register                                           
      spi_write(0x01);                                   // normal operation                                           
         output_high(max_load);                                      // set load line high
   

      ds1307_read_date_time();

      // Get these into variables with shorter names, so I can
      // put them into printf more easily.
      sec = gca_ds1307_regs[DS1307_SECONDS_REG];
      min = gca_ds1307_regs[DS1307_MINUTES_REG];
      hrs = gca_ds1307_regs[DS1307_HOURS_REG];
      day = gca_ds1307_regs[DS1307_DAY_OF_WEEK_REG];
      date = gca_ds1307_regs[DS1307_DATE_REG];
      month = gca_ds1307_regs[DS1307_MONTH_REG];
      yr = gca_ds1307_regs[DS1307_YEAR_REG];

   
         
      write_time(hrh,hrl,minh,minl);
      
      
    }

}


////////////////////////////////////////////////////////////////////////////
////                             max7219_ds1307.C                              ////
////                 Driver for Max7219 (8-bit 7-segment display        ////
////                                                                    ////
////  init_7219()   Must be called before any other function.           ////
////                                                                    ////
////  write_dig(a,b,c,d)  Will write the number (char) to digit 1-4     ////
////                      The following have special meaning:           ////
////                      hrh = 1st digit                                  ////
////                      hrl = 2nd digit                               ////
////                      minh = 3rd digit                                ////
////                      minl = 4th digit                                 ////
////          ** Digits are order from left to right                                                          ////
////                                                   ////
////
////////////////////////////////////////////////////////////////////////////

#define max_clk      pin_c3                                       // set pin clock is using
#define max_din      pin_c5                                       // set pin data in is using
#define max_load     pin_c0                                      // set pin load/cs is using


void init_7219()                                        
{
   // set number of LED displays to use
      output_low(max_load);                                        // set load line LOW             
      spi_write(0x1B);                                             // point to the Scan Register    
      spi_write(0x03);                                             // send 4, (Four LED Displays 0-3)   
      output_high(max_load);                                      // set load line high


   // set LED intensity to 50%
      output_low(max_load);                                       // set load line LOW   
      spi_write(0x1A);                                             // point to the Intensity Register    
      spi_write(0x05);                                             // send 5, (LED 50% brightness)    
      output_high(max_load);                                      // set load line high


   // set BCD Decoding
      output_low(max_load);                                       // set load line LOW     
      spi_write(0x19);                                            // point to Decode Mode Register   
      spi_write(0x0F);                                             // decode LED 0 - 3    
      output_high(max_load);                                      // set load line high

}
void write_time(unsigned char hrh,unsigned char hrl, unsigned char minh, unsigned char minl)
{
   // dig1
   output_low(max_load);                                       // set load line LOW
      spi_write(0x01);                                            // point to LED (0) Register       
      spi_write(hrh);                                            // send '1'       
   output_high(max_load);

   // dig2
   output_low(max_load);                                       // set load line LOW
      spi_write(0x02);                                            // point to LED (0) Register       
      spi_write(hrl);                                            // send '1'       
   output_high(max_load);

   // dig3
   output_low(max_load);                                       // set load line LOW
      spi_write(0x03);                                            // point to LED (0) Register       
      spi_write(minh);                                            // send '7'       
   output_high(max_load);                     
      

   // dig4   

   output_low(max_load);                                       // set load line LOW
      spi_write(0x04);                                            // point to LED (0) Register       
      spi_write(minl);                                            // send '7'       
   output_high(max_load);                     
   delay_ms(4);
}
Mikroişlemci bi araçtır, amaç değil.....