0
#define F_CPU 16000000UL          // AVRJazz28PIN Board Used 16MHz
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

#define SPI_PORT PORTB
#define SPI_DDR  DDRB
#define SPI_CS   PB2


void SPI_Write(uint8_t addr, uint8_t dataout)
{        
  // Enable CS Pin
  SPI_PORT &= ~(1<<SPI_CS);

  // Start Address transmission (MOSI)    
  SPDR = addr;

  // Wait for transmission complete
  while(!(SPSR & (1<<SPIF)));    

  // Start Data transmission (MOSI)
  SPDR = dataout;

  // Wait for transmission complete
  while(!(SPSR & (1<<SPIF)));

  // Disable CS Pin
  SPI_PORT |= (1<<SPI_CS);    
}
 char digit[10] = {0,0,0,0,0,0,0,0,0,0};
digit[0] = 0x7E
digit[1] = 0x30
digit[2] = 0x6D
digit[3] = 0x79
digit[4] = 0x33
digit[5] = 0x5B
digit[6] = 0x5F
digit[7] = 0x70
digit[8] = 0x7F
digit[9] = 0x7B

void main()
{
char ch;
char digits_disp[10] = {0,0,0,0,0,0,0,0,0,0};
ch = digits_disp[3];
}

this is a very basic code. I am designing a clock using the MAX 7219 display driver. Before i go into the detail of it, I wanted to get a basic code working where I will initialise the SPI and then declare the value of each character using the datasheet of MAX7219 and then just write a short array to display random numbers. But this code is not working propoerly and keeps saying: ../exp3.c:45: error: conflicting types for 'digits_disp' ../exp3.c:44: error: previous definition of 'digits_disp' was here

Can you please help me on what I am doing wrong and could you tell me how I can initialize my array so that I can display the character '3' on my simulation? In other words, what line of code will i need to add in order to display the characters in my array? Thank you.

  • The lines where you set up the digit[] array are not valid C. Firstly you haven't terminated the lines with semi-colons and secondly you can't have code outside of a function block. – Vicky Jan 06 '15 at 21:53
  • (and thirdly, I don't believe you get *that* error from *that* code. Post the exact code you are trying to compile and indicate which lines are noted in the error.) – Vicky Jan 06 '15 at 21:54
  • Did you ever get this sorted out? – Super-intelligent Shade Jan 22 '15 at 14:37

2 Answers2

0

I can't really make sense of your code, but this part of the code is syntactically invalid:

char digit[10] = {0,0,0,0,0,0,0,0,0,0};
digit[0] = 0x7E
digit[1] = 0x30
digit[2] = 0x6D
digit[3] = 0x79
digit[4] = 0x33
digit[5] = 0x5B
digit[6] = 0x5F
digit[7] = 0x70
digit[8] = 0x7F
digit[9] = 0x7B

You probably want to do this instead:

char digit[10] = { 0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F, 0x7B };
  • basically what I am trying to do is to use MAX7219 to display digits. I was told the best way of doing that is using SPI. I am not familiar SPI and have done some research in order to produce the code you see above. Could you possibly let me know if what I am doing is correct when initalizing the SPI and also, how can I create an array which i can use to display numbers on the 7 segment display. e.g. i want to display number s like 3, 5 ,2, 7. Which lines of code will I need to add and where in order to display these numbers one after the other? I really appreciate your help. – Syed M Kumail Bokhari Jan 07 '15 at 23:16
0

From the comment in the 1st line I gather you are using one of the Atmel chips. If so, here is the article that should help you:

http://www.adnbr.co.uk/articles/max7219-and-7-segment-displays

You can use their code as the starting point:

https://gist.github.com/adnbr/2352797

Here is also Arduino version in case anyone else is interested:

https://gist.github.com/nrdobie/8193350