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

Problem with MAX7221 and driving leds

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



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

View user's profile Send private message

Problem with MAX7221 and driving leds
PostPosted: Sat Mar 11, 2006 10:51 am     Reply with quote

I trying to drive a led connected on pin 2 (DIG0) and pin 14 (SEG A) on the max7221 with following program, but i can't get to work

Please help me

Code:
#include <18F4620.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,NOBROWNOUT,NOPUT,NOLVP,DEBUG,NOSTVREN,NOPROTECT

#include <max7221.h>

void main() {

   setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);

   max7221_init();

   while(true) {
      max7221_put(DIGIT_0,0x00);
      delay_ms(50);
      max7221_put(DIGIT_0,0x01);
      delay_ms(50);
   }

}

Code:
#ifndef MAX7221_CS

#define MAX7221_CS    PIN_C0
#define MAX7221_CLK   PIN_C3
#define MAX7221_DOUT  PIN_C4
#define MAX7221_DIN   PIN_C5

#endif

// Register address map
#define NO_OP                     0x00  // Used when cascading max7221s
#define DIGIT_0                   0x01  // Digit 0 register
#define DIGIT_1                   0x02  // Digit 1 register
#define DIGIT_2                   0x03  // Digit 2 register
#define DIGIT_3                   0x04  // Digit 3 register
#define DIGIT_4                   0x05  // Digit 4 register
#define DIGIT_5                   0x06  // Digit 5 register
#define DIGIT_6                   0x07  // Digit 6 register
#define DIGIT_7                   0x08  // Digit 7 register
#define DECODE_MODE               0x09  // Decode mode register
#define INTENSITY                 0x0A  // Intensity register
#define SCAN_LIMIT                0x0B  // Scan-limit register
#define SHUT_DOWN                 0x0C  // Shutdown register
#define DISPLAY_TEST              0x0F  // Display-test register

// Shutdown register
#define SHUTDOWN_MODE             0x00  // Shutdown mode
#define NORMAL_MODE               0x01  // Normal mode

// Decode-mode register
#define NO_DECODE_DIGITS_7_0      0x00  // No decode for digits 7-0
#define CODE_B_DECODE_DIGIT_0     0x01  // Code B decode for digit 0
#define CODE_B_DECODE_DIGITS_3_0  0x0F  // Code B decode for digits 3-0
#define CODE_B_DECODE_DIGITS_7_0  0xFF  // Code B decode for digits 7-0

// Intensity register
#define DUTY_CYCLE_1              0x00  // Intensity min
#define DUTY_CYCLE_2              0x01
#define DUTY_CYCLE_3              0x02
#define DUTY_CYCLE_4              0x03
#define DUTY_CYCLE_5              0x04
#define DUTY_CYCLE_6              0x05
#define DUTY_CYCLE_7              0x06
#define DUTY_CYCLE_8              0x07
#define DUTY_CYCLE_9              0x08
#define DUTY_CYCLE_10             0x09
#define DUTY_CYCLE_11             0x0A
#define DUTY_CYCLE_12             0x0B
#define DUTY_CYCLE_13             0x0C
#define DUTY_CYCLE_14             0x0D
#define DUTY_CYCLE_15             0x0E
#define DUTY_CYCLE_16             0x0F  // Intensity full

// Scan-limit register
#define DISPLAY_DIGIT_0           0x00  // Display digit 0
#define DISPLAY_DIGITS_01         0x01  // Display digits 0 & 1
#define DISPLAY_DIGITS_012        0x02  // Display digits 0 1 2
#define DISPLAY_DIGITS_0123       0x03  // Display digits 0 1 2 3
#define DISPLAY_DIGITS_01234      0x04  // Display digits 0 1 2 3 4
#define DISPLAY_DIGITS_012345     0x05  // Display digits 0 1 2 3 4 5
#define DISPLAY_DIGITS_0123456    0x06  // Display digits 0 1 2 3 4 5 6
#define DISPLAY_DIGITS_01234567   0x07  // Display digits 0 1 2 3 4 5 6 7

// Display-test register
#define NORMAL_OPERATION          0x00  // Normal operation
#define DISPLAY_TEST_MODE         0x01  // Display-test mode, all leds on

void max7221_put(int addr,int data) {
   output_low(MAX7221_CS);
   spi_write(addr);
   spi_write(data);
   output_high(MAX7221_CS);
}

void max7221_init() {
   max7221_put(DECODE_MODE,NO_DECODE_DIGITS_7_0);
   max7221_put(SCAN_LIMIT,DISPLAY_DIGIT_0);
   max7221_put(SHUT_DOWN,NORMAL_MODE);
   max7221_put(DISPLAY_TEST,NORMAL_OPERATION);
   max7221_put(INTENSITY,DUTY_CYCLE_8);
}
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Sun Mar 12, 2006 9:03 am     Reply with quote

You have to ask a SPECIFIC question here. Just stating that it doesn't work gives 0 information to any potential helper.

What did you want it to do? What is it doing instead? Why are you hooking up a single LED to a 7.5 segment LED driver?

As has been pointed out many times before:

1) Ask Specific questions. If you don't that means we all have to guess at the billion ways a hardware/firmware/software project can fail. No one will do this since it is a waste of our time.

2) Your last post went unanswered (AFAIK) because you basically pasted a pointer to a datasheet and asked people to get you started on it. Get yourself started on it and when you run in to a problem with your code then ask a specific question. Unless someone on here is more kindhearted than most and has designed one of those bits into a project of theirs, no one is going to go off and read a spec for you and write code.

Maybe its not my place to say this, and maybe it sounds harsh, but it needs to be said again. Its clearly term project season in high schools, colleges and universities around the globe, because there are alot of posts lately asking the forum members to do their project for them.

[/vent_mode]
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