Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

74ls165 & pic16f877

Status
Not open for further replies.

mesamune80

New Member
Hi all,

Any of you come a cross this 74LS165 with PIC,i am having a problem reading the bit send by this IC to my microcontroller..please comment about my code thanks.This is my code in PIC Simulator IDE (Basic format).

TRISB = %10000110
TRISC = 0
PORTB = 6

Dim b7 As Bit
Dim b6 As Bit
Dim b5 As Bit
Dim b4 As Bit
Dim b3 As Bit
Dim b2 As Bit
Dim b1 As Bit
Dim b0 As Bit


Low PORTB.1 'set clock low

High PORTB.4 'bring clock inhibit high

High PORTB.3 'bring shift/load high

start:

Gosub serial_in

If b7 = 1 Or b0 = 1 Then
Low PORTC.7
Low PORTC.6
Low PORTC.5
Low PORTC.4
Low PORTC.3
Low PORTC.2
Low PORTC.1
Low PORTC.0
Else
If b7 = 0 Or b0 = 0 Then
High PORTC.7
High PORTC.6
High PORTC.5
High PORTC.4
High PORTC.3
High PORTC.2
High PORTC.1
High PORTC.0
Endif
Endif
Goto start
End

serial_in:

High PORTB.3 'bring shift/load down momentarily
WaitUs 10
Low PORTB.3
WaitUs 10

Low PORTB.4 'bring clock inhibit low

b7 = PORTB.2 'load bit into B2

High PORTB.1 'Bring clock pin high then low
WaitUs 10
Low PORTB.1
WaitUs 10

b6 = PORTB.2 'load bit into B2

High PORTB.1 'Bring clock pin high then low
WaitUs 10
Low PORTB.1
WaitUs 10

b5 = PORTB.2 'load bit into B2

High PORTB.1 'Bring clock pin high then low
WaitUs 10
Low PORTB.1
WaitUs 10

b4 = PORTB.2 'load bit into B2

High PORTB.1 'Bring clock pin high then low
WaitUs 10
Low PORTB.1
WaitUs 10

b3 = PORTB.2 'load bit into B2

High PORTB.1 'Bring clock pin high then low
WaitUs 10
Low PORTB.1
WaitUs 10

b2 = PORTB.0 'load bit into B0

High PORTB.1 'Bring clock pin high then low
WaitUs 10
Low PORTB.1
WaitUs 10

b1 = PORTB.2 'load bit into B2

High PORTB.1 'Bring clock pin high then low
WaitUs 10
Low PORTB.1
WaitUs 10

b0 = PORTB.2 'load bit into B2

High PORTB.1 'Bring clock pin high then low
WaitUs 10
Low PORTB.1
WaitUs 10

Return
 
This code in C may or may not help


Code:
#define		SRPort		portb
#define		SRDataBit	1
#define		SRClockBit 	2





// =========== subroutine ==========
// 74HC/HCT164
void shiftOutByte( unsigned char aData ) {

	unsigned char ix;

	for( ix = 0; ix < 7; ix++ )   {
	
		if ( aData.1 ) {
			set_bit( SRPort, SRDataBit );
		} else {
			clear_bit( SRPort, SRDataBit );
		}
		
		clear_bit( SRPort, SRClockBit );   // edge triggered low to high 
		aData  >>= 1; // put here as delay 
		set_bit( SRPort, SRClockBit );
	
	}
	return;
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top