{
CLK = 1;
DATA = (LED data & (corresponding bit) ) ? 1 : 0;
delay();
CLK = 0;
delay();
}
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
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 }
okay thanks....
i can try it in assembly
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???
;================================================= ===========
; 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
;================================================= ===========
Great char2539211!!!!thank you!!!! i used the SPI interface.....
its working
Great char2539211!!!!thank you!!!! i used the SPI interface.....
its working
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?