amitaiwe
Member level 3
- Joined
- Feb 19, 2014
- Messages
- 57
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 547
LIST P=PIC16F877
include <P16f877.inc>
org 0x00
reset: goto start
org 0x04
start: bcf STATUS, RP1
bsf STATUS, RP0 ;bank 1
clrf TRISD
bcf STATUS, RP0 ;bank 0
movlw 0x01
movwf PORTD
LOOP:
rlf PORTD, f
call DELAY
call DELAY
call DELAY
call DELAY ; delay * 4
goto LOOP
DELAY
movlw 0xff ; N1
movwf 0x30
cont2: movlw 0xff ; N2
movwf 0x31
cont1: decfsz 0x31,1
goto cont1
decfsz 0x30,1
goto cont2
return ; D=(5+4N1+3N1N2)*200nsec = (5+4*255+3*255*255)*200ns = 39.22ms
end
LIST P=PIC16F877
include <P16f877.inc>
__CONFIG _LVP_OFF &_WDT_OFF &_PWRTE_ON &_CP_OFF & _XT_OSC
; basic config values Watchdog OFF. Lvp OFF, XT OSC crystal 4mhz and below
cblock 0x20 ; define user registers/variables
d1,d2,d3 ; delay routine
endc
org 0x00
reset: goto start
org 0x04
start:
; bcf STATUS, RP1
; bsf STATUS, RP0 ;bank 1
banksel TRISD ; USE INSTEAD OF BSF ETC
clrf TRISD
banksel 0 ;bank 0
movlw 0x01
movwf PORTD
LOOP:
rlf PORTD, f
call DELAY
call DELAY
call DELAY
call DELAY ; delay * 4
goto LOOP
DELAY
movlw 0xff ; N1
movwf d1
cont2: movlw 0xff ; N2
movwf d2
cont1: decfsz d2,1
goto cont1
decfsz d3,1
goto cont2
return ; D=(5+4N1+3N1N2)*200nsec = (5+4*255+3*255*255)*200ns = 39.22ms
end
LIST P=PIC16F877
include <P16f877.inc>
nop
reset: goto start
org 0x04
start: bcf STATUS, RP1
bsf STATUS, RP0 ;bank 1
clrf TRISB
bcf STATUS, RP0 ;bank 0
LOOP1:
movlw 0xFF
movwf PORTB
goto LOOP1
end
I tried using a RC without success.
I have a CRYSTAL OSCILLATOR HO 11C of hosonic.
The oscillator is supposed to be simple but It also dosen't show any Freq. in the DMM.
it is a 4 leg osc. which I connected to vdd and vss with and output (no other leg to connect to
the osc2 leg !? )
Thanks again, Amitai
LIST P=PIC16F877
include <P16f877.inc>
__CONFIG _LVP_OFF &_WDT_OFF &_PWRTE_OFF &_CP_OFF & _RC_OSC
; basic config values Watchdog ON, Lvp OFF, XT OSC crystal 4mhz and below
nop
reset: goto start
org 0x04
start:
; configuration
;-----------------------------------
bcf STATUS, IRP ; Indirect Addressing to Bank 0-1
;UART/*/*/
bsf STATUS,RP0 ; bank 1
bcf STATUS,RP1
movlw 0xB2 ; master, transmit EN, sync mode, Transmit Shift Register empty
movwf TXSTA ; Baud Rate = Fosc/(4(SPBRG+1)) , BRGH (baud rate) ignored in sync
; clrf TRISC ; making port C output (also for SPI)
bsf TRISC, 6
bsf TRISC, 7
movlw 0x10 ; = d"16" which corresponds to 15Kbps with 8MHz clock
movwf SPBRG
bcf STATUS,RP0 ; bank 0
movlw 0x80 ; enable UART
movwf RCSTA
;LED/*/*/
bsf STATUS, RP0 ;bank 1
clrf TRISD
; end configuration --------------------------------------
;************ MAIN PROGRAM ***************
;*****************************************
bcf STATUS,RP0 ; bank 0
movlw 0x50
movwf FSR
fill_reg:
incf INDF
incf FSR
movlw 0x60
subwf FSR, W
btfss STATUS, Z
goto fill_reg
MAIN_loop:
;-----transmit_data
movlw 0x50
movwf FSR ; indirect Addressing points on 0x21
transmit_data:
movf INDF, W
movwf TXREG ; writing to TXREG clears TXIF
trans_wait2: btfss PIR1, TXIF ; wait for the frame to be transmitted
goto trans_wait2
;call DELAY
incf FSR, F
movlw 0x60 ;transmit for 16 sensors
subwf FSR, W
btfss STATUS, Z
goto transmit_data
led_loop:
movlw 0x02
movwf 0x32
movlw 0x02
movwf 0x33
CALL DELAY
CALL DELAY
CALL DELAY
CALL DELAY
CALL DELAY
CALL DELAY
led_green:
bcf PORTD,3
bsf PORTD,2
decfsz 0x32, f
goto led_green
CALL DELAY
CALL DELAY
CALL DELAY
CALL DELAY
CALL DELAY
CALL DELAY
led_red:
bcf PORTD,2
bsf PORTD,3
decfsz 0x33, f
goto led_red
goto led_loop
goto MAIN_loop
;******** END MAIN LOOP ********************
DELAY:
movlw 0xFF
movwf 0x30
movlw 0xFF
movwf 0x31
loopa:
decfsz 0x30, f
goto loopa
loopb:
decfsz 0x31, f
goto loopb
return
end
What about using the SPI protocol by sending the output of the clk out (which is oscillated by
the external crystal) to the SPI receiver (of the same PIC)and measuring the changes of the incoming freq. ?
Amitai
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?