![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
ekocakaya
Joined: 13 Aug 2006 Posts: 12
|
74165 IC Problem Help Me |
Posted: Sun Aug 27, 2006 11:51 pm |
|
|
My problem is the circuit is ok but I cant read 32 bit value.In my circuit there is 32 button.system is giving +5V to 74165 input pins .When you push the button low the its pin then system will flash led as the number of pin . The system is now working ramdomly when I push button 2 its is flashing 2 times than I push button 3 it is again flashing 2 times.Where is problem can you help me?
Code: |
#include <18F4620.h>
#fuses NOWDT,INTRC_IO, NOPUT, NOMCLR, BROWNOUT, NOCPD, NOWRT, NODEBUG, NOPROTECT, FCMEN, IESO,NOLVP
#define OSC_4MHZ | OSC_INTRC
#use delay(clock=4000000)
#define EXP_IN_ENABLE PIN_C5
#define EXP_IN_CLOCK PIN_C6
#define EXP_IN_DI PIN_C7
#define NUMBER_OF_74165 4
#define high_start 15
byte seconds, high_count;
byte dakika=0,saat=0;
int32 ei;
void read_expanded_inputs(int32 *ei)
{
BYTE i;
output_high(EXP_IN_CLOCK);
output_low(EXP_IN_ENABLE); // Latch all inputs
output_high(EXP_IN_ENABLE);
for(i=1;i<=NUMBER_OF_74165*8;++i)
{
shift_left(ei,NUMBER_OF_74165,input(EXP_IN_DI));
output_low(EXP_IN_CLOCK);
output_high(EXP_IN_CLOCK);
}
output_low(EXP_IN_ENABLE);
}
void main()
{
byte value=0,a;
int i;
do
{
read_expanded_inputs(&ei);
for(i=0;i<=7;i++)
{
read_expanded_inputs(&ei);
delay_ms(500);
value = bit_test (ei,i);
if(value==0)
{
OUTPUT_HIGH(PIN_D4);
for(a=0;a<i;a++)
{
OUTPUT_HIGH(PIN_B6);
delay_ms(500);
OUTPUT_LOW(PIN_B6);
delay_ms(500);
}
if(value==1)
OUTPUT_LOW(PIN_D4);
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Aug 28, 2006 8:27 am |
|
|
Don't use your function. Use the standard read_expanded_inputs from
the 74165.c file in the drivers subdirectory. In your function you tell it
that the address is pointing to an int32. If you use yours, the address is
incr by 4 each time. But you really only wanted incr by 1.
Your int32 ie; is just fine. And you pass the address fine also.
Code: | #include <18F4620.h>
#fuses NOWDT,INTRC_IO, NOPUT, NOMCLR, BROWNOUT, NOCPD, NOWRT, NODEBUG, NOPROTECT, FCMEN, IESO,NOLVP
#define OSC_4MHZ | OSC_INTRC
#use delay(clock=4000000)
#define EXP_IN_ENABLE PIN_C5
#define EXP_IN_CLOCK PIN_C6
#define EXP_IN_DI PIN_C7
#define NUMBER_OF_74165 4
#define high_start 15
#include <74165.c>
byte seconds, high_count;
byte dakika=0,saat=0;
int32 ei;
void main()
{
byte value=0,a;
int i;
while(1){
read_expanded_inputs(&ei);
delay_ms(500);
for(i=0;i<=7;i++){
if(bit_test (ei,i)){
OUTPUT_HIGH(PIN_D4);
for(a=0;a<i;a++){
OUTPUT_HIGH(PIN_B6);
delay_ms(500);
OUTPUT_LOW(PIN_B6);
delay_ms(500);
}
}
else{
OUTPUT_LOW(PIN_D4);
}
}
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
ekocakaya
Joined: 13 Aug 2006 Posts: 12
|
|
Posted: Mon Aug 28, 2006 9:20 am |
|
|
Dear Sir,
If I want to read 32 bit one by one. what I must do? changing for(.. <32) is enough? |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Aug 28, 2006 9:28 am |
|
|
I don't understand what you mean.
Quote: | 32 bit one by one. |
The #define NUMBER_OF_74165 4
tells the function your reading 4 bytes.. that is how it gets the int32.
You must serially read all 4 bytes.
Then check the status of bit. |
|
![](templates/subSilver/images/spacer.gif) |
ekocakaya
Joined: 13 Aug 2006 Posts: 12
|
|
Posted: Mon Aug 28, 2006 10:44 am |
|
|
Dear Sir,
I want to read 32 bit and using four 74165.I have 32 button and each button is connected to 74165s .when ı change the code like below will it be correct?
Code: |
void main()
{
byte value=0,a;
int i;
while(1){
read_expanded_inputs(&ei);
delay_ms(500);
for(i=0;i<=31;i++){
if(bit_test (ei,i)){
OUTPUT_HIGH(PIN_D4);
for(a=0;a<i;a++){
OUTPUT_HIGH(PIN_B6);
delay_ms(500);
OUTPUT_LOW(PIN_B6);
delay_ms(500);
}
}
else{
OUTPUT_LOW(PIN_D4);
}
}
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Aug 28, 2006 1:07 pm |
|
|
Yes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|