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 CCS Technical Support

16F628A With MAX7219

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



Joined: 09 May 2011
Posts: 9

View user's profile Send private message

16F628A With MAX7219
PostPosted: Wed May 16, 2012 2:03 am     Reply with quote

Hi all. Nowadays I'm working on a 4 digit 7-segment project. I'm tired of using shift registers or 7447/7448 7-segment driver chips. Then I found this MAX7219. I know that 16F628A doesn't have hardware spi module. So I decided to create a library to use MAX7219 without using hardware or software spi communication. I've simulated all my project using ISIS and there was no problem. However when I try to assamble my project on a breadboard, bam! It doesn't work. I've checked connections, C code, power supply or anything else for a hundred times. I've changed my speed from 20 Mhz to 4 Mhz. I've disabled comparator and timer modules (I thought maybe these can cause trouble). I've set the tris register correctly for port a. But noting nothing and nothing appear on this damn 4 digit 7-segment common cathode display!

This is my library. (You can delete "wait" words. I was trying to giving some delay and I was tired of writing delay_ms(10) Smile "

Code:
/*
******************************************************************************************************
* Chip        : MAX7219
* Author      : Burak HANÇERLİ
* Mail        : bhancerli@gmail.com
* Description : MAX7219 LED Display Driver Routines - v1.0
*   

*  The Maxim MAX7219 is a led display driver. It can control up to 64 individual leds or eight
*  7-segment-display.
*
*  Max7912 uses 3-wire to communicate with microcontroller.
*    - DATA   : Used to transmit data.
*    - CLOCK  : Used to generate clock signal which is required for transmitting each bite of data.
*    - LOAD   : Used to load data to the Max7913's Dual-Port SRam.
*                 
*
*
*  Advantages of Max7219 :
*  - Adjustable intensity. (More or less bright leds)
*  - Shutdown mode (much less power consumption)
*  - Test mode (To see if digits are working or not)
*  - Adjustable digit number. (1 to 8 seven-segment-display)
*  - Changeable decode mode. (codeB-decode-mode or no-decode-mode)
*      (Look over datasheet for more detailed information)
*
*
*  DESCRIPTION OF USER FUNCTIONS
* -------------------------------
*  init7219()                      : Required for initialize MAX7219. This function have has to be called before calling any function.
*  write7219(digit, data)          : Writes data to the specified digit number. If Decimal Point needed on any digit, just add
                                     128 to the data.
                                     For example : write7219(1,3)   = writes "3"  to first digit.
                                                   write7219(1,131) = writes "3." to first digit.
*  shutdown7219(operatingMode)     : Set operatingMode = 0 to Shutdown mode
*                                    Set operatingMode = 1 to Normal mode
*  decode7219(decodeMode)          : Sets digit-decode mode. code-B or no-decode mode. Look up datasheet for detailed instructions.
*                                    For example, if user sets decodeMode = 4, (4=0b00000100), then 3. digit will be
*                                    decoded as code-B algorithm, but other pins don't have any decode mode.
*  brightness7219(brightnessLevel) : Sets brightness level of digits.
*                                    brightnessLevel = 0  ; minimum brightness level
*                                    brightnessLevel = 15 ; maximum brigthness level
*                                   
*  scanLimit7219(totalDigitNumber) : Sets number of connected digits to the MAX7219.   
*  test7219(testMode)              : Sets 7-segment-display test-mode on or off.
                                     testMode = 0 ; normal operation mode
                                     testMode = 1 ; display test mode
                                     
** THIS LIBRARY CAN BE USED, DEVELOPED OR SHARED WITH REFERRING THE AUTHOR.                                   
******************************************************************************************************/


// CONSTANTS //
// - Connection Pins (CHANGE THESE PINS AS YOU WISH)
#define CLK       PIN_A2
#define LOAD      PIN_A1
#define SEND_DATA PIN_A0

// - Mode Selection
#define decode 0x09
#define brightness 0x0A
#define scanLimit 0x0B
#define shutDown 0x0C
#define dispTest 0x0F

// Firt 4 bites (not used generally)
#define firstBites 0x0

// Wait function
#define wait delay_ms(10)

long serialData=0;



void clock7219() // clock (CLK) pulse
{
   output_low(CLK);
   wait;
   output_high(CLK);
}

void load7219()  // load (LOAD) pulse
{
   output_low(LOAD);
   wait;
   output_high(LOAD);
}

void send7219(long data) // send 16 bit data word to the 7219
{

   int count;
   for (count=0; count<16; ++count)
   {
      output_bit(SEND_DATA, shift_left(&data,2,0)); // set data (DIN) level
      clock7219(); // clock data in
   }
   load7219(); // latch the last 16 bits clocked
   wait;
}

void dataMaker(byte mode, int dataIncoming) // Standart data package function
{
   serialData=firstBites;
   serialData<<=4;
   serialData|=mode;
   serialData<<=8;
   serialData|=dataIncoming;
   send7219(serialData);
   wait;
}

void write7219(byte digit, int data) // Send data to digits
{
   dataMaker(digit, data);
   wait;
}

void shutdown7219(int operatingMode)
{
   dataMaker(shutDown,operatingMode);
   wait;
}

void decode7219(int decodeMode)
{
   dataMaker(decode, decodeMode);
   wait;
}

void brightness7219(int brightnessLevel)
{
   dataMaker(brightness, brightnessLevel);
   wait;
}

void scanLimit7219(int totalDigitNumber)
{
   dataMaker(scanLimit, totalDigitNumber);
   wait;
}

void test7219(int testMode)
{
   dataMaker(dispTest, testMode);
   wait;
}

void init7219()
{
   dataMaker(shutDown, 1);     // No-Shutdown mode. Normal Operation mode.
   wait;
   dataMaker(decode, 15);      // All digits are programmed as code-B decode mode.
   wait;
   dataMaker(scanLimit, 4);    // Total digit number set to 4.
   wait;
   dataMaker(brightness, 15);  // Full brightness.
   wait;
}

_________________
Liberate your mind..
canavaroski90



Joined: 09 May 2011
Posts: 9

View user's profile Send private message

PostPosted: Wed May 16, 2012 4:59 am     Reply with quote

Ok, I've solved the problem.

First of all, I couldn't find anything in datasheet about my problem. I've looked up datasheet for hundred times. There's a missing part in "Typical Application Circuit" part.

If you want to make your circuit work, then you should connect 1uF and 10uF between VDD pin of 7219 and +5V. You'll find detailed information here:

http://www.rasmicro.com/FTP/MAX7219-21%208-Digit%20LED%20Display%20Driver.pdf

PS: If you want to use this library, then you can delete wait functions (except which are in load() and clock() functions) and it works @20 Mhz.
_________________
Liberate your mind..
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Wed May 16, 2012 9:49 am     Reply with quote

You are correct that Maxim's diagram "Typical Application Circuit" doesn't have filter capacitors, but the text mentions them under "Supply Bypassing and Wiring". They say 10uF and 0.1uF, but I think 1.0uF would also work. You really should expect capacitors on the power supply of any digital chip.

And Vdd is the +5V pin, though Maxim refers to it as V+. The filter caps go from V+ to Gnd, obviously.
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