MAX7219 with Atmega16A | not showing the 2nd and 1st digit

Status
Not open for further replies.

ikelectro

Member
Here is the code I'm using. In simple when I send instruction to the digits it is showing perfect. But whenever I'm sending instruction to the MAX7219 in the function call "digit_separation", It is not showing the 2nd and 1st digit. Showing only 3rd digit. Can anyone help me on that?



Code:
#include <avr/io.h>
#define F_CPU 12000000UL
#include <util/delay.h>
#include <avr/interrupt.h>

#define MOSI PORTB5
#define SCK PORTB7
#define SS PORTB4

#define setbit(port, bit) (port) |= (1 << (bit))
#define clearbit(port, bit) (port) &= ~(1 << (bit))



void execute  (unsigned char cmd, unsigned char data)
{
    PORTB &= ~(1<<SS);
 
    SPDR = cmd;
    while (!(SPSR & (1<<SPIF)));
 
    PORTB |= (1<<SS);
 
    PORTB &= ~(1<<SS);
 
    SPDR = data;
    while (!(SPSR & (1<<SPIF)));
 
    PORTB |= (1<<SS);
}



void digit_separation (unsigned char y)
 
    {    unsigned char a = ((y/100)%10);
        unsigned char b =((a/10)%10);
        unsigned char c = (b%10);
         
                execute (0x09,0XFF); // enable decoding
                execute (0X0A,0X04); // intensity level
                execute (0X0B,0X02); // scan four segments
                execute (0X0C,0X01); //TURN ON THE CHIP
                execute (0X0F,0X00); //normal mode
                execute(0X01,c);
                execute(0X02,b);
                execute(0X03,a);
             
    }
 


    int main (void)
{ 
    //
 
 
    DDRB = 0XFF;
    clearbit (PORTB,0);
    _delay_ms(1000);
    setbit(PORTB,0);
    _delay_ms(1000);
 
    DDRB = (1<< MOSI) | (1<<SCK) | (1<<SS); // making it out put
    SPCR = (1<<SPE)| (1<<MSTR)|(1<<SPR0); // SPI AS MASTER
 
    execute (0x09,0XFF); // enable decoding
    execute (0X0A,0X04); // intensity level
    execute (0X0B,0X02); // scan four segments
    execute (0X0C,0X01); //TURN ON THE CHIP
    execute (0X0F,0X01); // test mode
    _delay_ms(1000); //test mode wait 1 seconds
    execute (0X0F,0X00); // normal mode
    execute (0X01,0X03);
    
    execute (0X02,0X86);// FOR DECIMAL 128+8 setting the 7th bit
    
    execute (0X03,0X08);
    
    _delay_ms(3000);
 
    unsigned char x = 250;
 
    while (1)
    {
        for (;x>=0;x--)
        {
            digit_separation (x);
            _delay_ms(1000);
            //_delay_ms(1000);
        }
     
    }
 
//return 0;
}
 
Reading the data sheet... The scan limit is set to digits 0,1 & 2... Next to that is an asterisk... You have all 8 enabled

command 0x09 data 0xFF... Try 0x0F and have only four enabled.. The scan limit should be better!! Worth a try!
 
Reading the data sheet... The scan limit is set to digits 0,1 & 2... Next to that is an asterisk... You have all 8 enabled

command 0x09 data 0xFF... Try 0x0F and have only four enabled.. The scan limit should be better!! Worth a try!
I have tried command 0X09, data 0X0F. but no luck. Same results.
 
Try out this sequence to calculate the digits.
I think there is something wrong in Your calculation.
 
hi guys....i need your help. i am in need of creating HEX file from C file or h file. i tried but i was not succeded. thanks a lot.
 

Attachments

  • adc.h
    759 bytes · Views: 225
  • da_pimp2.c
    5.8 KB · Views: 228
  • util.c
    797 bytes · Views: 224
I've tried to rebuilt the failing files.
F_CPU in makefile was set by me to 16000000 please change when not OK.
CPU / 4000 was Changed into F_CPU / 4000 in UTIL File CPU wasn't defined anywhere.
Try out please, if that will work.
Please rename make.pnproj.c to make.pnproj and Makefile.rar to Makefile - ETO doesn't support that file extensions.
Use AVR_GCC to built Your wished .hex File
 

Attachments

  • adc.h
    759 bytes · Views: 230
  • da_pimp2.c
    5.8 KB · Views: 231
  • da_pimp2.hex
    4.6 KB · Views: 234
  • util.c
    799 bytes · Views: 233
  • make.pnproj.c
    91 bytes · Views: 277
  • Makefile.rar
    17.1 KB · Views: 228
if you change "Makefile" it makes a difference on hex file?
Yes, because some parameters are depending from predefines.
E.G. F_CPU = When there is a Variable depending from F_CPU like clock = F_CPU / 4000 then the variable "clock" changes depending from predefined F_CPU.
This was translated into Assembler and then into the the .hex file.
 
if you change "Makefile" it makes a difference on hex file?
I hope I do not sound disrespectful but I don't think you should be messing with the make file!! This is used by the linker to generate the end product! If you are using an IDE, then leave it alone..
 
wkrug....so can you creating hex file by using the newer "makefile" on (#9)?
wkrug i appriciat for your time
Again thanks a lot.
 
This is used by the linker to generate the end product! If you are using an IDE, then leave it alone..
I absolutly agree with You.
In the first post was no Makefile present.
But AVRGCC doesn't work without that. The project file was missing too.
So I've tryed to built the Makefile manually ( with mFile Generator ).
 
wkrug....thank you very much. Vielen Dank dafür, dass du mir gutes Herz zeigst, um mir zu helfen.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…