amitaiwe
Member level 3
- Joined
- Feb 19, 2014
- Messages
- 57
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 547
3. About the code:
Recently I did a project which contains a pic16f877 and
for that purpose I wrote in assembly language and used Mplab environment and ICD2
For burning the code to the pic.
can I use the same method here by copying the text of the code and use in the same
method? (by changing the configuration of Mplab to C code)
LIST P=PIC16F877
include <P16f877.inc>
__CONFIG _LVP_OFF &_WDT_ON &_PWRTE_ON &_CP_OFF & _XT_OSC
; basic config values Watchdog ON, Lvp OFF, XT OSC crystal 4mhz and below
cblock 0x20 ; define user registers/variables
ctr ; number of loops between two watchdog resets
previous ; previous value of ctr
calibr ; calibration value when oscillator runs free
restarts ; number of watchdog restarts
en ; enable flag, allows detection
endc
org 0x00
nop
goto start
start:
; configuration
;-----------------------------------
ction
banksel TRISB
clrf TRISB ; making PORTB output
banksel 0 ;bank 0
clrf PORTB ; reset output
; end configuration
;-----------------------------------
;*************** MAIN PROGRAM *****************
main_loop:
bcf STATUS,RP0 ;bank 0
btfss STATUS, 4 ; POWER UP? WDT TIME OUT OCCURRED?
goto init_loops ; yes
goto check_reset_counter ; no
init_loops:
clrf restarts
movlw 0x01
movwf calibr
check_reset_counter:
movlw 0xFF
subwf restarts, w ; restarts - 255
btfss STATUS, C ; restarts =< 255 ?
incf restarts, f ; yes - increment restarts
movf previous, w
xorwf ctr
subwf calibr, w ; calibr - ( previous xor ctr)
btfss STATUS, C ; is previous XOR ctr > calibr ?
call metal_detcted ; yes
movf ctr, w
movwf previous
movlw 0x0F
subwf restarts, w ; restarts - 15
btfsc STATUS, C ; calibration over?
goto calib_over ; yes
goto calib_still_active ; no
calib_over:
bcf PORTB, 1 ; calib led OFF
movlw 0xFF
movwf en ; enable detect led
goto WDT_set
calib_still_active:
bsf PORTB, 1 ; calib led ON
clrf en ; disable detect led
goto WDT_set
WDT_set:
bsf STATUS,RP0 ;bank 1
movlw 0xF9
movwf OPTION_REG ; Prescaler Rate, PORTB pull-ups are disable? (needed)?
bcf STATUS,RP0 ;bank 0
clrf ctr
waiting_loop: ; start counter, to be interrupted by watchdog
btfss STATUS, 4
goto main_loop
incf ctr, f
goto waiting_loop
;------
metal_detcted:
bsf PORTB, 2 ; turn led detect ON
btfss STATUS, 4 ; time out occurred ?
goto led_off ; yes
goto calib_check ; no
led_off:
bcf PORTB, 2 ; turn led detect OFF
return
calib_check:
movlw 0x0F
subwf restarts, w ; restarts - 15
btfsc STATUS, C ; in calibration mode?
return ; no
rlf calibr
call DELAY_1m
call DELAY_1m
call DELAY_1m
call DELAY_1m
call DELAY_1m
return
;*************** END MAIN PROGRAM *************
DELAY_1m:
movlw 0x2f ; N1 = 47
movwf 0x35
cont2: movlw 0x10 ; N2 = 16
movwf 0x36
cont1: decfsz 0x36,1
goto cont1
decfsz 0x35,1
goto cont2
return
end
Using a DMM I can see that the frequency on the inductor changes while having metal near,
but the led doesn't respond at all. the output of both the legs is
'0' continuously.
.
If you check on those bits you will see that its default power on value is 1:512
OK, Thanks,
But what can I do with this information?
Amitai
Hi,
For the chip to run pin1 Mclre must be tied to +5v , preferably by a resistor, around 10k.
Two simple choices, rewrite your code to compensate, or better still write you own code from scratch ,givne you can see the logic of the original code or buy that 12F as the guy has provided the .hex code.
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?