CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem with two max7219

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rosiley



Joined: 29 May 2014
Posts: 18
Location: Brasil

View user's profile Send private message

Problem with two max7219
PostPosted: Mon Apr 25, 2016 6:10 pm     Reply with quote

Good evening everyone.

I have a question here that I can not solve.

I am using two MAX7219, the first triggering 5 7-segment display showing the value of channel 0 and the second MAX7219 showing channel 1 pic. How should I do the scheduling ? Follows the code.

I can not do the second MAX7219 for the value of channel 1.
Code:

#include <18F4553.h>          // Includes header file PIC 18F4553
#device ADC = 12              //Sets 12 bits for the result of the AD conversion
#use delay (clock=20000000)   /*Set the frequency of the crystal to calculate
                              ..of delays */

#use spi(do=pin_D0,clk=pin_D2,bits=16,load_active=1,load=pin_D1,idle=1, stream=MAX1)

#use spi(do=pin_C0,clk=pin_C2,bits=16,load_active=1,load=pin_C1,idle=1, stream=MAX2)

//bits control configuration
#fuses HS
#fuses NOWDT
#fuses PUT
#fuses BROWNOUT
#fuses NOLVP

// It shows the value of the AD converter
int32 hc1, hc2;       

// It shows the value of Conversion
int32 hc1result; 
int32 hc2result; 
 

// The bits to display configuration in the 7-segment display
int address, data, adqnum, digit[5];
int16 packetmax;

// Packet transmission via spi to the max
void maxsend(int8 channel)
{                                //routine for send information to the max
packetmax=make16(address,data);  //make a 16 bit variable direcc byte high, dato byte low
if(channel == 1)
spi_xfer(MAX1, packetmax);       //transfer using spi software
if(channel == 2)
spi_xfer(MAX2, packetmax);
}

// Configuration properties MAX7219
void maxsetup()
{
   // Initialize the first MAX7219. The channel parameter = 1.
   
   address=0x00, data=0x00,  maxsend(1);  // No-Operation
   address=0x09, data=0xff,  maxsend(1);  // Decode-Mode Register Examples (Address (Hex) = 0xX9)
   address=0x0a, data=0x0f,  maxsend(1);  // Intensity Register Format (Address (Hex) = 0xXA)
   address=0x0b, data=0x05,  maxsend(1);  // Scan-Limit Register Format (Address (Hex) = 0xXB)
   address=0x0f, data=0x01,  maxsend(1);  // Display-Test Register Format(Address (Hex) = 0xXF)
   address=0x0c, data=0x01,  maxsend(1);  // Shutdown Register Format (Address (Hex) = 0xXC)
   
   // Initialize the second MAX7219. The channel parameter = 2.
   
   address=0x00, data=0x00, maxsend(2);   // No-Operation
   address=0x09, data=0xff, maxsend(2);   // Decode-Mode Register Examples (Address (Hex) = 0xX9)
   address=0x0a, data=0x0f, maxsend(2);   // Intensity Register Format (Address (Hex) = 0xXA)
   address=0x0b, data=0x05, maxsend(2);   // Scan-Limit Register Format (Address (Hex) = 0xXB)
   address=0x0f, data=0x01, maxsend(2);   // Display-Test Register Format(Address (Hex) = 0xXF)   
   address=0x0c, data=0x01, maxsend(2);   // Shutdown Register Format (Address (Hex) = 0xXC)
}

// The following lines are used for the digits
void algebra_digits()
{   
   // Initialize the first line 7 segments display.. The channel parameter = 1.
   digit[0] = hc1result/1000;
   digit[1] = ((hc1result % 1000)*10)/1000;
   digit[2] = ((((hc1result % 1000)*10) % 1000)*10)/1000;
   digit[3] = ((((((hc1result % 1000)* 10) % 1000) * 10) % 1000 )* 10) / 1000;
   digit[4] = ((((((((hc1result % 1000)* 10) % 1000) * 10) % 1000) * 10) % 1000)* 10) / 1000;
   
   // Initialize the second line 7 segments display. The channel parameter = 2.
   digit[0] = hc2result/1000;
   digit[1] = ((hc2result % 1000)*10)/1000;
   digit[2] = ((((hc2result % 1000)*10) % 1000)*10)/1000;
   digit[3] = ((((((hc2result % 1000)* 10) % 1000) * 10) % 1000 )* 10) / 1000;
   digit[4] = ((((((((hc2result % 1000)* 10) % 1000) * 10) % 1000) * 10) % 1000)* 10) / 1000;
   
}
void main()                   
{
// Set the analog inputs AN0 to AN4
SETUP_ADC_PORTS(AN0_TO_AN4|VSS_VREF);   
// Use the internal clock to the time of acquisition
SETUP_ADC(ADC_CLOCK_Internal);
// Enable global interrupt
Enable_Interrupts(GLOBAL);
// Enables interruption by receiving data in serial
Enable_Interrupts(INT_RDA);
// Enables interruption by overflow of Timer 0
ENABLE_INTERRUPTS(INT_TIMER0);
/* Set Timer 0 Prescaler to increase the machine cycle of 1 : 256 and
mode 8 bits */
SETUP_TIMER_0(RTCC_INTERNAL | RTCC_DIV_256 | RTCC_8_BIT);
// Start the Timer 0 with the value 61 - Interruption every 25ms
SET_TIMER0(61);

maxsetup();
delay_ms(3000); // Delays the start of the display

/* Makes cleaning all the rec variable and makes the controleb maga indexes 0 */
for(cont = 0; cont < 5; cont++) rec[cont] = '\0';
cont = 0;

//Main Loop
while(true)                           
   {
     
  for(adqnum=1;adqnum<=100;adqnum++)
  {   //collect 100 samples, I usually do this, u can use your favorite method
         hc1=hc1+read_adc();     //for acquisition.
         delay_us(20);
         
         hc2=hc2+read_adc();     //for acquisition.
         delay_us(20);
  }   
      hc1=hc1*10;
      algebra_digits();           //call algebra routine to get each digit
      address=0x01, data=(digit[0] | 0b10000000), maxsend(1);   //use OR for adding decimal point
      address=0x02, data=digit[1], maxsend(1);
      address=0x03, data=digit[2], maxsend(1);   
      address=0x04, data=digit[3], maxsend(1);
      address=0x05, data=digit[4], maxsend(1);
     
      hc1=0;                      //clean hc1
     
      hc2=hc2*10;
      algebra_digits();           //call algebra routine to get each digit
      address=0x01, data=(digit[0] | 0b10000000), maxsend(2);   //use OR for adding decimal point
      address=0x02, data=digit[1], maxsend(2);
      address=0x03, data=digit[2], maxsend(2);   
      address=0x04, data=digit[3], maxsend(2);
      address=0x05, data=digit[4], maxsend(2);
         
      hc2=0;                      //clean hc2
     
 
   SET_ADC_CHANNEL(0);     //Sets the read channel 0
   delay_us(100);          //Channel adjustment time (required)
   hc1 = READ_ADC();       //Does the AD conversion and saves it in the variable ad0
   
   SET_ADC_CHANNEL(1);     //Sets the read channel 1
   delay_us(100);          //Channel adjustment time (required)
   hc2 = READ_ADC();       //Does the AD conversion and saves it in the variable ad1
   
   
   hc1result = (hc1 * 5000) /4095;
   hc2result = (hc2 * 5000) /4095; 
           
   delay_ms(100);          //Delay 100ms
   }
}


Last edited by rosiley on Tue Apr 26, 2016 12:58 pm; edited 3 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 25, 2016 6:43 pm     Reply with quote

Quote:
second MAX7219 showing channel 1 pic

What do you mean by "pic" ?
Is it your 12F683 ? Or do you mean a graphic image ?

Is your second MAX7219 connected to your 12F683 ? What pins on the PIC ?
Is there only one 12F683, or are there two of them ?

I'm just trying to get some details that you didn't explain.
rosiley



Joined: 29 May 2014
Posts: 18
Location: Brasil

View user's profile Send private message

PostPosted: Mon Apr 25, 2016 6:55 pm     Reply with quote

What do you mean by "pic" ?
This is my microcontroller.

Is it your 12F683 ? Or do you mean a graphic image ?
I used the pic 16f877a

Is your second MAX7219 connected to your 12F683 ?
I used two max7219 and one pic

What pins on the PIC ?
Is there only one 12F683, or are there two of them ?
This code is a example, i go used
the pic 16f877

I'm just trying to get some details that you didn't explain.


Last edited by rosiley on Mon Apr 25, 2016 7:17 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 25, 2016 7:01 pm     Reply with quote

I'm not sure exactly what your problem is.

What is "channel 1" ?

- Is it the 2nd MAX7219 ?

- Is it a different ADC channel on the PIC ?

And please answer my questions from my previous reply.
rosiley



Joined: 29 May 2014
Posts: 18
Location: Brasil

View user's profile Send private message

PostPosted: Mon Apr 25, 2016 7:24 pm     Reply with quote

I am using a 16F877A , the value of AN0 channel will be shown in the first max and the value of AN1 channel will be shown in the second max . I already have the value of AN0 channel being shown , only two are in max I need this figure shows only the first max .
How do I put a picture here.
rosiley



Joined: 29 May 2014
Posts: 18
Location: Brasil

View user's profile Send private message

PostPosted: Mon Apr 25, 2016 7:43 pm     Reply with quote

See this video.

https://www.youtube.com/watch?v=ikgQyHx_yB0
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 25, 2016 11:59 pm     Reply with quote

You are using a 16F877A, so you many i/o pins.

1. Choose 3 unused i/o pins on the 16F877A, and connect the second
MAX7219 to those pins.

2. Make a second #use spi() statement for the second MAX7219.

3. Use streams with the #use spi() statements. The first #use spi()
should have stream=MAX1 added to it. The second #use spi() should
have stream=MAX2 added to it.

Example:
Let's assume the second MAX7219 is placed on PortB. The two #use spi()
statements would be given stream names like this:
Code:
#use spi(do=pin_a0,clk=pin_a2,bits=16,load_active=1,load=pin_a1,idle=1, stream=MAX1)

#use spi(do=pin_b0,clk=pin_b2,bits=16,load_active=1,load=pin_b1,idle=1, stream=MAX2)


Then modify the maxsend() function to have a parameter for the channel.
If channel 1 is specified, then send SPI data to the first MAX7219. If
channel 2 is specified, then send it to the second MAX7219:
Code:

void maxsend(int8 channel){                         
   packetmax=make16(address,data); 
   if(channel == 1)
      spi_xfer(MAX1, packetmax); 
   if(channel == 2)
      spi_xfer(MAX2, packetmax);
}



When you call the maxsend() function, you must specify which MAX7219
chip you want to talk to. This is done with the channel parameter.
Example:
Code:

void maxsetup(){   
// Initialize the first MAX7219. The channel parameter = 1.
address=0x00, data=0x00, maxsend(1);
address=0x09, data=0xff, maxsend(1);
address=0x0a, data=0x0f, maxsend(1);
address=0x0b, data=0x05, maxsend(1);
address=0x0f, data=0x01, maxsend(1);
address=0x0c, data=0x01, maxsend(1);

// Initialize the second MAX7219. The channel parameter = 2.
address=0x00, data=0x00, maxsend(2);
address=0x09, data=0xff, maxsend(2);
address=0x0a, data=0x0f, maxsend(2);
address=0x0b, data=0x05, maxsend(2);
address=0x0f, data=0x01, maxsend(2);
address=0x0c, data=0x01, maxsend(2);

}


In the rest of your program, you must do the same thing. Put in the
channel parameter in maxsend() to write to the desired MAX7219 chip.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group