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

MAX6953 5x7 LED matrix driver functions

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
StuH_CC



Joined: 07 May 2004
Posts: 16
Location: Shropshire, UK

View user's profile Send private message

MAX6953 5x7 LED matrix driver functions
PostPosted: Tue Aug 10, 2004 6:23 pm     Reply with quote

I hope this isn't too messy! It works, anyway (if I haven't left something out...).

Code:
/******************************************************************************

Driver routines for MAX6953 5x7 cathode-row LED display drivers.

Written for the CCS PCM cross-compiler version 3.185

Originally written by Stuart Hunter, Technical Director, ViziMatic Ltd.
******************************************************************************/


#ifndef DISPLAY_SDA

//The pin definitions are set for a PIC16F819 SSP module. If they are
//redefined elsewhere before this file is included then your own definitions
//will override these.
#define DISPLAY_SDA        PIN_B1
#define DISPLAY_SCL        PIN_B4
#endif

//Miscellaneous defines
#define SLOW             0      //Use for setting blink rate      
#define FAST             1
#define PLANE0             0x20   //Use for setting data start address
#define PLANE1             0x40
#define BOTHPLANES          0x60
#define WRITE_NOW          1      //Used in operations affecting the CONFIG
#define WRITE_LATER       0      //register.




//Add FORCE_HW to the end of the line below if you want or need
//to use a hardware I2C implementation (ie your PIC has the MSSP module).
//Remove the line if you've already defined the I2C pins!!!
#use i2c(master, sda=DISPLAY_SDA, scl=DISPLAY_SCL )      //,FORCE_HW

int config_byte;
int device_address;


// Initialise the I2C bus and config register
void init_display()
{
      output_float(DISPLAY_SCL);
      output_float(DISPLAY_SDA);
   config_byte = 0;
}

void set_device_address( int addr )
{
   addr+= 0x50;         //MAX6953 addresses take the form 101xxxx
   device_address = addr;   //where xxxx is the user-selected address 0-15.
}

// This function is mainly for internal use, but you can use it to
// set the CONFIG register directly if you don't want to use the
// individual functions provided for this purpose.
void write_config_register( int config_byte )
{
   i2c_start();
   i2c_write( (device_address<<1) & 0xFE );
   i2c_write( 0x04 );
   i2c_write( config_byte );
   i2c_stop();
}

// This function sets the display interval for each display plane.
// With a 4MHz clock, FAST is 0.5s and SLOW is 1.0s.
void set_blink_speed( int speed, short wrt )
{
   if( speed == SLOW ) config_byte &= 0xFB;
   else config_byte |= 0x04;
   if( wrt ) write_config_register( config_byte );
}

// This function enables or disables plane switching ( blinking )
void blink_enable( short state, short wrt )
{
   if( state ) config_byte |= 8;
   else config_byte &= 0xF7;
   if( wrt ) write_config_register( config_byte );
}

// This function is used for blink time synchronisation across multiple devices.
// call it once for each device, in sequence. Nonpersistent.
void blink_sync( void )
{
   write_config_register( config_byte |= 0x10 );
}

// Clear the plane data in the chip. Nonpersistent.
void clear_digits( void )
{
   write_config_register( config_byte | 0x20 );
}

// Put the display into low power shutdown mode
void shutdown( short state, short wrt )
{
   if( !state ) config_byte |= 0x01;
   else config_byte &= 0xFE;
   if( wrt ) write_config_register( config_byte );
}

// Put the display in test mode. Will illuminate all LEDs if state=TRUE.
// Does not affect plane data - original display is restored when set FALSE.
void display_test( short state )
{
   i2c_start();
   i2c_write( (device_address<<1) & 0xFE );
   i2c_write( 0x07 );
   if (state )
   {
      i2c_write( 1 );
   }
   else
   {
      i2c_write( 0 );
   }
   i2c_stop();
}

// Set the display intensity from 0-15. This routine sets all digits to
// the same value, if you want to set 'em individually then you need to
// implement your own function - I don't need that ability!
void set_intensity( int intens )
{
   int tempd;
   tempd = intens<<4;   //set the most significant nybble
   intens |= tempd;
   i2c_start();
   i2c_write( (device_address<<1) &0xFE );
   i2c_write( 0x01 );      //first intensity register
   i2c_write( intens );
   i2c_write( intens );   //register addr autoincrements, so write second reg.
   i2c_stop();
}

// Sets the number of digits to be displayed ( 2 or 4 ). Included just for
// the hell of it - I don't use this in my app.
void set_scan_limit( short state )
{
   i2c_start();
   i2c_write( (device_address<<1) &0xFE );
   i2c_write( 0x03 );
   if (state )
   {
      i2c_write( 1 );
   }
   else
   {
      i2c_write( 0 );
   }
   i2c_stop();
}

// Set the plane data for display. Normal characters should be written to
// PLANE0. See the Maxim datasheet for an explanation of the data planing
// system.
void write_display_character( int start, int length, char* string )
{
   int n;

   i2c_start();
   i2c_write( (device_address<<1) &0xFE );
   i2c_write( start );                  //start address of write operation
   for( n=0; n<length; n++ )
   {
      i2c_write( string[n] );            //write noninverted string, address
   }                              //will autoincrement.
   i2c_stop();
}

// As above, but displays an inverted ( background lit, char off ) character.
void write_inverted_display_character( int start, int length, char* string )
{
   int n;

   i2c_start();
   i2c_write( (device_address<<1) &0xFE );
   i2c_write( start );                  //start address of write operation
   for( n=0; n<length; n++ )
   {
      i2c_write( string[n] |= 0x80 );      //write inverted string, address
   }                              //will autoincrement.
   i2c_stop();
}


As an example, in the main() function, include the following code:
Code:

init_display();
set_device_address( 0 );
shutdown( FALSE,TRUE );
set_intensity( 15 );
display_test( TRUE );
delay_ms( 2000 );
display_test( FALSE );
write_display_character( PLANE0,4,"TEST" );


This of course assumes that your MAX6953 is set at the base address - if it isn't, then substitute the appropriate number 0-15 in set_device_address().
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Feb 28, 2006 1:07 pm     Reply with quote

Is the driver the same for the MAX6952, exept then the I2C functions
this must be concerted to SPI
Lykos1986



Joined: 26 Nov 2005
Posts: 68

View user's profile Send private message

PostPosted: Fri May 18, 2007 12:15 pm     Reply with quote

Hello!
I am trying to use the previous driver but I have some problems with the program. The MPLAB gives me that error:
Error 90 "E:\MPLAB 7.50\Projects\... …" Line 24(43,44): Attempt to create a pointer to a constant

And the program is:

#include <16F876A.h>
#fuses XT, NOWDT, NOPUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay (clock = 4000000)
#include <max6953.c>

void main()
{
input(pin_b2);
input(pin_b3);
input(pin_c0);
input(pin_c1);

delay_ms(100);

output_high(pin_a5);

init_display();
set_device_address( 0 );
shutdown( FALSE,TRUE );
set_intensity( 1 );
display_test( TRUE );
delay_ms( 2000 );
display_test( FALSE );
write_display_character( PLANE0,4, "TEST" ); ---------------------Error

while(1)
{
output_high(pin_a5);
delay_ms(1000);
output_low(pin_a5);
delay_ms(1000);
}
}


What I have to do???
PCM programmer



Joined: 06 Sep 2003
Posts: 20101

View user's profile Send private message

PostPosted: Fri May 18, 2007 12:32 pm     Reply with quote

Create an array in RAM. Copy the constant string into that array.
Pass the array to the write_display_character() function. See the
changes shown in bold below:
Quote:

void main()
{
char stringbuf[20];

.
.
.


strcpy(stringbuf, "TEST");
write_display_character( PLANE0, 4, stringbuf);
.
.
.
while(1);
}
Lykos1986



Joined: 26 Nov 2005
Posts: 68

View user's profile Send private message

PostPosted: Fri May 18, 2007 2:48 pm     Reply with quote

It works!!!!!

Thank you very much!!!
But why that is happening? I have very basics knowledge on C
PCM programmer



Joined: 06 Sep 2003
Posts: 20101

View user's profile Send private message

PostPosted: Fri May 18, 2007 3:01 pm     Reply with quote

Read the compiler error message:
Quote:
Line 24(43,44): Attempt to create a pointer to a constant

The compiler will not let you create a pointer to a string stored in ROM.
It will only let you create a pointer to a string stored in RAM.
Therefore, you must copy the string from a ROM array ('const') to
a RAM array. Then you can pass the RAM array to a function.
This is a limitation of CCS with the PIC. In future versions of CCS,
they propose to remove this limitation.
getforumcss



Joined: 03 Jun 2007
Posts: 1

View user's profile Send private message

PostPosted: Sun Jun 03, 2007 3:44 pm     Reply with quote

Tks you StuH_CC
It is a very good sample code! but you don't have implement all functionality of a max6953 eg for using USER-DEFINED Fonts in address code 0x05.
i would like drawn a heart or several smiler. can you make it...
best regard

getelectronic
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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