Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing 74HC164 with PIC

Status
Not open for further replies.

charu2539211

Junior Member level 3
Junior Member level 3
Joined
Jul 22, 2013
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Visit site
Activity points
200
Hi.

I am working on a project in which I have to make a 7 segment display to work controlled by PIC16f887. i am writing the code in Assembly language. the pic would generate serial data which is given to 74hc164n (8 bit serial in parralel out shift register). the output from 74hc164n is given to the 7 segment display.
I would like to know how i can sync the clock cycles which i have to generate from the microcontroller with the microcontroller frequency. Can anyone help me with a code for this or at least an algorithm would do.


you ll fiind the screen shot of the circuit in the below URL

https://obrazki.elektroda.pl/4775218100_1374472338.jpg

thanks
 

I assume you doesnt give shift registers your crystal frequency...

then you have to generate both clk and data outputs to SRs..

you have to enable the SR
and then for example it haves negative edge clock,



Do this 8 times for 1 write (1 byte)
Code:
{
CLK = 1;
DATA = (LED data & (corresponding bit) ) ? 1 : 0;
delay();
CLK = 0;
delay();
}
at the end you will have the data in LED segments
 
Last edited by a moderator:
I am writing in C

Code C - [expand]
1
2
3
4
5
6
7
8
for( i = 0; i < 8; i++)
{
CLK = 1;
DATA = (LED_data & (1 << i ) ) ? 1 : 0; // in this case we are transmitting from LSB
delay();
CLK = 0;
delay();
}

 
Hi.

I am working on a project in which I have to make a 7 segment display to work controlled by PIC16f887. i am writing the code in Assembly language. the pic would generate serial data which is given to 74hc164n (8 bit serial in parralel out shift register). the output from 74hc164n is given to the 7 segment display.
I would like to know how i can sync the clock cycles which i have to generate from the microcontroller with the microcontroller frequency. Can anyone help me with a code for this or at least an algorithm would do.


you ll fiind the screen shot of the circuit in the below URL

http://obrazki.elektroda.pl/4775218100_1374472338.jpg

thanks


Hi,

If you see this Assembly tutorial it shows a much more typical way to drive a 7 segment led with just one transistor to turn on each unit than using a serial to parallel converter.
http://www.winpicprog.co.uk/pic_tutorial_7seg_board.htm
http://www.winpicprog.co.uk/pic_tutorial10.htm

If you have to use your serial method then again see this same tutorial, section RS232, which shows both software and hardware USARTs.
http://www.winpicprog.co.uk/pic_tutorial7.htm
 

ya i have to use the serial shift register.

can i use the timer to generate my clock signals and sync with my data transfer???
 

Use Timer interrupt to send serial data to Shift register. For every bit you need to clock once. If Shift register o/p are Q0 to Q6 then Q6 will be the LSB and Q0 will be the MSB. After the data appears at the o/ps of Shift register then turn on the particular SSD using a transistor. You can also try MAX7219, MAX6954, MAX6955.
 

yeah you can . . .
without ISR you can replace the above program delay with Timer module delay....

If you want to give clock pulse using timer Isr then you have to give only 8 for one write If you go more It will made overflow the SR...
So for each write ther should be only 8 clks..

And you can Do like this

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
main()
{
timer_init();
- - - ;
- - - ;
start_transmit(LED_data);
- - - ;
- - - ;
}
 
void start_transmit(char data)
{
enable_timer_interrupt;
i = 2*SIZE_OF_DATA;   //in bits..
Txbuff = data;
CLK = 1;
DATA = Txbuff & first_bit
}
 
void Timer_ISR(void)
{
if(i>0)
{
i--;
CLK =~CLK;         // toggles two times a bit
}
 
if(Clk == 1)
DATA = Txbuff & (corresponding bit) // loads one time a bit
 
if(i == 0)
Disable_interrupt; // turns off after 8 bit
}

 
Last edited:
sorry Charu,
I never wrote in assembly for pic , still its an algorithm only and you have to make changes to get a perfect code..
 

okay thanks....
i can try it in assembly


Hi,

If you looked at the software usart code in that tutorial I gave, it shows you how to output one byte to a port pin one bit at a time. see below.

You do not need a Timer to SYNC the the two chips - if you read the 74164data sheet, all the clock does is cause the data to be read in every time the clock pulse goes from Low to High so that should be very easy to incorperate in the above mentioned code every time you send a bit of data out.

Edit - have you done Any Assembly coding before ?


Code:
XMIT_RS232  MOVWF   Xmit_Byte             ;move W to Xmit_Byte
            MOVLW   0x08                  ;set 8 bits out
            MOVWF   Bit_Cntr
            BCF     PORTB, 6
            CALL    Bit_Delay
Ser_Loop    RRF     Xmit_Byte , f         ;send one bit
            BTFSS   STATUS    , C
            BCF     PORTB, 6
            BTFSC   STATUS    , C
            BSF     PORTB, 6
            CALL    Bit_Delay
            DECFSZ  Bit_Cntr  , f         ;test if all done
            GOTO    Ser_Loop
            BSF     PORTB, 6
            CALL    Bit_Delay
            RETURN
 
HI

the program you have given is very helpful.
so in the code we shift the transmitting bit right through carry. by checking the status of the Carry register, we set or reset the Rb6. is that right???

but i have to produce clock pulses for the 74hc164n also. how can i incorporate that in the code???
 

HI

the program you have given is very helpful.
so in the code we shift the transmitting bit right through carry. by checking the status of the Carry register, we set or reset the Rb6. is that right???

but i have to produce clock pulses for the 74hc164n also. how can i incorporate that in the code???


Hi,

Yes, thats correct, once you have set RB6 to the required state then you Pulse the 174s clock line by turning another port on and off for a few milli seconds ,which tells the 174 to read in /shift the data.

If you are new the assembler you might find that tutorials early lessons on flashing a led a good place to start learning, otherwise you are working in the dark too much.

You also want to see section 15 of the 16f887s datasheet which gives full details of all the Instructions you can use.
 
hi
here's my code :

Code:
;=================================================  ===========
; File name:pic164shift
; Date:07/24/2013
; Author:kgavionics
; Processor:PIC16F877A
; Reference circuit:
;=================================================  ===========
; Copyright notice:
;=================================================  ===========
; Program Description:
;
;===========================
; configuration switches
;===========================
list		p=16f877A	; list directive to define processor
	#include	<p16f877A.inc>	; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF



;=================================================  ====
; constant definitions
#define CS 0x02 ; PORTA,2
;=================================================  ====
;=================================================  ====
; PIC register equates

;=================================================  ====
;=================================================  ====
; variables in PIC RAM
;=================================================  ====
cblock 0x20
counter1 :  1 
counter2  : 1
datas : 1
endc
;=================================================  ===========
; program
;=================================================  ===========
org 0X00 ; start at address
goto main

delay
	movlw	0x50
	movwf	counter2
loop1
	movlw	0xff
	movwf	counter1
loop2
 	nop
	decfsz counter1
	goto loop2
	decfsz counter2
	goto loop1
return
spi_init
	bsf STATUS,RP0
	movlw 0x00
	movwf TRISA
	movlw 0x01
	movwf TRISC
	movlw 0x40
	movwf SSPSTAT	
	bcf STATUS,RP0
	movlw 0x31
	movwf SSPCON
return

Send_DT

	bcf PORTA,CS  ;ENABLE CHIP SELECT OUTPUT LOW
	movf datas,w ; get cltr (counter value) in w
	movwf SSPBUF ; PUT IN SSPBUFFER
	Char2
	bsf STATUS,RP0
	btfss SSPSTAT,BF ; datas transfer complete?
	goto Char2
	bcf STATUS,RP0 ;change bank
	movf SSPBUF,W ;Get datas from SSPBUF and throw it away
	bsf PORTA,CS ; DISBLE CHIP SELECT
	
return

main

	call spi_init
	movlw 0x18
	movwf datas
	call Send_DT
	call delay
	movlw 0x24
	movwf datas
	call Send_DT
	call delay
	movlw 0x42
	movwf datas
	call Send_DT
	call delay
	movlw 0x81
	movwf datas
	call Send_DT
	call delay
	movlw 0x81
	movwf datas
	call Send_DT
	call delay
	movlw 0x42
	movwf datas
	call Send_DT
	call delay
	movlw 0x24
	movwf datas
	call Send_DT
	call delay
	movlw 0x18
	movwf datas
	call Send_DT
	call delay
	goto main
;=================================================  ===========
end ; END OF PROGRAM
;=================================================  ===========

and here's also the video of the working circuit
hope it will be helpful
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top