|
|
View previous topic :: View next topic |
Author |
Message |
wmeade
Joined: 08 Sep 2003 Posts: 16
|
MAX7219 LED Driver Help needed... |
Posted: Mon Oct 20, 2003 1:28 pm |
|
|
I am trying to drive 2 7 segment leds using a 16F877 with a MAX7219 LED Display Driver chip using PICC SPI Drivers. I have done a search of the forum and found 4 references that I have used to accomplish this. I am only getting the decimal points to blink when I turn on the proto-board. My code is below and any help will be greatly appreciated. All I am trying to do in the program is put a number '8' on LED 0.
As you can see in the setup_spi line, I had to use comas and not the | between the Parameters. Why is this? Is that why it is not working?
Code: |
#include <16F877.H> // processor include file
#fuses HS,NOWDT,PUT,PROTECT,BROWNOUT,NOLVP,WRT // set fuses
#use delay(clock=20000000) // set processor speed 20 MHz
#define max_clk pin_c3 // set pin clock is using
#define max_dout pin_c5 // set pin data in is using
#define max_cs pin_b2 // set pin load/cs is using
output_low(max_clk); // set clock line low
output_low(max_din); // set data line in low
output_high(max_cs); // set load/cs line low
output_float(max_din); // set pin as input
setup_adc_ports(NO_ANALOGS);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER, SPI_L_TO_H, SPI_XMIT_L_TO_H, SPI_CLK_DIV_16);
setup_7219()
{
// set number of LED displays to use
output_low(max_cs); // set cs line low
spi_write(0x0B); // point to the Scan Register
spi_write(0x05); // send 1, (Two LED Displays 0-1)
output_high(max_cs); // set cs line high
// set LED intensity to 50%
output_low(max_cs); // set cs line low
spi_write(0x0A); // point to the Intensity Register
spi_write(0x05); // send 5, (LED 50% brightness)
output_high(max_cs); // set cs line high
// set BCD Decoding
output_low(max_cs); // set cs line low
spi_write(0x09); // point to Decode Mode Register
spi_write(0x03); // decode LED 0 and 1
output_high(max_cs); // set cs line high
// turn off test mode
output_low(max_cs); // set cs line low
spi_write(0x0F); // point to Display Test Register
spi_write(0x00); // turn off test mode
output_high(max_cs); // set cs line high
}
main()
{
setup_7219();
// display a '8' on LED 0
output_low(max_cs); // set cs line low
spi_write(0x001); // point to LED (0) Register
spi_write(0x08); // send '8'
output_high(max_cs); // set cs line high
}
|
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Oct 20, 2003 2:25 pm |
|
|
The setup_spi() is a function call. It should go inside a routine. The way you have it, the compiler thinks that it is a function prototype, thus the error when you compiled with the "|". Yes it should be "|". You should also have an endless loop in your main to prevent the processor from executing a hidden sleep command. I didn't check your code but I made corrections where I know there were problems.
Code: |
#include <16F877.H> // processor include file
#fuses HS,NOWDT,PUT,PROTECT,BROWNOUT,NOLVP,WRT // set fuses
#use delay(clock=20000000) // set processor speed 20 MHz
#define max_clk pin_c3 // set pin clock is using
#define max_dout pin_c5 // set pin data in is using
#define max_cs pin_b2 // set pin load/cs is using
setup_7219()
{
// set number of LED displays to use
output_low(max_cs); // set cs line low
spi_write(0x0B); // point to the Scan Register
spi_write(0x05); // send 1, (Two LED Displays 0-1)
output_high(max_cs); // set cs line high
// set LED intensity to 50%
output_low(max_cs); // set cs line low
spi_write(0x0A); // point to the Intensity Register
spi_write(0x05); // send 5, (LED 50% brightness)
output_high(max_cs); // set cs line high
// set BCD Decoding
output_low(max_cs); // set cs line low
spi_write(0x09); // point to Decode Mode Register
spi_write(0x03); // decode LED 0 and 1
output_high(max_cs); // set cs line high
// turn off test mode
output_low(max_cs); // set cs line low
spi_write(0x0F); // point to Display Test Register
spi_write(0x00); // turn off test mode
output_high(max_cs); // set cs line high
}
main()
{
output_low(max_clk); // set clock line low
output_low(max_din); // set data line in low
output_high(max_cs); // set load/cs line low
output_float(max_din); // set pin as input
setup_adc_ports(NO_ANALOGS);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);
setup_7219();
// display a '8' on LED 0
output_low(max_cs); // set cs line low
spi_write(0x001); // point to LED (0) Register
spi_write(0x08); // send '8'
output_high(max_cs); // set cs line high
while(1);
}
|
|
|
|
cxiong
Joined: 09 Sep 2003 Posts: 52
|
MAX7219 Does not work |
Posted: Tue Dec 28, 2004 11:56 am |
|
|
I have found this post in the forum and I try it, it does not work.
I just does not turn on the LED at all. I use the LDQ-N512RI with
the Max7219. I just need to drive the first 2 digit according to this post.
I modified the code to use my 4Mhz, and pin RC5 to max_din, and max_cs
to pin RC0.
Here is my code:
Code: | #include <16F877.H> // processor include file
#fuses XT,NOLVP // set fuses
#use delay(clock=4000000) // set processor speed 4 MHz
#define max_clk pin_c3 // set pin clock is using
#define max_din pin_c5 // set pin data in is using
#define max_cs pin_c0 // set pin load/cs is using
setup_7219()
{
// set number of LED displays to use
output_low(max_cs); // set cs line low
spi_write(0x0B); // point to the Scan Register
spi_write(0x05); // send 1, (Two LED Displays 0-1)
output_high(max_cs); // set cs line high
// set LED intensity to 50%
output_low(max_cs); // set cs line low
spi_write(0x0A); // point to the Intensity Register
spi_write(0x05); // send 5, (LED 50% brightness)
output_high(max_cs); // set cs line high
// set BCD Decoding
output_low(max_cs); // set cs line low
spi_write(0x09); // point to Decode Mode Register
spi_write(0x03); // decode LED 0 and 1
output_high(max_cs); // set cs line high
// turn off test mode
output_low(max_cs); // set cs line low
spi_write(0x0F); // point to Display Test Register
spi_write(0x00); // turn off test mode
output_high(max_cs); // set cs line high
}
main()
{
output_low(max_clk); // set clock line low
output_low(max_din); // set data line in low
output_low(max_cs); // set load/cs line low
output_float(max_din); // set pin as input
setup_adc_ports(NO_ANALOGS);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);
setup_7219();
while(1)
{
// display a '8' on LED 0
output_low(max_cs); // set cs line low
spi_write(0x01); // point to LED (0) Register
spi_write(0x08); // send '8'
output_high(max_cs); // set cs line high
}
}
|
Did you have your code above working? |
|
|
Guest
|
max7219 |
Posted: Tue Dec 28, 2004 1:14 pm |
|
|
Here is the latest code I have. I have the code to display 8405 on digit 0-3. It does not display the 8405, it display a.a.a.a. on the LED. and I can't control the intensity of the display by low the the hex under register address: 0x0A.
Here is my code: Code: | #include <16f877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#define max_clk pin_c3 // set pin clock is using
#define max_din pin_c5 // set pin data in is using
#define max_cs pin_c0 // set pin load/cs is using
setup_7219()
{
// set number of LED displays to use
output_high(max_cs); // set cs line high
delay_us(1);
spi_write(0x0B); // point to the Scan Register
delay_us(1);
spi_write(0x03); // send 4, (Four LED Displays 0-3)
delay_us(1);
output_low(max_cs); // set cs line low
// set LED intensity to 50%
output_high(max_cs); // set cs line high
delay_us(1);
spi_write(0x0A); // point to the Intensity Register
delay_us(1);
spi_write(0x01); // send 5, (LED 50% brightness)
delay_us(1);
output_low(max_cs); // set cs line high
// set BCD Decoding
output_high(max_cs); // set cs line high
delay_us(1);
spi_write(0x09); // point to Decode Mode Register
delay_us(1);
spi_write(0x0F); // decode LED 0 - 3
delay_us(1);
output_low(max_cs); // set cs line low
// turn off test mode
output_high(max_cs); // set cs line high
delay_us(1);
spi_write(0x0F); // point to Display Test Register
delay_us(1);
spi_write(0x01); // turn off test mode
delay_us(1);
output_low(max_cs); // set cs line low
}
main()
{
output_low(max_clk); // set clk line low
delay_us(1);
output_low(max_din); // set data line in low
delay_us(1);
output_high(max_cs); // set load/cs line high
delay_us(1);
output_float(max_din); // set pin as input
setup_adc_ports(NO_ANALOGS);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_L_TO_H |SPI_XMIT_L_TO_H|SPI_CLK_DIV_4|SPI_SAMPLE_AT_END);
setup_7219();
while(1)
{
// display a '8' on LED 0
output_high(max_cs); // set cs line high
spi_write(0x01); // point to LED (0) Register
delay_us(1);
spi_write(0x08); // send '8'
delay_us(1);
output_low(max_cs); // set cs line low
// display a '4' on LED 1
output_high(max_cs); // set cs line high
spi_write(0x02); // point to LED (0) Register
delay_us(1);
spi_write(0x04); // send '8'
delay_us(1);
output_low(max_cs); // set cs line low
// display a '0' on LED 2
output_high(max_cs); // set cs line high
spi_write(0x03); // point to LED (0) Register
delay_us(1);
spi_write(0x00); // send '8'
delay_us(1);
output_low(max_cs); // set cs line low
// display a '5' on LED 3
output_high(max_cs); // set cs line high
spi_write(0x04); // point to LED (0) Register
delay_us(1);
spi_write(0x05); // send '8'
delay_us(1);
output_low(max_cs); // set cs line low
}
}
|
Any body can help me? |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Wed Dec 29, 2004 9:32 am |
|
|
Read the datasheet for the MAX7219 again.
The code for 50% intensity is 0x07.
The part is in shutdown at powerup. Why are you taking it out of test mode?
Use Code: |
spi_write(0x0C); // shutdown register
spi_write(0x01); // normal operation
|
In your while loop you are setting the CS line high when it should be low and low when it should be high. _________________ David |
|
|
wlasoi@saci.ubu.ac.th Guest
|
try my code, it easy to understand. |
Posted: Fri Feb 04, 2005 3:31 am |
|
|
#include<18f452.h>
#fuses xt,nowdt,put,noprotect
#use delay(clock=4000000)
#define da pin_c0
#define cs pin_c1
#define clk pin_c2
void send_16bit(byte address,byte data)
{
byte i;
#bit carry=0x03.0;
carry=0;
output_low(cs);
for(i=0;i<8;i++)
{
if((address & 0b10000000)==0)
output_low(da);
else
output_high(da);
rotate_left(&address,1);
output_high(clk);
delay_us(50);
output_low(clk);
delay_us(50);
}
for(i=0;i<8;i++)
{
if((data & 0b10000000)==0)
output_low(da);
else
output_high(da);
rotate_left(&data,1);
output_high(clk);
delay_us(50);
output_low(clk);
delay_us(50);
}
output_high(cs);
}
void init_7219()
{
send_16bit(0x09,0xff); //decode
delay_us(100);
send_16bit(0x0a,0x0f); //intensity
delay_us(100);
send_16bit(0x0b,0x07); //scan limit
delay_us(100);
send_16bit(0x0c,0x01); //shutdown
delay_us(100);
send_16bit(0x0f,0x00); //display
delay_us(100);
}
main()
{
int i,j;
set_tris_c(0x00);
init_7219();
delay_ms(1000);
while(1){
for(i=1;i<=8;i++){
for(j=0;j<=9;j++){
send_16bit(i,j);
delay_ms(200);
}
}
}
} |
|
|
Guest
|
Max7219 |
Posted: Mon Aug 29, 2005 8:51 am |
|
|
I want to display the result of ADC result into the 7-segments in decimal,
example 0-255.
How do I separate these numbers such as one, tenth, hundredth out from
the ADC result and display them in the 7-segments.
I have been searching for a very simple way (theory) how to do it, I can't
one that simple enough for me to understand.
Any body give me a direction or a simple theory (explanation) how to do that?
Thanks... |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Aug 29, 2005 9:17 am |
|
|
Well the simplest way would be to divide by 10. The remainder would be the digit.
Code: |
int8 number,digit1,digit10,digit100;
// Get the number
number = get_adc();
// Compute the 1's
digit1 = number % 10;
number /= 10;
// Compute the 10's
digit10 = number % 10;
number /= 10;
// The rest is the 100's
digit100 = number;
|
Last edited by Mark on Mon Aug 29, 2005 10:26 am; edited 1 time in total |
|
|
Guest
|
|
Posted: Mon Aug 29, 2005 10:03 am |
|
|
Hi Mark
I just want clear
example, the adc result is equal to 123
is the above code which divide by 10 will work?
my calculation is
123 / 10 = 12 remainder 3 (3 is the digit1)
123 / 10 = 12 remainder 3 (so the digit10 is also 3?)
Can you explain little bit?
Thanks.. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Aug 29, 2005 10:22 am |
|
|
He is using the /= so the result is the previous result divided by 10
result=123/10=12 R3
result=12/10 =1 R2
result=1/10 = 0 R1
your interested in the remainder
Its like hacking off a digit at a time. hack off 3 then 2 then 1 |
|
|
cxiong
Joined: 09 Sep 2003 Posts: 52
|
|
Posted: Tue Aug 30, 2005 2:26 pm |
|
|
How do I display the ds1307 (hh:mm) into the 7-segment using max7219?
What is the best way to do it? Theory? |
|
|
Guest
|
|
Posted: Thu Sep 01, 2005 7:10 am |
|
|
Can not display the hour and minutes digits into 7-segment.
My questions are:
1. I can not initialize both of the ds1307 and max7219, I think they are
conflict when I run the init_7219(); and the init_ds1307();
in my main code because both use the RC3, RC4 pins.
2. I can not think of a way to single out the following min into minh
and minl, and single out the hrs into hrh and hrl so I can display
their individual digit into their proper location on the 7-segments.
Quote: | min = gca_ds1307_regs[DS1307_MINUTES_REG];
hrs = gca_ds1307_regs[DS1307_HOURS_REG]; |
I would be great appreciate if anyone can help.
I welcome any input or suggestion..
Thanks...........
Here is my main.c code
Code: | ////////////////////////////////////////////////////////////////////////////////
//
// The LOAD/CS of the MAX7219 was LOW Active
//
//
////////////////////////////////////////////////////////////////////////////////
#include <18F452.h>
#device ADC=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
//#use i2c(Master, SDA=PIN_B7, SCL=PIN_B6)
#use i2c(Master, SDA=PIN_B4, SCL=PIN_B3)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
//#use i2c(Master, SDA=PIN_B7, SCL=PIN_B6)
#use i2c(Master, SDA=PIN_c4, SCL=PIN_c3)
#include <max7219_ds1307.c>
#include <ds1307.c>
unsigned char hrh,hrl,minh,minl;
void init_ds1307()
{
// Put some date and time values into the global date & time array.
gca_ds1307_regs[DS1307_SECONDS_REG] = 0; // 0 seconds
gca_ds1307_regs[DS1307_MINUTES_REG] = 14; // 10 minutes
gca_ds1307_regs[DS1307_HOURS_REG] = 8; // 8 AM
gca_ds1307_regs[DS1307_DAY_OF_WEEK_REG]= 0; // Skip this.
gca_ds1307_regs[DS1307_DATE_REG] = 04; // 3 rd
gca_ds1307_regs[DS1307_MONTH_REG] = 01; // Jan
gca_ds1307_regs[DS1307_YEAR_REG] = 05; // 2005
// Write these values to the DS1307, for testing.
ds1307_set_date_time();
}
//********* Main Program Start Here **********/////
void main()
{
int second;
int minute;
int hours;
int dates;
int months;
int year;
char sec;
char min;
char hrs;
char day;
char date;
char month;
char yr;
init_ds1307();
setup_adc_ports( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
output_low(max_clk); // set clk line low
output_low(max_din); // set data line in low
output_high(max_load); // set load/cs line high
output_float(max_din); // set pin as input
setup_spi(SPI_MASTER|SPI_L_TO_H |SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
init_7219(); // Initialize MAX7219 Value
hrh =0;
hrl =0;
minh=0;
minl=0;
write_time(hrh,hrl,minh,minl);
while(1)
{
// turn off test mode
output_low(max_load); // set load line LOW
spi_write(0x0C); // shutdown register
spi_write(0x01); // normal operation
output_high(max_load); // set load line high
ds1307_read_date_time();
// Get these into variables with shorter names, so I can
// put them into printf more easily.
sec = gca_ds1307_regs[DS1307_SECONDS_REG];
min = gca_ds1307_regs[DS1307_MINUTES_REG];
hrs = gca_ds1307_regs[DS1307_HOURS_REG];
day = gca_ds1307_regs[DS1307_DAY_OF_WEEK_REG];
date = gca_ds1307_regs[DS1307_DATE_REG];
month = gca_ds1307_regs[DS1307_MONTH_REG];
yr = gca_ds1307_regs[DS1307_YEAR_REG];
write_time(hrh,hrl,minh,minl);
}
}
|
And here is my include file max7219_ds1307.c
Code: | ////////////////////////////////////////////////////////////////////////////
//// max7219_ds1307.C ////
//// Driver for Max7219 (8-bit 7-segment display ////
//// ////
//// init_7219() Must be called before any other function. ////
//// ////
//// write_dig(a,b,c,d) Will write the number (char) to digit 1-4 ////
//// The following have special meaning: ////
//// hrh = 1st digit ////
//// hrl = 2nd digit ////
//// minh = 3rd digit ////
//// minl = 4th digit ////
//// ** Digits are order from left to right ////
//// ////
////
////////////////////////////////////////////////////////////////////////////
#define max_clk pin_c3 // set pin clock is using
#define max_din pin_c5 // set pin data in is using
#define max_load pin_c0 // set pin load/cs is using
void init_7219()
{
// set number of LED displays to use
output_low(max_load); // set load line LOW
spi_write(0x1B); // point to the Scan Register
spi_write(0x03); // send 4, (Four LED Displays 0-3)
output_high(max_load); // set load line high
// set LED intensity to 50%
output_low(max_load); // set load line LOW
spi_write(0x1A); // point to the Intensity Register
spi_write(0x05); // send 5, (LED 50% brightness)
output_high(max_load); // set load line high
// set BCD Decoding
output_low(max_load); // set load line LOW
spi_write(0x19); // point to Decode Mode Register
spi_write(0x0F); // decode LED 0 - 3
output_high(max_load); // set load line high
}
void write_time(unsigned char hrh,unsigned char hrl, unsigned char minh, unsigned char minl)
{
// dig1
output_low(max_load); // set load line LOW
spi_write(0x01); // point to LED (0) Register
spi_write(hrh); // send '1'
output_high(max_load);
// dig2
output_low(max_load); // set load line LOW
spi_write(0x02); // point to LED (0) Register
spi_write(hrl); // send '1'
output_high(max_load);
// dig3
output_low(max_load); // set load line LOW
spi_write(0x03); // point to LED (0) Register
spi_write(minh); // send '7'
output_high(max_load);
// dig4
output_low(max_load); // set load line LOW
spi_write(0x04); // point to LED (0) Register
spi_write(minl); // send '7'
output_high(max_load);
delay_ms(4);
}
|
|
|
|
Guest
|
|
Posted: Thu Sep 01, 2005 7:11 am |
|
|
Can not display the hour and minutes digits into 7-segment.
My questions are:
1. I can not initialize both of the ds1307 and max7219, I think they are
conflict when I run the init_7219(); and the init_ds1307();
in my main code because both use the RC3, RC4 pins.
2. I can not think of a way to single out the following min into minh
and minl, and single out the hrs into hrh and hrl so I can display
their individual digit into their proper location on the 7-segments.
Quote: | min = gca_ds1307_regs[DS1307_MINUTES_REG];
hrs = gca_ds1307_regs[DS1307_HOURS_REG]; |
I would be great appreciate if anyone can help.
I welcome any input or suggestion..
Thanks...........
Here is my main.c code
Code: | ////////////////////////////////////////////////////////////////////////////////
//
// The LOAD/CS of the MAX7219 was LOW Active
//
//
////////////////////////////////////////////////////////////////////////////////
#include <18F452.h>
#device ADC=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
//#use i2c(Master, SDA=PIN_B7, SCL=PIN_B6)
#use i2c(Master, SDA=PIN_B4, SCL=PIN_B3)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
//#use i2c(Master, SDA=PIN_B7, SCL=PIN_B6)
#use i2c(Master, SDA=PIN_c4, SCL=PIN_c3)
#include <max7219_ds1307.c>
#include <ds1307.c>
unsigned char hrh,hrl,minh,minl;
void init_ds1307()
{
// Put some date and time values into the global date & time array.
gca_ds1307_regs[DS1307_SECONDS_REG] = 0; // 0 seconds
gca_ds1307_regs[DS1307_MINUTES_REG] = 14; // 10 minutes
gca_ds1307_regs[DS1307_HOURS_REG] = 8; // 8 AM
gca_ds1307_regs[DS1307_DAY_OF_WEEK_REG]= 0; // Skip this.
gca_ds1307_regs[DS1307_DATE_REG] = 04; // 3 rd
gca_ds1307_regs[DS1307_MONTH_REG] = 01; // Jan
gca_ds1307_regs[DS1307_YEAR_REG] = 05; // 2005
// Write these values to the DS1307, for testing.
ds1307_set_date_time();
}
//********* Main Program Start Here **********/////
void main()
{
int second;
int minute;
int hours;
int dates;
int months;
int year;
char sec;
char min;
char hrs;
char day;
char date;
char month;
char yr;
init_ds1307();
setup_adc_ports( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
output_low(max_clk); // set clk line low
output_low(max_din); // set data line in low
output_high(max_load); // set load/cs line high
output_float(max_din); // set pin as input
setup_spi(SPI_MASTER|SPI_L_TO_H |SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
init_7219(); // Initialize MAX7219 Value
hrh =0;
hrl =0;
minh=0;
minl=0;
write_time(hrh,hrl,minh,minl);
while(1)
{
// turn off test mode
output_low(max_load); // set load line LOW
spi_write(0x0C); // shutdown register
spi_write(0x01); // normal operation
output_high(max_load); // set load line high
ds1307_read_date_time();
// Get these into variables with shorter names, so I can
// put them into printf more easily.
sec = gca_ds1307_regs[DS1307_SECONDS_REG];
min = gca_ds1307_regs[DS1307_MINUTES_REG];
hrs = gca_ds1307_regs[DS1307_HOURS_REG];
day = gca_ds1307_regs[DS1307_DAY_OF_WEEK_REG];
date = gca_ds1307_regs[DS1307_DATE_REG];
month = gca_ds1307_regs[DS1307_MONTH_REG];
yr = gca_ds1307_regs[DS1307_YEAR_REG];
write_time(hrh,hrl,minh,minl);
}
}
|
And here is my include file max7219_ds1307.c
Code: | ////////////////////////////////////////////////////////////////////////////
//// max7219_ds1307.C ////
//// Driver for Max7219 (8-bit 7-segment display ////
//// ////
//// init_7219() Must be called before any other function. ////
//// ////
//// write_dig(a,b,c,d) Will write the number (char) to digit 1-4 ////
//// The following have special meaning: ////
//// hrh = 1st digit ////
//// hrl = 2nd digit ////
//// minh = 3rd digit ////
//// minl = 4th digit ////
//// ** Digits are order from left to right ////
//// ////
////
////////////////////////////////////////////////////////////////////////////
#define max_clk pin_c3 // set pin clock is using
#define max_din pin_c5 // set pin data in is using
#define max_load pin_c0 // set pin load/cs is using
void init_7219()
{
// set number of LED displays to use
output_low(max_load); // set load line LOW
spi_write(0x1B); // point to the Scan Register
spi_write(0x03); // send 4, (Four LED Displays 0-3)
output_high(max_load); // set load line high
// set LED intensity to 50%
output_low(max_load); // set load line LOW
spi_write(0x1A); // point to the Intensity Register
spi_write(0x05); // send 5, (LED 50% brightness)
output_high(max_load); // set load line high
// set BCD Decoding
output_low(max_load); // set load line LOW
spi_write(0x19); // point to Decode Mode Register
spi_write(0x0F); // decode LED 0 - 3
output_high(max_load); // set load line high
}
void write_time(unsigned char hrh,unsigned char hrl, unsigned char minh, unsigned char minl)
{
// dig1
output_low(max_load); // set load line LOW
spi_write(0x01); // point to LED (0) Register
spi_write(hrh); // send '1'
output_high(max_load);
// dig2
output_low(max_load); // set load line LOW
spi_write(0x02); // point to LED (0) Register
spi_write(hrl); // send '1'
output_high(max_load);
// dig3
output_low(max_load); // set load line LOW
spi_write(0x03); // point to LED (0) Register
spi_write(minh); // send '7'
output_high(max_load);
// dig4
output_low(max_load); // set load line LOW
spi_write(0x04); // point to LED (0) Register
spi_write(minl); // send '7'
output_high(max_load);
delay_ms(4);
}
|
|
|
|
Guest
|
|
Posted: Thu Sep 01, 2005 7:12 am |
|
|
Can not display the hour and minutes digits into 7-segment.
My questions are:
1. I can not initialize both of the ds1307 and max7219, I think they are
conflict when I run the init_7219(); and the init_ds1307();
in my main code because both use the RC3, RC4 pins.
2. I can not think of a way to single out the following min into minh
and minl, and single out the hrs into hrh and hrl so I can display
their individual digit into their proper location on the 7-segments.
Quote: | min = gca_ds1307_regs[DS1307_MINUTES_REG];
hrs = gca_ds1307_regs[DS1307_HOURS_REG]; |
I would be great appreciate if anyone can help.
I welcome any input or suggestion..
Thanks...........
Here is my main.c code
Code: | ////////////////////////////////////////////////////////////////////////////////
//
// The LOAD/CS of the MAX7219 was LOW Active
//
//
////////////////////////////////////////////////////////////////////////////////
#include <18F452.h>
#device ADC=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
//#use i2c(Master, SDA=PIN_B7, SCL=PIN_B6)
#use i2c(Master, SDA=PIN_c4, SCL=PIN_c3)
#include <max7219_ds1307.c>
#include <ds1307.c>
unsigned char hrh,hrl,minh,minl;
void init_ds1307()
{
// Put some date and time values into the global date & time array.
gca_ds1307_regs[DS1307_SECONDS_REG] = 0; // 0 seconds
gca_ds1307_regs[DS1307_MINUTES_REG] = 14; // 10 minutes
gca_ds1307_regs[DS1307_HOURS_REG] = 8; // 8 AM
gca_ds1307_regs[DS1307_DAY_OF_WEEK_REG]= 0; // Skip this.
gca_ds1307_regs[DS1307_DATE_REG] = 04; // 3 rd
gca_ds1307_regs[DS1307_MONTH_REG] = 01; // Jan
gca_ds1307_regs[DS1307_YEAR_REG] = 05; // 2005
// Write these values to the DS1307, for testing.
ds1307_set_date_time();
}
//********* Main Program Start Here **********/////
void main()
{
int second;
int minute;
int hours;
int dates;
int months;
int year;
char sec;
char min;
char hrs;
char day;
char date;
char month;
char yr;
init_ds1307();
setup_adc_ports( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
output_low(max_clk); // set clk line low
output_low(max_din); // set data line in low
output_high(max_load); // set load/cs line high
output_float(max_din); // set pin as input
setup_spi(SPI_MASTER|SPI_L_TO_H |SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
init_7219(); // Initialize MAX7219 Value
hrh =0;
hrl =0;
minh=0;
minl=0;
write_time(hrh,hrl,minh,minl);
while(1)
{
// turn off test mode
output_low(max_load); // set load line LOW
spi_write(0x0C); // shutdown register
spi_write(0x01); // normal operation
output_high(max_load); // set load line high
ds1307_read_date_time();
// Get these into variables with shorter names, so I can
// put them into printf more easily.
sec = gca_ds1307_regs[DS1307_SECONDS_REG];
min = gca_ds1307_regs[DS1307_MINUTES_REG];
hrs = gca_ds1307_regs[DS1307_HOURS_REG];
day = gca_ds1307_regs[DS1307_DAY_OF_WEEK_REG];
date = gca_ds1307_regs[DS1307_DATE_REG];
month = gca_ds1307_regs[DS1307_MONTH_REG];
yr = gca_ds1307_regs[DS1307_YEAR_REG];
write_time(hrh,hrl,minh,minl);
}
}
|
And here is my include file max7219_ds1307.c
Code: | ////////////////////////////////////////////////////////////////////////////
//// max7219_ds1307.C ////
//// Driver for Max7219 (8-bit 7-segment display ////
//// ////
//// init_7219() Must be called before any other function. ////
//// ////
//// write_dig(a,b,c,d) Will write the number (char) to digit 1-4 ////
//// The following have special meaning: ////
//// hrh = 1st digit ////
//// hrl = 2nd digit ////
//// minh = 3rd digit ////
//// minl = 4th digit ////
//// ** Digits are order from left to right ////
//// ////
////
////////////////////////////////////////////////////////////////////////////
#define max_clk pin_c3 // set pin clock is using
#define max_din pin_c5 // set pin data in is using
#define max_load pin_c0 // set pin load/cs is using
void init_7219()
{
// set number of LED displays to use
output_low(max_load); // set load line LOW
spi_write(0x1B); // point to the Scan Register
spi_write(0x03); // send 4, (Four LED Displays 0-3)
output_high(max_load); // set load line high
// set LED intensity to 50%
output_low(max_load); // set load line LOW
spi_write(0x1A); // point to the Intensity Register
spi_write(0x05); // send 5, (LED 50% brightness)
output_high(max_load); // set load line high
// set BCD Decoding
output_low(max_load); // set load line LOW
spi_write(0x19); // point to Decode Mode Register
spi_write(0x0F); // decode LED 0 - 3
output_high(max_load); // set load line high
}
void write_time(unsigned char hrh,unsigned char hrl, unsigned char minh, unsigned char minl)
{
// dig1
output_low(max_load); // set load line LOW
spi_write(0x01); // point to LED (0) Register
spi_write(hrh); // send '1'
output_high(max_load);
// dig2
output_low(max_load); // set load line LOW
spi_write(0x02); // point to LED (0) Register
spi_write(hrl); // send '1'
output_high(max_load);
// dig3
output_low(max_load); // set load line LOW
spi_write(0x03); // point to LED (0) Register
spi_write(minh); // send '7'
output_high(max_load);
// dig4
output_low(max_load); // set load line LOW
spi_write(0x04); // point to LED (0) Register
spi_write(minl); // send '7'
output_high(max_load);
delay_ms(4);
}
|
|
|
|
Guest
|
|
Posted: Thu Sep 01, 2005 7:16 am |
|
|
I am sorry for the tripple post, every time I click the submit button, it
show an error, I thought it did not successful, so I did click it 3 times and it display the same message 3 times.
Sorry. |
|
|
|
|
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
|