- Joined
- Jan 22, 2008
- Messages
- 52,432
- Helped
- 14,752
- Reputation
- 29,786
- Reaction score
- 14,106
- Trophy points
- 1,393
- Location
- Bochum, Germany
- Activity points
- 298,152
Thanks for the Reply. Then what is OE, Output Enable used for in 74HC595?
#include <avr/io.h>#include <util/delay.h>#include <avr/interrupt.h>#include <avr/pgmspace.h>#include <string.h>#include "font5x7.h"volatile PGM_P ptr=smallFont;
volatile uint16_t ii,iii;
//Message to displayvolatile char string[]="Welcome ! * Avinash Gupta * ";
volatile uint8_t len;
#define DISP_ROW_CNT 7#define DISP_COL_CNT 15/***************************************Configure Connections****************************************/#define HC595_PORT PORTB #define HC595_DDR DDRB#define HC595_DS_POS PB0#define HC595_SH_CP_POS PB1#define HC595_ST_CP_POS PB2/***************************************Configure Connections ***ENDS*******************************************/void HC595Init()
{
HC595_DDR|=((1<<HC595_SH_CP_POS)|(1<<HC595_ST_CP_POS)|(1<<HC595_DS_POS));
}
#define HC595DataHigh() (HC595_PORT|=(1<<HC595_DS_POS))#define HC595DataLow() (HC595_PORT&=(~(1<<HC595_DS_POS)))void HC595Pulse()
{
//Pulse the Shift Clock HC595_PORT|=(1<<HC595_SH_CP_POS);//HIGH HC595_PORT&=(~(1<<HC595_SH_CP_POS));//LOW}
void HC595Latch()
{
//Pulse the Store Clock HC595_PORT|=(1<<HC595_ST_CP_POS);//HIGH _delay_loop_1(1);
HC595_PORT&=(~(1<<HC595_ST_CP_POS));//LOW _delay_loop_1(1);
}
void SelectRow(uint8_t r)
{
DDRD|=(0B11110111);
PORTD&=(0B00001000);
switch(r)
{
case6:
PORTD|=(1<<PD0);
break;
case5:
PORTD|=(1<<PD1);
break;
case4:
PORTD|=(1<<PD2);
break;
case3:
PORTD|=(1<<PD4);
break;
case2:
PORTD|=(1<<PD5);
break;
case1:
PORTD|=(1<<PD6);
break;
case0:
PORTD|=(1<<PD7);
break;
}
}
void main()
{
// Prescaler = FCPU/256 TCCR0|=((1<<CS02));
//Enable Overflow Interrupt Enable TIMSK|=(1<<TOIE0);
//Initialize Counter TCNT0=0;
//Enable Global Interrupt sei();
//Init Shift Register HC595Init();
//Get Length of message len=strlen(string);
ii=iii=0;
while(1)
{
}
}
ISR(TIMER0_OVF_vect)
{
/* This interrup service routine (ISR) Updates the displays */static uint8_t row;
static uint16_t cnt=0;
cnt++;
//Handle Scrollingif(cnt == 29)
{
cnt =0;
ii++;
if(ii==5)
{
ii=0;
iii++;
if(iii>len)
iii=0;
}
return;
}
//Now Transfer a row of data int8_t col;
int8_t chr = iii;
int8_t m=ii;
for(col=0;col<DISP_COL_CNT;col++)
{
uint8_t data;
if(m!=5)
{
data=pgm_read_byte( ptr + ((string[chr]-' ')*5)+m);
}
else {
data=0x00;
}
if((data & (1<<row)))
HC595DataHigh();
else HC595DataLow();
HC595Pulse();
m++;
if(m==6)
{
chr++;
m=0;
if(chr >=len)
chr=0;
}
}
//Acivate a row according to 'row' SelectRow(row);
HC595Latch();
row++;
if(row==DISP_ROW_CNT)
{
//If on last row then come//back to first. row=0;
}
#define F_CPU 20000000UL
#include <avr/io.h>
#include <util/delay.h>
/***************************************
Configure Connections
****************************************/
#define HC595_PORT PORTB
#define HC595_DDR DDRB
#define HC595_DS_POS PB0 //Data pin (DS) pin location
#define HC595_SH_CP_POS PB1 //Shift Clock (SH_CP) pin location
#define HC595_ST_CP_POS PB2 //Store Clock (ST_CP) pin location
/***************************************
Configure Connections ***ENDS***
****************************************/
//Initialize HC595 System
void HC595Init()
{
//Make the Data(DS), Shift clock (SH_CP), Store Clock (ST_CP) lines output
HC595_DDR|=((1<<HC595_SH_CP_POS)|(1<<HC595_ST_CP_POS)|(1<<HC595_DS_POS));
}
//Low level macros to change data (DS)lines
#define HC595DataHigh() (HC595_PORT|=(1<<HC595_DS_POS))
#define HC595DataLow() (HC595_PORT&=(~(1<<HC595_DS_POS)))
//Sends a clock pulse on SH_CP line
void HC595Pulse()
{
//Pulse the Shift Clock
HC595_PORT|=(1<<HC595_SH_CP_POS);//HIGH
HC595_PORT&=(~(1<<HC595_SH_CP_POS));//LOW
}
//Sends a clock pulse on ST_CP line
void HC595Latch()
{
//Pulse the Store Clock
HC595_PORT|=(1<<HC595_ST_CP_POS);//HIGH
_delay_loop_1(1);
HC595_PORT&=(~(1<<HC595_ST_CP_POS));//LOW
_delay_loop_1(1);
}
/*
Main High level function to write a single byte to
Output shift register 74HC595.
Arguments:
single byte to write to the 74HC595 IC
Returns:
NONE
Description:
The byte is serially transfered to 74HC595
and then latched. The byte is then available on
output line Q0 to Q7 of the HC595 IC.
*/
void HC595Write(uint8_t data)
{
//Send each 8 bits serially
//Order is MSB first
for(uint8_t i=0;i<8;i++)
{
//Output the data on DS line according to the
//Value of MSB
if(data & 0b10000000)
{
//MSB is 1 so output high
HC595DataHigh();
}
else
{
//MSB is 0 so output high
HC595DataLow();
}
HC595Pulse(); //Pulse the Clock line
data=data<<1; //Now bring next bit at MSB position
}
//Now all 8 bits have been transferred to shift register
//Move them to output latch at one
HC595Latch();
}
/*
Simple Delay function approx 0.5 seconds
*/
void Wait()
{
for(uint8_t i=0;i<30;i++)
{
_delay_loop_2(0);
}
}
int main()
{
uint8_t led_pattern[29]={
0b00001110,
0b00010001,
0b00011111,
0b00010001,
0b00010001,
0b00000000,
0b00011110,
0b00010001,
0b00011110,
0b00010001,
0b00011110,
0b00000000,
0b00001110,
0b00010001,
0b00010000,
0b00010001,
0b00001110,
0b00000000,
0b00011110,
0b00010001,
0b00010001,
0b00010001,
0b00011110,
0b00000000,
0b00011111,
0b00010000,
0b00011110,
0b00010000,
0b00011111,
};
//Initialize HC595 system
HC595Init();
DDRA=0xFF;
PORTA=0;
int k,j;
while(1)
{
///**********i want to get from here simplified*********
for(uint8_t i=0;i<11;i++)
{
HC595Write(led_pattern[i]); //Write the data to HC595
j=i;
if(i>5){ j=i-6;}
if(i>11){ j=i-12;}
if(i>17){ j=i-18;}
if(i>23){ j=i-24;}
PORTA=(1<<j);
_delay_ms(0.2);
}
///**********till here*********
}
}
Thanks for the reply Gorgon, Sorry that i didn't mention to say the circuit is of Row scanning (Consisting 100 Led not 10). So, 100X20Ma=2A. Since ULN2003 have only a capacity of 500Ma, I thought of using it for 15 leds (15X20Ma=300Ma) like wise for whole 100 leds in series.
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?