Microcontroller › AVR › how to interface 74hc595 with ATMEGA 16
- This topic has 3 replies, 3 voices, and was last updated 6 years, 4 months ago by Hari Prasaath K.
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
July 31, 2011 at 8:24 pm #1237kamran ullahParticipant
hi i am a computer engineering student and i want to interface the ic 74hc595 with my microcontroller(ATMEGA16) someone help me by giving me code or by making correction in my code
for input ( parallel to serial conversion ) used ic 74hc165for input ( serial to parallel conversion ) used ic 74hc595
// ***********************************************************// Project:// Author:// Module description:// ***********************************************************#include <avrio.h> // Most basic include files#include <avrinterrupt.h> // Add the necessary ones#include <avrsignal.h> // here#include<utildelay.h>int IN1,IN2,IN3,IN4,IN5,IN6,IN7,IN8;int x1,x2,x3,x4,x5,x6,x7,x8;void my_inputcode(void){// to transfer data enable clock//low to high transition is done//and clock is disabled//DDRD=0x00;//PORTD.4=0;// CP Clock//PORTD&=~(1<<PD4);//PORTD.5=1;// Clear CE Enable 15 cebar//PORTD|=(1<<PD5); //works on zero so one//PORTC.7=1;// PL Load 1 PLbar//PORTC|=(1<<PC7);//PORTC.7 = 0;// Load Data_delay_ms(10);PORTC&=~(1<<PC7);_delay_ms(10);// Serial Transfer ModePORTC|=(1<<PC7);_delay_ms(10);/enable clock pulses//PORTD&=~(1<<PD5);PORTD&=~(1<<PD4);_delay_ms(10);//
Bit 1
// making low to highPIND|=(1<<PD4);//PORTD|=(1<<PD4);_delay_ms(10);IN1=(PIND|=(1<<PD6));// Data Pin 01000000// Data Pin_delay_ms(10);// clock zeroPORTD&=~(1<<PD4);_delay_ms(10);//
Bit 2
PORTD|=(1<<PD4);_delay_ms(10);IN2=(PIND|=(1<<PD6));_delay_ms(10);PORTD&=~(1<<PD4);_delay_ms(10);//
Bit 3
PORTD|=(1<<PD4);_delay_ms(10);IN3=(PIND|=(1<<PD6));_delay_ms(10);PORTD&=~(1<<PD4);_delay_ms(10);//
Bit 4
PORTD|=(1<<PD4);_delay_ms(10);IN4=(PIND|=(1<<PD6));_delay_ms(10);PORTD&=~(1<<PD4);_delay_ms(10);//
Bit 5
PORTD|=(1<<PD4);_delay_ms(10);IN5=(PIND|=(1<<PD6));_delay_ms(10);PORTD&=~(1<<PD4);_delay_ms(10);//
Bit 6
//PORTD.4=1;PORTD|=(1<<PD4);_delay_ms(10);IN6=(PIND|=(1<<PD6));_delay_ms(10);PORTD&=~(1<<PD4);_delay_ms(10);//
Bit 7
PORTD|=(1<<PD4);_delay_ms(10);IN7=(PIND|=(1<<PD6));_delay_ms(10);PORTD&=~(1<<PD4);_delay_ms(10);//
Bit 8
PORTD|=(1<<PD4);_delay_ms(10);PIN8=(PIND|=(1<<PD6));_delay_ms(10);PORTD&=~(1<<PD4);_delay_ms(10);//
end
// sh/ld parallel loadPORTC|=(1<<PC7);//NIH clock enablePORTD|=(1<<PD5);}void my_outputcode(void){// output enable active low OEbar 13PORTC|=(1<<PC6);// Serial In. DS Serial Data input DS 14PORTC&=~(1<<PC3);// Serial Shift Register Clock. SH_CP 11PORTC&=~(1<<PC2); // shift register clock input// Shift Register Clear. MRbar 10// master reset active low..PORTC|=(1<<PC5);// Register Clock.// storage register clock input ST_CP 12PORTC&=~(1<<PC4);// 10 master reset (active low) MRbar 10PORTC&=~(1<<PC5);_delay_us(50);PORTC|=(1<<PC5);_delay_us(50);//
Bit 1
// 11 shift register clock input SH_CP 11PORTB&=~(1<<PB2);_delay_us(10);// 14 serial data input.. DS 14PORTB|=(1<<PB3);_delay_us(10);_delay_ms(2);// 11 shift register clock input SH_CP 11PORTB|=(1<<PB2);_delay_us(10);//
Bit 2
PORTC&=~(1<<PC2);_delay_us(10);PORTC&=~(1<<PC3);_delay_us(10);PORTC|=(1<<PC2);_delay_us(10);//
Bit 3
PORTC&=~(1<<PC2);_delay_us(10);(PORTC|(1<<PC3));_delay_us(10);PORTC|=(1<<PC2);_delay_us(10);//
Bit 4
PORTC&=~(1<<PC2);_delay_us(10);PORTC&=~(1<<PC3);_delay_us(10);PORTC|=(1<<PC2);_delay_us(10);//
Bit 5
PORTC&=~(1<<PC2);_delay_us(10);PORTC|=(1<<PC3);_delay_us(10);PORTC|=(1<<PC2);_delay_us(10);//
Bit 6
// First Error Exixst HerePORTC&=~(1<<PC2);//PORTC.2=0;_delay_us(10);PORTC&=~(1<<PC3);//PORTC.3=x6;_delay_us(10);PORTC|=(1<<PC2);//PORTC.2=1;_delay_us(10);//
Bit 7
PORTC&=~(1<<PC2);_delay_us(10);PORTC|=(1<<PC3);_delay_us(10);PORTC|=(1<<PC2);_delay_us(10);//
Bit 8
PORTC&=~(1<<PC2);_delay_us(10);PORTC&=~(1<<PC3);_delay_us(10);PORTC|=(1<<PC2);_delay_us(10);// Data Transfer to output.PORTC|=(1<<PC4);PORTC&=~(1<<PC6);}// ***********************************************************// Main program//int main(void){DDRD&=~(1<<PD6);DDRD|(1<<PD5)|(1<<PD4));DDRC=0XFF;while(1){my_inputcode();_delay_ms(30);// my_outputcode();}}its giving me some error and em not able to remove it…
July 28, 2017 at 5:39 pm #14637FarooghParticipantHI !
If you still interested in 74hc595 please telll me iam working on that using Atmega32A and Atmega8July 17, 2018 at 11:58 am #14860FarooghParticipantCan u tell me how to create a library of 74hc595
July 17, 2018 at 5:44 pm #14862Hari Prasaath KParticipantMention the errors your facing, whether during compilation or output error.
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.