kod değişikliği

Başlatan fatefate420, 17 Aralık 2013, 18:13:27

fatefate420

ekteki dosyada bulunan program 12f615 için yazılmış bunu 12f675 e çevirme şansımız varmıdır
piclerle ilgili çok fazla bilgim yok daha yeni başlıyorum sayılır yardımcı olabiliseniz sevinirim
list       F=inhx8m, P=12F615, R=hex, N=0
#include  P12F615.inc; PIC definitions
 __config _BOR_ON & _IOSCFS_8MHZ & _CP_OFF & _MCLRE_ON & _PWRTE_OFF & _WDT_OFF & _INTOSCIO


 Errorlevel -302, -224     ; switches off Message [302]: Register in operand not in bank 0.
; Definitions -------------------------------------------------------------
#define OutputPin porta,0
#define ToggleSelect porta,5
#define SensitivitySelect porta,4
#define PreviousButtonState Flags,0


; RAM preserved -----------------------------------------------------------
	cblock 0x40
		WaitCounter,WaitCounter2
		PassArg1,PassArg2
		PassArg3,PassArg4

		Press_Threshold_H,Press_Threshold_L
		Release_Threshold_H,Release_Threshold_L
		Flags
	endc 



; Conastants --------------------------------------------------------------
GLPressHysteresis_H			=		b'00000001'		;High sensitivity
GLPressHysteresis_L			=		b'00000010'		;High sensitivity
GLReleaseHysteresis_H		=		b'00000001'		;High sensitivity
GLReleaseHysteresis_L		=		b'00000000'		;High sensitivity

GLPressHysteresis_H_2		=		b'00000001'		;Low sensitivity
GLPressHysteresis_L_2		=		b'00001110'		;Low sensitivity
GLReleaseHysteresis_H_2		=		b'00000001'		;Low sensitivity
GLReleaseHysteresis_L_2		=		b'00001000'		;Low sensitivity



; Program Memory ----------------------------------------------------------
                org     0
                goto    Init
; Interrupt Service Routine -----------------------------------------------
                org     4               ; ISR beginning

; -------------------------------------------------------------------------
; Microcontroller initialization
Init            
				include myInitilization.inc	;Include the PIC Initialization routine


;##########################################################################
; Main Program ------------------------------------------------------------

Start
				;TRIS setup
				bank1					;Go to bank 1
				movlw b'11111010'		;
				movwf TRISA				;Set the port pin types of the RA
				bank0					;Go to bank 0
				bcf OutputPin

				MOVLW b'11100111'
				option		
				bsf cmcon0,CMON			;Enable comparator
				bcf cmcon0,CMPOL		;Logic is inverted
				bcf cmcon0,COUT			;
				bsf cmcon0,CMOE			;Output to COUT pin
				bsf cmcon0,CMR			;V+ driven to Vref
				bcf cmcon0,CMCH			;V- driven to channel 0
				bcf CMCON1,T1ACS		;Timer 1 Clock Source is Instruction Clock (FOSC\4)
				bcf CMCON1,CMHYS		;Comparator Hysteresis disabled
				bsf CMCON1,T1GSS		;Timer 1 Gate Source is T1G pin (pin should be configured as digital input)
				bcf CMCON1,CMSYNC		;Output is asynchronous
				movlw b'00010000'
				movwf vrcon

				;Set the press threshold
				call wait250msec
				call wait250msec
				call wait250msec
				call wait250msec			;Wait for frequency to become stable

				call GetFrequencyCount

				movlw GLPressHysteresis_H_2
				btfsc SensitivitySelect
				movlw GLPressHysteresis_H
				subwf passarg1,w			;Sub from count HIGH the HIGH byte of Press Thresshold
				movwf Press_Threshold_H		;And save it to memory

				movlw GLPressHysteresis_L_2
				btfsc SensitivitySelect
				movlw GLPressHysteresis_L
				subwf passarg2,w			;Sub from count LOW the LOW byte of Press Thresshold
				movwf Press_Threshold_L		;And save it to memory

				;Set the release threshold
				movlw GLReleaseHysteresis_H_2
				btfsc SensitivitySelect
				movlw GLReleaseHysteresis_H
				subwf passarg1,w			;Sub from count HIGH the HIGH byte of Release Thresshold
				movwf Release_Threshold_H	;And save it to memory

				movlw GLReleaseHysteresis_L_2
				btfsc SensitivitySelect
				movlw GLReleaseHysteresis_L
				subwf passarg2,w			;Sub from count LOW the LOW byte of Release Thresshold
				movwf Release_Threshold_L	;And save it to memory


MainLoop
				call GetFrequencyCount

				;Check if pressed
				movf passarg2,w
				movwf passarg4				;Save Prescaller Count
				movf passarg1,w
				movwf passarg3				;Save TMR0 Count

				movf Press_Threshold_L,w
				subwf passarg2,w			; R= Prescaller - LOW threshold
				btfss carry
				decf passarg1,f				;If R < 0, decrease passarg1 (TMR0 count)
				movf Press_Threshold_H,w
				subwf passarg1,w			; R= TMR0 - HIGH threshold
				btfsc carry
				goto IsNotPressed			;If R < 0, Button is NOT Pressed
											;Else is pressed

				btfss ToggleSelect			;If ToggleSelect is LOW (pushbutton action)
				goto ActivateOutput			;Then just activate output

				btfsc PreviousButtonState	;Else, check if previous state was RELEASED
				goto PressReleaseCheckDone	;If not, then do nothing
											;If WAS released...
				bsf PreviousButtonState		;Update previous state
				movlw b'00000001'	
				xorwf PORTA,f				;Toggle output
				call wait100msec			;and wait 100msec
				goto PressReleaseCheckDone

ActivateOutput
				bsf OutputPin					
IsNotPressed	;Check if released
				movf passarg3,w
				movwf passarg1				;Restore TMR0 Count
				movf Release_Threshold_L,w
				subwf passarg2,w			; R= Prescaller - LOW threshold
				btfss carry
				decf passarg1,f				;If R < 0, decrease passarg3 (TMR0 count)
				movf Release_Threshold_H,w
				subwf passarg1,w			; R= TMR0 - HIGH threshold
				btfss carry
				goto PressReleaseCheckDone	;If R > 0, Button is NOT Released
											;Else is released
				btfss ToggleSelect			;If ToggleSelect is LOW (pushbutton action)
				bcf OutputPin				;Then deactivate output
				bcf PreviousButtonState		;else (Toggle) do not deactivate it

PressReleaseCheckDone
				goto MainLoop


GetFrequencyCount
				;This sub returns PassArg1:PassArg2 as the TMR0:Prescaller count
				clrf passarg1
				movlw d'44' 				; Set the maximum prescaller value 
				movwf passarg2				; to start decreasing (max 43+1)
				clrf tmr0
				call wait10msec
				call wait10msec
				call wait10msec
				call wait10msec
				call wait10msec
				call wait10msec
				movf tmr0,w
				movwf passarg1
				MOVLW b'11000111'	;Tmr0 source is Fosc/4
				option		
GetPrescallerValue
				decF passarg2,f				;1
				MOVF tmr0,w					;1
				XORWF passarg1,w			;1
				BTFSC status,z				;1
				GOTO GetPrescallerValue		;2 = total 6 instruction cycles
				;So, it prescaller is 0 (min), we can measure (ceil)255/6=43
				MOVLW b'11100111'			;Tmr0 source is T0CKI
				option		
				return




				include mSecDelays8MHz.inc


Fins

                end             ; end of program

RaMu

 list       F=inhx8m, P=12F615, R=hex, N=0
#include  P12F615.inc; PIC definitions

bu satırlarda P =12f675
p12F675.inc
olarak değiştir,
mplab da program nasıl derlenir öğren,
mplabta bu programı derle,
isis biliyorsan simulasyonda dene,
ama 615 ile 675 arasındaki farklara bakman lazım
programda 615 in neleri kullanılmışsa
port timer vs. register lar
bunların yeni kullanacağın picdede aynı olması lazım
yoksa kodları ona göre düzenlemen gerekir.
Sorularınıza hızlı cevap alın: http://www.picproje.org/index.php/topic,57135.0.html