Each hc595's output pin can drive 35 mA, so, we don't need to add ULN2803. And to drive 1A, we can use one TIP42 for each row.
Continuous current through VCC or GND ±70 mA
Each pin can give up to 35mA but the TOTAL current for all pins of the chip can't be more than 70mA
Continuous current through VCC or GND ±70 mA
#include <mega32.h>
// SPI functions
#include <spi.h>
#include <delay.h>
void spi_begin(void) {
// set /SS = low to select SPI slave device.
PORTB &= 0b11101111;
}
void spi_end(void) {
// set new data by /SS = high then Low,
PORTB |= 0b00010000;
PORTB |= 0b00000000;
}
void spi_send(char cData) {
SPDR = cData;
while(!(SPSR.7)) {
; // wait for SPIF flag to be set
}
}
// Declare your global variables here
flash unsigned char symbols[10][8]=
{
{0x3C,0x66,0x66,0x66,0x66,0x66,0x66,0x3C},
{0x1E,0x18,0x18,0x18,0x18,0x18,0x18,0x7E},
{0x3C,0x66,0x66,0x30,0x18,0xC,0x7E,0x76},
{0x7E,0x66,0x30,0x18,0x30,0x66,0x66,0x3C},
{0x30,0x38,0x34,0x34,0x36,0x7E,0x30,0x78},
{0x7E,0x66,0x6,0x3E,0x60,0x66,0x66,0x3C},
{0x3C,0x66,0x6,0x3E,0x66,0x66,0x66,0x3C},
{0x7E,0x66,0x66,0x30,0x30,0x18,0x18,0x18},
{0x3C,0x66,0x66,0x3C,0x66,0x66,0x66,0x3C},
{0x3C,0x66,0x66,0x66,0x7C,0x60,0x66,0x3C}
};
char ticker=0x01;
char row=0;
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// SPI transfer
spi_begin();
//sending column data
spi_send(symbols[2][row]);
//sending Row data; only one row is active at a time
spi_send(~ticker);
spi_end();
//selecting the next row
ticker=ticker<<1;
row++;
if(row==8){row=0;ticker=0x01;}
;
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0xff;
// Port B initialization
// Func7=Out Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=T State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xB2;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 921.600 kHz
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x02;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 0.977 kHz
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x05;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x1c;
OCR1AL=0x20;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x11;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 1843.200 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x50;
SPSR=0x00;
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
// setting port B; output = MOSI, SCK, /SS, PB1(/OE)
PORTB = 0;
};
}
After sending single row, then clear all HC595 output and disable all row before process next row.
---I assume it's kind of software glitch since it's not the whole leds
here's the code sample to display number 2 pattern ...
void spi_end(void)
// set new data by /SS = high [COLOR="#FF0000"]then Low[/COLOR],
PORTB |= 0b00010000; // high
[COLOR="#FF0000"]//PORTB |= 0b00000000; // this line does nothing !!! [/COLOR]
PORTB &= 0b11101111; // [COLOR="#FF0000"]low[/COLOR]
}
// setting port B; output = MOSI, SCK, /SS, PB1(/OE)
PORTB = 0;
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
};
} // end of main
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 #define time_to_on 0x08 #define time_to_off 0x02 //init timer TCCR1A=0x00; TCCR1B=0x0A; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x10; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; .. .. //scanning section for (c=0;c<8;c++) { for (a=0;a<56;a++) { b=buffer_data[a]; d=b>>c; if (d & 1) (sdata_1_a=0); else (sdata_1_a=1); hc595_clock_a=1; hc595_clock_a=0; }; e=0; while (e==0) e=TIFR; TIFR|=16; OCR1AH=time_to_on; row=c; e3_138=1; //138 is enabled hc595_strobe_a=1; hc595_strobe_a=0; e=0; while (e==0) e=TIFR; TIFR|=16; OCR1AH=time_to_off; hc595_reset=0;//you can use these two lines or not. hc595_reset=1; e3_138=0; //138 is disabled };
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?