CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

74hc165 read problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
engineer_er



Joined: 10 Feb 2014
Posts: 1

View user's profile Send private message

74hc165 read problem
PostPosted: Mon Feb 10, 2014 3:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 10, 2014 4:31 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 10, 2014 6:49 pm     Reply with quote

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: 9178
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 10, 2014 7:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 11, 2014 4:06 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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