djc
Advanced Member level 1
- Joined
- Jan 27, 2013
- Messages
- 402
- Helped
- 3
- Reputation
- 6
- Reaction score
- 2
- Trophy points
- 1,298
- Location
- India
- Activity points
- 4,554
Hi,
I have a hardware.It operates as exchange.I have no schematic, direct hardware.It has one controller ATMEGA8, 4 74HC589, 4 74HC595,one CD4515 and one cross point switch IC 8816. Regarding connections (SCK),pin 11 from 74HC589 is connected to micro controller PIN 17.(RCK),PIN 12 from 74HC589 is connected to micro controller PIN 18.(SLOAD), PIN 13 from 74HC589 is connected to PIN 19 of micro controller.Serial input pin of 74HC589 i.e. PIN 14 has no connection. (OE)PIN is connected to CD4515 line decoder.First latch clock i.e RCK pin is made high to low, then SLOAD pin is made low to high and then SCK pin is made high to low 8 times to get 8 output bits serially.
There are 4 such 74HC589 and 4 such 74HC595. Each of the output enable pin i.e (OE) pin of 74HC589 and 74HC595 are connected to CD4515 line decoder output. Now there are A,B,C,D as 4 inputs on CD4515 which are connected to micro controller's PIN 2,3,5 and 6. CD4515 decoder inhibit pin is connected to Micro controller's PORTD_2. I have made it logical '0' as mentioned in datasheet.
Now by using various combinations on A,B,C,D input of CD4515 various outputs could be selected as selected output will give logical '0' and will enable particular 74HC589 or particular 74HC595. Now switches are connected on all 4 74hc589 on first 4 parallel inputs i.e. a,b,c,d and opto coupler on rest of the parallel inputs. And LED's and Relays are connected to 74HC595 parallel outputs.
Initially i had to detect the key press, which are connected on 74hc589.When key is pressed output of 589 is logical '0'. Which i detected. Now when key is pressed once led should glow and when pressed 2nd time LED should be OFF. Issue i am facing is if key is continuously pressed then LED is continuously ON and OFF i.e. blinking.My code is as below,
Here it is not sure that when key is released what will be its status, whether it will be ON or OFF. While loop doesn't work as when key is pressed it doesn't come out of that loop. Can somebody please guide.
I have a hardware.It operates as exchange.I have no schematic, direct hardware.It has one controller ATMEGA8, 4 74HC589, 4 74HC595,one CD4515 and one cross point switch IC 8816. Regarding connections (SCK),pin 11 from 74HC589 is connected to micro controller PIN 17.(RCK),PIN 12 from 74HC589 is connected to micro controller PIN 18.(SLOAD), PIN 13 from 74HC589 is connected to PIN 19 of micro controller.Serial input pin of 74HC589 i.e. PIN 14 has no connection. (OE)PIN is connected to CD4515 line decoder.First latch clock i.e RCK pin is made high to low, then SLOAD pin is made low to high and then SCK pin is made high to low 8 times to get 8 output bits serially.
There are 4 such 74HC589 and 4 such 74HC595. Each of the output enable pin i.e (OE) pin of 74HC589 and 74HC595 are connected to CD4515 line decoder output. Now there are A,B,C,D as 4 inputs on CD4515 which are connected to micro controller's PIN 2,3,5 and 6. CD4515 decoder inhibit pin is connected to Micro controller's PORTD_2. I have made it logical '0' as mentioned in datasheet.
Now by using various combinations on A,B,C,D input of CD4515 various outputs could be selected as selected output will give logical '0' and will enable particular 74HC589 or particular 74HC595. Now switches are connected on all 4 74hc589 on first 4 parallel inputs i.e. a,b,c,d and opto coupler on rest of the parallel inputs. And LED's and Relays are connected to 74HC595 parallel outputs.
Initially i had to detect the key press, which are connected on 74hc589.When key is pressed output of 589 is logical '0'. Which i detected. Now when key is pressed once led should glow and when pressed 2nd time LED should be OFF. Issue i am facing is if key is continuously pressed then LED is continuously ON and OFF i.e. blinking.My code is as below,
Code:
#include <mega8.h>
#include <delay.h>
#define A PORTD.1 //right
#define B PORTD.0
#define D PORTD.3
#define C PORTD.4
#define decoder_inhibit PORTD.2
#define par_sck PORTB.3
#define par_rck PORTB.4
#define par_out PINB.0
#define par_sload PORTB.5
#define ser_shcp PORTB.4
#define ser_stcp PORTB.3
#define ser_ds PORTB.2
#define test PORTD.5
//#define test_1 PORTD.7
#define delay_1 20
#define delay_2 30
unsigned char key_status[9],binaryNumber[10];
//bit i_5=1,i_6=1,i_7=1,i_8=1;
int i=0,j=0,a=0,m=0,key_1=0,key_2=0,key_3=0,key_4=0,key_status_1=0,key_status_2=0,key_status_3=0,key_status_4=0;
unsigned int final_1,final_2,final_3,final_4,m_1,m_2,m_3,m_4,m_5,m_6,m_7,m_8,m_9,m_10,m_11,m_12;
unsigned int key_5,key_6,key_7,key_8,key_status_5,key_status_6,key_status_7,key_status_8;
unsigned int key_9,key_10,key_11,key_12,key_status_9,key_status_10,key_status_11,key_status_12;
unsigned int key_13,key_14,key_15,key_16,key_status_13,key_status_14,key_status_15,key_status_16;
bit IC_1=0,IC_2,IC_3,IC_4;
void LED_display(unsigned int data) //Function to convert decimal to binary
{
//
i=1;
for(k=0;k<=8;k++){
binaryNumber[i++]= data % 2;
data = data / 2;
//Data_DS = binaryNumber[i];
}
for(j = i-1;j> 0;j--){
ser_ds = binaryNumber[j];
ser_shcp = 1;
//delay_us(1);
ser_shcp = 0;
//delay_us(1);
}
ser_stcp = 1;
//delay_us(1);
ser_stcp = 0;
delay_us(1000);
}
void main(void)
{
PORTB=0x00;
DDRB=0xFE;
// Port C initialization
PORTC=0x00;
DDRC=0x00;
// Port D initialization
PORTD=0x00;
DDRD=0xFF;
while (1)
{
// Place your code here
j=0,i=0;
A = 0; //1st parallel IC
B = 0;
C = 1;
D = 0;
par_rck = 1;
delay_us(2);
par_rck = 0;
par_sload = 0;
delay_us(2);
par_sload = 1;
par_sck = 1; //G Q6
//delay_ms(2);
#asm("nop")
par_sck = 0;
par_sck = 1; //F Q5
//delay_ms(2);
#asm("nop")
par_sck = 0;
par_sck = 1; //E Q4
//delay_ms(2);
#asm("nop")
par_sck = 0;
par_sck = 1; //D Q3
//delay_ms(2);
#asm("nop")
par_sck = 0;
if(par_out==1){
//key_status[4]=1;
}
else{
//key_status[4]=0;
delay_us(1);
key_4++;
}
if(key_4==1){
m_4=0;
while(m_4<=delay_1){
key_status_4=1;
m_4++;
}
}
if(key_4==2){
m_4=0;
while(m_4<=delay_2){
key_status_4=0;
m_4++;
}
key_4=0;
}
par_sck = 1; //C Q2
//delay_ms(2);
#asm("nop")
par_sck = 0;
if(par_out==1){
key_status[5]=1;
}
else{
key_status[5]=0;
delay_us(1);
key_3++;
}
if(key_3==1){
m_3=0;
while(m_3<=delay_1){
key_status_3=1;
m_3++;
}
}
if(key_3==2){
m_3=0;
while(m_3<=delay_2){
key_status_3=0;
m_3++;
}
key_3=0;
}
par_sck = 1; //B Q1
//delay_ms(2);
#asm("nop")
par_sck = 0;
if(par_out==1){
key_status[6]=1;
}
else{
//key_status[6]=0;
delay_us(1);
key_2++;
}
if(key_2==1){
m_2=0;
while(m_2<=delay_1){
key_status_2=1;
m_2++;
}
}
if(key_2==2){
m_2=0;
delay_ms(1);
while(m_2<=delay_2){
key_status_2=0;
m_2++;
}
key_2=0;
}
par_sck = 1; //A Q0
//delay_ms(2);
#asm("nop")
par_sck = 0;
if(par_out==1){
key_status[7]=1;
}
else {
key_1++;m_1++;
}
if(key_1==50 ){
key_status_1=1;;
m_1=0;
key_1=0;
}
if(key_1==1){
m_1=0;
while(m_1<=delay_1){
key_status_1=1;
m_1++;
}
}
if(key_1==2){
m_1=0;
while(m_1<=delay_2){
key_status_1=0;
m_1++;
}
key_1=0;
}
final_1 = (128*0+64*0+32*0+16*0+8*key_status_4+4*key_status_3+2*key_status_2+1*key_status_1);
A = 1;
B = 0;
C = 1;
D = 0;
IC_1=1;
LED_display(final_1);
}
}
Here it is not sure that when key is released what will be its status, whether it will be ON or OFF. While loop doesn't work as when key is pressed it doesn't come out of that loop. Can somebody please guide.