View previous topic :: View next topic |
Author |
Message |
engineer_er
Joined: 10 Feb 2014 Posts: 1
|
74hc165 read problem |
Posted: Mon Feb 10, 2014 3:19 pm |
|
|
Hi! I'm new CCS C and shift registers. I'd like to read a keyboard's button value. [img=http://s10.postimg.org/k32mxm3dx/new.jpg] For example , if 6. button was on, "6. button selected" will be right on lcd. I coded something but every time, I see 0 (zero). Help me please.
PS: for schmea download https://www.dropbox.com/s/7byeyh5y9l4kojh/my_circuit.DSN
Code: | #include <16f877a.h>
#use delay(clock=4000000)
#include "74165.c"
#include "lcd.c"
int8 say;
void main()
{
lcd_init();
while (2) {
read_expanded_inputs(say);
printf(lcd_putc,"\f %d ",say);
delay_ms(500);
}
} |
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Mon Feb 10, 2014 4:31 pm |
|
|
You need pull up resistors on all '165 inputs then switches connect to GND.
(Or the other way up if you wish.)
Read '165 data sheet, it will tell you how to :-
1) Load the switch data into the '165.
2) Clock the data through the shift register.
So you write PIC code to:-
a) Load the switch data.
b) Shift the data.
c) Repeat (b) once for each switch.
d) Repeat from (a) fast enough not to miss any key presses.
At this stage you should be able to see data coming out of the serial output pins of the '165 on a 'scope.
Next stage, get the PIC to decipher the data from the serial output, and deal with switch de-bounce.
Then send data to LCD.
Job done
Mike |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Mon Feb 10, 2014 6:49 pm |
|
|
The expanded input function was declared as:
void read_expanded_inputs(BYTE *ei)
hence to call it you must use the '&' character in order to point to "the address of"
read_expanded_inputs(&say);
hth, _________________ Humber |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Feb 10, 2014 7:19 pm |
|
|
also..
be sure to add a delay_ms(500); before the lcd Init call. This will ensure the LCD module gets 'organized' before you access it.
also
be sure the PIC and LCD are running! The simple '1Hz flashing LED' and LCD 'hello World' programs should be confirmed working before trying to code and debug the 165/keys program.
hth
jay |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Feb 11, 2014 4:06 pm |
|
|
Sorry I assumed you were wanting to create driver code from scratch.
I've had another look at your schematic, and noticed you've also left all the spare inputs floating.
You should tie these to either GND or VCC.
Failure to do this can create all sorts of problems.
Mike |
|
|
|