pic12f1822 ile dokunmatik tuş uygulaması

Başlatan teknissyen, 09 Mart 2025, 16:52:46

teknissyen

arkadaşlar merhaba. pic12f1822 ile dokumnatik tuş uygulaması yapmak için int. den bu kodu buldum ayarları falan kolay oldun diye .fakat derleme hatası alıyorum. eksik yada hata nedir anlayamadım. mcs 4.0 kullanıyorum. bilgisayarım 64 bit. kendi yazdığım basic kodlarım çalışıyor. yardımcı olabilecekler için şimdiden teşekkürler.
kod bu şekilde...

'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : Dwight and others                                *
'*  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                              *
'*  Date    : 11/29/2013                                        *
'*  Version : 1.0                                              *
'*  Notes  :  PIC12F1822                                                *
'*          :                                                  *
'****************************************************************
#CONFIG
  __CONFIG _CONFIG1, _FCMEN_OFF & _FOSC_INTOSC & _WDTE_SWDTEN & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF
  __CONFIG _CONFIG2, _LVP_OFF
#ENDCONFIG
DEFINE  OSC 8                'tell picbasic what speed the oscillator is
'INCLUDE "DT_INTS-14.bas"    '
'INCLUDE "ReEnterPBP.bas"    ' Include if using PBP interrupts
OSCCON = %01110010       
                        '0 = 4x PLL is disabled
                        ' 1110 = 8 MHz
                        '    0 = unused
                        '      1X = Internal oscillator
ANSELA = %00000100        'make port A.2 is analog
TRISA  = %00000100        'port A.2 is input
WPUA  = %00000000        'turn off weak pull ups
APFCON = %00000001        'Alternate Pin Function Control Reg (default %00000000)
                          'move CCP to PortA.5 (for PWM output)
OPTION_REG = %10000111   
                        '1 = All weak pull-ups are disabled (except MCLR, if it is enabled)
                        ' 0 = Interrupt on falling edge of RB0/INT pin
                        '  0 = Timer0 clock is internal cycle clock (Fosc/4)
                        '  0 = Increment on low-to-high transition on RA4/T0CKI pin
                        '    0 = Prescaler is assigned to the Timer0 module
                        '    111 = 1:256 Timer0 prescaler rate
               
T1CON = %11000001      'enable timer 1 (bit 0) & source the clock from the CPS module (bit 6 & 7 =11
CPSCON0 = %10001100    'set the CPS module highest frequency availabe (for vcc mode) + timer0 clock sourced from CPS module. (BIT 1)
                        '1 = CPS module is enabled
                        ' 0 = CPS module is in the low range. Internal oscillator voltage references are used.
                        '  00 = unused
                        '    11 = Oscillator is in High Range. Charge/Discharge Current is nominally 18 µA
                        '      0 = Capacitive Sensing Oscillator Status bit (only readable)
                        '      0 = Timer0 clock source is controlled by the core/Timer0 module and is FOSC/4
CPSCON1 = %00000010        '0010 = channel 2, (CPS2)
CM1CON0 = 0  ' COMPARATOR OFF
CM1CON1 = 0  ' COMPARATOR OFF
CPS2_PRESENT    var WORD
CPS2_THRESHOLD  var WORD
CPS2_LAST      var WORD
'      Software variables
'      ==================
Duty    VAR WORD
stepp  var byte
' ----------------[ I/O Definitions ]-----------------------------------
FET VAR PORTA.5  ' PWM output to control the FET switch
'      Software/Hardware initialisation
'      ================================
PAUSE 50                          ' OSC settle delay
Duty = 0
stepp = 5
hpwm 1,255,250                    ' Start with Light full ON
pause 1000
   
ASM
INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
        INT_Handler  TMR0_INT,  _Timer0_Int,  pbp,  yes
    endm
    INT_CREATE              ; Creates the interrupt processor
ENDASM
TMR0 = 0                  'clear  TIMER0
@ INT_ENABLE  TMR0_INT    'enable timer0 interrupts
'***********************************************************************
'------------------------------< Main program >-------------------------
Main:
pause 100  ' not a whole lot going on here
goto main
'*****************************************************************************
Timer0_Int:
@ INT_DISABLE  TMR0_INT  ' stop timer0 interrupts while we're in here
pause 25
CPS2_PRESENT = TMR1                                ' take a snapshot of Timer1's present count.
CPS2_THRESHOLD = CPS2_LAST - ((CPS2_LAST/10)*2)    ' this sets the 'trigger' up for a 20% diversion (finger press)
CPS2_LAST = CPS2_PRESENT                          ' store away the present timer0count for the next time we come into the interrupt routine
if cps2_present < cps2_threshold then
    stepp = stepp +1
    if stepp>6 then stepp=0            ' check for rollover
    lookup stepp, [0,1,16,64,128,255,255],duty  'choose level, 5 levels plus OFF
    if stepp=6 then
        hpwm 1,0,1000    'off              ' arrive here when brightness is MAX
        pause 100                          '    So blink to let user know.
        hpwm 1,255,1000  'on
        pause 100
        hpwm 1,0,1000    'off
        pause 100
        hpwm 1,255,1000  'on              ' blink to show that you are at the highest level
    endif   
    hpwm 1,duty,250                    ' else set new level                      ' button pressed so increment stepp 
    pause 100
endif
pause 50     
TMR0 = 0                  ' clear TIMER0   
TMR1 = 0                  ' clear TIMER1
@ INT_ENABLE  TMR0_INT    ' re-enable timer0 interrupt
@ INT_RETURN 
end

ete

Birincisi bu program mcs 4.0 ile derlenir ise öncelikle sigorta ayarlarının veriliş şekli nedeni ile hata verir
İkincisi bu programda Darrel Taylor'un include edilebilen programlarıda kullanılmış.
Bunlar;
   'INCLUDE "DT_INTS-14.bas"    '
   'INCLUDE "ReEnterPBP.bas"    ' Include if using PBP interrupts
olup bunlarında derleme yapılan yerde olması gerekir.

Sigorta ayarları hatasını aşmak için,

ASM
  __CONFIG _CONFIG1, _FCMEN_OFF & _FOSC_INTOSC & _WDTE_SWDTEN & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF
  __CONFIG _CONFIG2, _LVP_OFF
ENDASM
şeklinde verebilirsin. Bu şekilde verebilmen için de bu derlemeyi MPASM assembleri kullanılması gerekir.  Bunun için
https://etepic.com/index.php/topic,1687.0.html
linkte verilen açıklamaları dikkatlice okumanı ve söylenilenleri yapmanı önerebilirim.

Son olarak da gereken Darrel Taylor programlarını buraya ekliyorum. Bu programlarıda asıl programın olduğu klasöre kopyalaman yeterli olacaktır.

Ete


teknissyen

teşekkür ederim. verdiğiniz bilgilerle deneyip sonucu buradan paylaşırım.

teknissyen

ete hocam tekrar teşekkür ederim. normal derleme yapabildim. bakalım kodu istediğim gibi değiştirip çalıştırabilecekmiyim. yine sonuçları buradan paylaşırım.

Powered by EzPortal