max7219cng sa picom

Rasprava o PIC mikrokontrolerima, PIC projekti i drugo vezano za PIC-eve...

Moderators: pedja089, stojke369, [eDo], trax

Post Reply
User avatar
LegoMan4
Penjem se :)
Penjem se :)
Posts: 92
Joined: 09-05-2012, 21:47
Location: split

max7219cng sa picom

Post by LegoMan4 »

zna li ko koji program ili stranicu u datasheetu u kojem objasnjava kako koordinirati pic sa maxom?
jazz
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 21-10-2010, 21:18
Location: Hrvatska

Re: max7219cng sa picom

Post by jazz »

LegoMan4 wrote:zna li ko koji program ili stranicu u datasheetu u kojem objasnjava kako koordinirati pic sa maxom?
Radi se o standardnom SPI interface-u, a u datasheet dokumentu imaš navedene/objašnjene MAX registre.

I inače, možeš prvo pitati google, pa ako ne pomogne, onda na forumu.

http://www.logicalside.com/LED_driver
http://ee.cleversoul.com/max7219.html
abc
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 498
Joined: 08-03-2007, 20:19
Location: Hrvatska

Re: max7219cng sa picom

Post by abc »

Ovo ti vazi za dspic33fj, radi sa 2 SPI , jedan SPI koristim za komunikaciju sa 2 MAX7219 , svaki ima 8 cifri odnosno 7-segmentnih displeja. SPI se moze ubrzati ali moras imati osciloskop ili logicki analizer da bi odredio delay poslije SPIBUF, jer ne radi sa svim setovanjima. Ovo dolje setovanje ti vazi da nije ukljucen PLL i radi sa internim oscilatorom, znaci 7,37MHz.
Pozoves na pocetku #include<spi.h>
Ovo vise manje vazi za sve picove.

Code: Select all

void init_SPI(void)
{

  
    /* Holds the information about SPI configuartion */

   unsigned int spi1_config1,spi1_config2,spi1_config3;

/* Holds the information about SPI Enable/Disable */

  // unsigned int spi2_config1,spi2_config2,spi2_config3;



/* Turn off SPI modules */

   // CloseSPI1();

ConfigIntSPI1(SPI_INT_EN &  SPI_INT_PRI_5);


/* Configure SPI1 module to transmit 8 bit value in master mode  */
    spi1_config1 = ENABLE_SCK_PIN & ENABLE_SDO_PIN &  SPI_MODE16_ON &

                SPI_SMP_OFF & SPI_CKE_ON &

                SLAVE_ENABLE_OFF &

                CLK_POL_ACTIVE_HIGH &

                MASTER_ENABLE_ON &

                SEC_PRESCAL_8_1 &

                PRI_PRESCAL_1_1;

    spi1_config2 = FRAME_ENABLE_OFF &

            FRAME_SYNC_OUTPUT &

            FRAME_POL_ACTIVE_HIGH &

            FRAME_SYNC_EDGE_COINCIDE;

   spi1_config3 = SPI_ENABLE &

            SPI_IDLE_CON &

            SPI_RX_OVFLOW_CLR;

    OpenSPI1(spi1_config1, spi1_config2, spi1_config3);
    CloseSPI1();
    OpenSPI1(spi1_config1, spi1_config2, spi1_config3);



}





void init_SDI_PINS()
{

	

	_TRISB10 = 0;		//SDO
	_LATB10 = 0;

	_TRISB11 = 0;		//SCK
	_LATB11 = 0;

}

Funkcije za max imas na netu ova je za dspic33fj i dva max-a , da te ne buni CS1 i CS. Takodje radu u 16 bitnom modu slanja kao master, sa pinovima CS i CS1 odredjujem koji max prima a SCK i SDI koristim zajednicke, to radi u MHz pa mozes sa nekoliko da komuniciras bez problema preko istih SCK i SDI .

Code: Select all

void MAX7219Write(unsigned char CS,unsigned int address_dataout)
{
    unsigned char k;
            if(CS>0)
            {SPI_CS1=0; SPI_CS=1;}
            else
            {SPI_CS=0;SPI_CS1=1;}

             SPI1BUF=address_dataout;
             while (SPI1STATbits.SPITBF==1);
		for(k=20;k>0;k--)
        		{
                            asm("nop");
                            }
             if(CS>0)
            {SPI_CS1=1;
             SPI_CS=1;}
            else
            {SPI_CS=1;
            SPI_CS1=1;}




}


void MAX7219DisplayChar(unsigned char CS, unsigned char digit, unsigned char character, unsigned char dp)
{

    unsigned char kk;
    unsigned int send_SDO;

            if(CS>0)
            {SPI_CS1=0; SPI_CS=1;}
            else
            {SPI_CS=0;SPI_CS1=1;}

                unsigned char val;

                val = MAX7219_Font[character];

                    if(dp == 1)
                {
		val |= 0x80;
                }

            send_SDO= digit << 8;
            send_SDO=send_SDO | val;

            SPI1BUF=send_SDO;
         while (SPI1STATbits.SPITBF==1);
		for(kk=20;kk>0;kk--)
        		{
                            asm("nop");
                            }
             if(CS>0)
            {SPI_CS1=1;
             SPI_CS=1;}
            else
            {SPI_CS=1;
            SPI_CS=1;}




}


void MAX7219Init(void)
{



SPI_CS=1;
SPI_CS=1;

  MAX7219Write(0,0x0B07);  //Set Scan limit All 8 Digits
  MAX7219Write(0,0x0900);  //No decode
  MAX7219Write(0,0x0C01);  //put display in normal operation mode
  MAX7219Write(0,0x0f00);  //Start display test
  //MAX7219Write(0,0x0f01);  //Stop display test
  MAX7219Write(0,0x0A04);  //Brightness



}

static const unsigned char MAX7219_Font[] = {0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b,0x77,0x1f,0x4e,0x3d,0x4f,
   0x47, 0x67,0x00,0x80,0x01};



User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3509
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: max7219cng sa picom

Post by trax »

Ako koristis C kompajler za PIC, mozes skinuti kod odavdje: http://www.elektronika.ba/841/sat-sa-rijecima/ koji je pisan za AVR (C jezik) pa ga malo prepraviti i portati na PIC.
Post Reply