|
|
View previous topic :: View next topic |
Author |
Message |
sshahryiar
Joined: 05 May 2010 Posts: 94 Location: Dhaka, Bangladesh
|
Library for MAX7219 and MAX7221 SPI LED Display Driver IC |
Posted: Sat Nov 29, 2014 11:28 am |
|
|
MAX72xx.h
Code: |
#define DIN pin_A1
#define CS pin_A2
#define CLK pin_A4
#define NOP 0x00
#define DIG0 0x01
#define DIG1 0x02
#define DIG2 0x03
#define DIG3 0x04
#define DIG4 0x05
#define DIG5 0x06
#define DIG6 0x07
#define DIG7 0x08
#define decode_mode_reg 0x09
#define intensity_reg 0x0A
#define scan_limit_reg 0x0B
#define shutdown_reg 0x0C
#define display_test_reg 0x0F
#define shutdown_cmd 0x00
#define run_cmd 0x01
#define no_test_cmd 0x00
#define test_cmd 0x01
#define digit_0_only 0x00
#define digit_0_to_1 0x01
#define digit_0_to_2 0x02
#define digit_0_to_3 0x03
#define digit_0_to_4 0x04
#define digit_0_to_5 0x05
#define digit_0_to_6 0x06
#define digit_0_to_7 0x07
#define No_decode_for_all 0x00
#define Code_B_decode_digit_0 0x01
#define Code_B_decode_digit_0_to_3 0x0F
#define Code_B_decode_for_all 0xFF
void MAX72xx_init();
void MAX72xx_write(unsigned char address, unsigned char value);
|
MAX72xx.c
Code: |
#include "MAX72xx.h"
void MAX72xx_init()
{
output_high(CS);
MAX72xx_write(shutdown_reg, run_cmd);
MAX72xx_write(decode_mode_reg, No_decode_for_all);
MAX72xx_write(scan_limit_reg, digit_0_to_7);
MAX72xx_write(intensity_reg, 0x04);
MAX72xx_write(display_test_reg, test_cmd);
delay_ms(100);
MAX72xx_write(display_test_reg, no_test_cmd);
}
void MAX72xx_write(unsigned char address, unsigned char value)
{
unsigned char s = 0;
unsigned long data_word = 0;
data_word = (((unsigned long)address << 8) | value);
output_low(CS);
for(s = 0; s < 16; s += 1)
{
if((data_word & 0x8000) != 0)
{
output_high(DIN);
}
else
{
output_low(DIN);
}
output_low(CLK);
delay_ms(1);
output_high(CLK);
data_word <<= 1;
}
output_high(CS);
}
|
_________________ https://www.facebook.com/MicroArena
SShahryiar |
|
|
tedibear
Joined: 03 Mar 2015 Posts: 2
|
gggg |
Posted: Tue Mar 03, 2015 2:05 am |
|
|
Rica etsem örnek bir kod yazmanız mümkün mü?
Is it possible to write a sample code please? _________________ Nawaz |
|
|
sshahryiar
Joined: 05 May 2010 Posts: 94 Location: Dhaka, Bangladesh
|
Sample code |
Posted: Tue Mar 03, 2015 2:37 am |
|
|
Code: |
#include <12F675.h>
#device *=16
#device ADC = 8
#fuses INTRC_IO, PROTECT, CPD, PUT, NOBROWNOUT, NOWDT, NOMCLR
#use delay (internal=4MHz)
#define tilt_switch !input(pin_A3)
#include <stdlib.h>
#include "MAX72xx.c"
const unsigned char disp[56] =
{
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03,
0xC0, 0xC0, 0x00, 0x18, 0x18, 0x00, 0x03, 0x03,
0xC3, 0xC3, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xC3,
0xC3, 0xC3, 0x00, 0x18, 0x18, 0x00, 0xC3, 0xC3,
0xDB, 0xDB, 0x00, 0x00, 0x00, 0x00, 0xDB, 0xDB,
0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81
};
void setup();
void main()
{
unsigned char i = 0;
unsigned long j = 0; ;
unsigned char disp_adj = 0;
setup();
while(TRUE)
{
read_adc(adc_start_only);
while(!adc_done());
disp_adj = read_adc(adc_read_only);
disp_adj >>= 4;
MAX72xx_write(intensity_reg, disp_adj);
if(tilt_switch)
{
for(i = 0; i < 8; i++)
{
MAX72xx_write((i + 1), 0x00);
}
while(tilt_switch)
j = rand();
j /= 4681;
}
else
{
for(i = 0; i < 8; i++)
{
MAX72xx_write((i + 1), disp[((j << 3) + i)]);
}
}
}
}
void setup()
{
disable_interrupts(global);
setup_comparator(NC_NC_NC_NC);
setup_ADC(ADC_clock_internal);
setup_ADC_ports(sAN0);
set_ADC_channel(0);
setup_timer_0(T0_internal);
setup_timer_1(T1_disabled);
set_timer0(0);
set_timer1(0);
MAX72xx_init();
}
|
_________________ https://www.facebook.com/MicroArena
SShahryiar |
|
|
|
|
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
|