bluetooth kontrollü pic

Konusu 'Akıllı Bina Otomasyonu' forumundadır ve Battery tarafından 11 Mayıs 2014 başlatılmıştır.


  1. Battery

    Battery Üye

    Katılım:
    14 Ağustos 2011
    Mesajlar:
    36
    Beğenilen Mesajları:
    2
    Ödül Puanları:
    3
    İyi günler enerji sistemleri mühendisliği 2.sınıf öğrencisiyim. Okulda küçük bir proje ekibimiz var.İlk proje çalışmamızda küçük bir akıllı ev uygulaması. Bunun içinde bluetooth haberleşme yolunu seçtik.Teknik bilgi ve birikimimiz az. Buraya bu tarz 100lerce konu açılmış.Ama ben hala nasıl yapacağımı anlayamadım.
    Amacım sadece proje yaparken öğrenmek. Size sormak istediklerim :


    1-Hangi bluetooth modülünü kullanmalıyım (mümkünse ucuz yollu olması gerekir öğrenciyiz)
    2-Bu bluetooth modülünü ile nasıl pic ile haberleşeceğim.
    3-Pic için yazılım lazım bunu nasıl halledeceğim.
    isis devresi ares devresi,pic yazılımı, bluetooth modül bağlantısı lazım anlayacağınız.
    nasıl yol izlemem gerekir

    Gerekirse yardım eden arkadaşlara küçük bir miktar ücret bile ödemeye bile hazırım.
     
  2. zenze

    zenze Üye

    Katılım:
    2 Eylül 2007
    Mesajlar:
    251
    Beğenilen Mesajları:
    12
    Ödül Puanları:
    3
    1-hc serisi bluetooth modülleri var hc06 gibi bunları kullanabilirsin
    2- bu modüller seri ara birim gibi kullanılabilirler rx tx olarak
    3- Yazılımı bildiğin bir dille yazacaksın
    4- Bu tip kontrollerde genellikle verici cep tlf, tablet oluyor , yani işin bir tarafı pic yazılımı diğeri pc programı , nette hazır örnekler vardır sanırım araştır istersen

    ör:Android Üzerinde MSP430 Bluetooth ile Kablosuz Kontrol Uygulaması » Elektronik Sitesi
     
    Son düzenleme: 11 Mayıs 2014
  3. Battery

    Battery Üye

    Katılım:
    14 Ağustos 2011
    Mesajlar:
    36
    Beğenilen Mesajları:
    2
    Ödül Puanları:
    3
    elimde bu kit mevcut fakat yazılım konusunda yazılım dili bilmiyorum ccs programıda var bana yazılım konusunda yardım edebilecek var mı acaba

    KontrolKalemi Mobile ile gönderildi.
     
  4. kevser3703

    kevser3703 Üye

    Katılım:
    6 Haziran 2017
    Mesajlar:
    4
    Beğenilen Mesajları:
    0
    Ödül Puanları:
    1
    Cinsiyet:
    Bayan
    Arkadaşlar akıllı ev projesi için gerekli programı yazdım pic assembly dili ile yazıyorum fakat bluetooth modülünü picle haberlştirmek için nasıl yazıcam nasıl olacak hiç bir fikrim yok. Bluetooth ile 3 çıkışı kontrol etmem gerekiyo aç kapa vs.
    Ama örnek hiç bir yerde yazılımı bulamıyorum. Lütfen yardımcı olur musunuz
     
  5. alarmko

    alarmko Üye

    Katılım:
    14 Ocak 2009
    Mesajlar:
    365
    Beğenilen Mesajları:
    32
    Ödül Puanları:
    3
    Cinsiyet:
    Bay
    Meslek:
    mak müh
    Asagıda verdigim yazılım hc-05 ile yapılmıs calısan bir yazılımdır.Bir arkadasımın çiftligindeki kamerayı saga sola çevirmek için(step motor ile) yapılmıstır.R100 veya L200 gibi komutlar ile saga veya sola donmektedir.R saga 100,100 puls anlamındadır.Takıldıgın yer olursa sorabilirsin.Kolay gelsin.
    INCLUDE "P16F886.INC"

    __CONFIG _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_ON & _HS_OSC
    __CONFIG _CONFIG2, _WRT_OFF & _BOR21V


    ;
    ;******** bu kýsým sonradan eklendý interrup ile pc denrs232 data alýp yazýyor



    SPBRG_VAL EQU .29 ;9600 baud brg16=0 brgh=0
    TX_BUF_LEN EQU .96 ;length of transmit circular buffer
    RX_BUF_LEN EQU .48 ;length of receive circular buffer

    M_HIZ EQU .25





    #DEFINE STA PORTC,3
    #DEFINE LED PORTA,2
    #DEFINE MOTOR_DIR PORTA,0
    #DEFINE MOTOR_STEP PORTA,1
    #DEFINE MOTOR_ENABLE PORTA,4
    ;port B tanýmlarý

    ;----------------------------------------------------------------------------
    ;Bit Definitions

    TxBufFull EQU 0 ;bit indicates Tx buffer is full
    TxBufEmpty EQU 1 ;bit indicates Tx buffer is empty
    RxBufFull EQU 2 ;bit indicates Rx buffer is full
    RxBufEmpty EQU 3 ;bit indicates Rx buffer is empty

    ReceivedLF EQU 5 ;bit indicates <LF> character received
    ReceivedCR1 EQU 6 ;bit indicates <CR> character received
    ReceivedCR2 EQU 7 ;bit indicates <CR> character received
    ;----------------------------------------------------------------------------






    ; Define statements.


    RAM_START EQU 00020h
    RAM_END EQU 001EFh
    RAM_BANKS EQU 00004h
    BANK0_START EQU 00020h
    BANK0_END EQU 0007Fh
    BANK1_START EQU 000A0h
    BANK1_END EQU 000EFh
    BANK2_START EQU 00110h
    BANK2_END EQU 0016Fh
    BANK3_START EQU 00190h
    BANK3_END EQU 001EFh
    EEPROM_START EQU 02100h
    EEPROM_END EQU 021FFh


    EE_ADR EQU RAM_START + 004h
    EE_ADRH EQU RAM_START + 005h
    EE_DATA EQU RAM_START + 006h
    EE_DATH EQU RAM_START + 007h

    ;Variables
    CBLOCK RAM_START + 0X08
    FLAG_CEVAP
    TEMP
    TEMP1
    TEMP2
    TEMP3
    WREG_TEMP ;storage for WREG during interrupt
    STATUS_TEMP ;storage for STATUS during interrupt
    PCLATH_TEMP ;storage for PCLATH during interrupt
    FSR_TEMP ;storage for FSR during interrupt
    Flags ;byte to store indicator flags
    TempData ;temporary data in main routines
    BufferData ;temporary data in buffer routines
    TxStartPtr ;pointer to start of data in TX buffer
    TxEndPtr ;pointer to end of data in TX buffer
    RxStartPtr ;pointer to start of data in RX buffer
    RxEndPtr ;pointer to end of data in RX buffer
    CONN_TIME
    TEMP_H
    TEMP_L
    ENDC
    CBLOCK 0X40
    RxBuffer:RX_BUF_LEN ;receive data buffer
    ENDC

    CBLOCK 0X110
    TxBuffer:TX_BUF_LEN ;transmit data buffer
    ENDC




    #DEFINE ReceivedCR FLAG_CEVAP,2 ;bit indicates <CR> character received
    #DEFINE EEPR_FLAS FLAG_CEVAP,5 ;0 ISE EEPROM 1 ISE FLAS




    ;-----------------------------------------------------------------------------
    ;Macros to select the register bank
    ; Many bank changes can be optimized when only one STATUS bit changes

    Bank0 MACRO ;macro to select data RAM bank 0
    bcf STATUS,RP0
    bcf STATUS,RP1
    ENDM

    Bank1 MACRO ;macro to select data RAM bank 1
    bsf STATUS,RP0
    bcf STATUS,RP1
    ENDM

    Bank2 MACRO ;macro to select data RAM bank 2
    bcf STATUS,RP0
    bsf STATUS,RP1
    ENDM

    Bank3 MACRO ;macro to select data RAM bank 3
    bsf STATUS,RP0
    bsf STATUS,RP1
    ENDM


    #define FOSC .20 ;20
    #define CODE_SIZE 8
    #DEFINE RESET_ORG 0400H


    RAM_START EQU 00020h
    RAM_END EQU 001EFh
    RAM_BANKS EQU 00004h
    BANK0_START EQU 00020h
    BANK0_END EQU 0007Fh
    BANK1_START EQU 000A0h
    BANK1_END EQU 000EFh
    BANK2_START EQU 00110h
    BANK2_END EQU 0016Fh
    BANK3_START EQU 00190h
    BANK3_END EQU 001EFh
    EEPROM_START EQU 02100h
    EEPROM_END EQU 021FFh


    ORG 000H

    ;place code at reset vector

    ResetCode: clrf PCLATH ;select program memory page 0
    goto Main ;go to beginning of program
    ;---------------------------
    ORG 0x0004 ;place code at interrupt vector
    GOTO InInterruptCode
    ORG 0010H

    ;*****************************
    BEKLE500US CLRF TEMP2
    TBEKLE500 CLRWDT
    nop
    nop
    NOP
    NOP
    NOP
    NOP
    DECFSZ TEMP2,F
    GOTO TBEKLE500
    RETLW 0
    ;********************************************
    BEKLE145US MOVLW .180 ;185
    MOVWF TEMP2
    TBEKLE145 CLRWDT
    DECFSZ TEMP2,F
    GOTO TBEKLE145
    RETLW 0
    ;********************************************
    BEKLE5MS MOVLW .238
    MOVWF TEMP1
    MOVLW .22
    MOVWF TEMP2
    TBEKLE5MS CLRWDT
    DECFSZ TEMP1,F
    GOTO TBEKLE5MS
    DECFSZ TEMP2,F
    GOTO TBEKLE5MS
    RETLW 0
    ;**************************************
    BEKLE40MS MOVLW .238
    MOVWF TEMP1
    MOVLW .195
    MOVWF TEMP2
    TBEKLE40MS CLRWDT
    DECFSZ TEMP1,F
    GOTO TBEKLE40MS
    DECFSZ TEMP2,F
    GOTO TBEKLE40MS
    RETLW 0
    ;***********************************************


    InInterruptCode:Bank0
    movwf WREG_TEMP ;save WREG
    movf STATUS,W ;store STATUS in WREG
    clrf STATUS ;select file register bank0
    movwf STATUS_TEMP ;save STATUS value
    movf PCLATH,W ;store PCLATH in WREG
    movwf PCLATH_TEMP ;save PCLATH value
    clrf PCLATH ;select program memory page0
    movf FSR,W ;store FSR in WREG
    movwf FSR_TEMP ;save FSR value

    Bank0 ;select bank0

    btfsc PIR1,RCIF ;test RCIF receive interrupt
    bsf STATUS,RP0 ;change to bank1 if RCIF set
    btfsc PIE1,RCIE ;test if interrupt eabled if RCIF set
    goto GetData ;if RCIF and RCIE set, do receive

    Bank0 ;select
    ;-------------------------------------------------bank0
    btfsc PIR1,TXIF ;test for TXIF transmit interrupt
    bsf STATUS,RP0 ;change to bank1 if TXIF set
    Bank1
    btfsc PIE1,TXIE ;test if interrupt enabled if TXIF set
    goto PutData ;if TXIF and TCIE set, do transmit
    goto EndInt

    ;------------------------------------
    ;Get received data and write into receive buffer.

    GetData: Bank0
    btfsc RCSTA,OERR ;test overrun error flag
    goto ErrOERR ;handle it if error
    btfsc RCSTA,FERR ;test framing error flag
    goto ErrFERR ;handle it if error


    RCVRCIK1 MOVLW .1
    MOVWF TMR2
    BSF ReceivedCR


    MOVF RCREG,W ;change back to valid data
    call PutRxBuffer ;and put in buffer


    goto EndInt

    ;--------------------------
    ErrOERR: bcf RCSTA,CREN ;reset the receiver logic
    bsf RCSTA,CREN ;enable reception again
    goto EndInt
    ;-----------------------------------
    ErrFERR: movf RCREG,W ;discard received data that has error
    goto EndInt
    ;------------------------------
    ErrRxOver: movlw 0A0h
    MOVWF RxStartPtr
    MOVWF RxEndPtr
    goto EndInt
    ;------------------------------------
    ;Read data from the transmit buffer and transmit the data.
    PutData: Bank0 ;select bank 0
    btfss Flags,TxBufEmpty ;check if transmit buffer empty
    goto PutDat1 ;if not then go get data and transmit
    Bank1 ;select bank1
    bcf PIE1,TXIE ;disable TX interrupt because all done
    goto EndInt
    ;------------------------
    PutDat1:call GetTxBuffer ;get data to transmit


    banksel PORTA
    BTFSS PIR1,TXIF ;check if transmitter busy
    GOTO $-1

    MOVF INDF,W
    movwf TXREG ;and transmit

    Bank1
    TT1 BTFSC TXSTA,1 ;gonderme iþleminin tamamlanmasý bekleniyor
    GOTO TT2
    NOP
    TT2 Bank0
    ;------------------------------------
    ;End of interrupt routine restores context
    EndInt: Bank0 ;select bank 0
    movlw .1
    movwf TMR2 ;RXSTART ADRESINI DUZELTMEK ICIN

    movf FSR_TEMP,W ;get saved FSR value
    movwf FSR ;restore FSR
    movf PCLATH_TEMP,W ;get saved PCLATH value
    movwf PCLATH ;restore PCLATH
    movf STATUS_TEMP,W ;get saved STATUS value
    movwf STATUS ;restore STATUS
    swapf WREG_TEMP,F ;prepare WREG to be restored
    swapf WREG_TEMP,W ;restore WREG without affecting STATUS
    retfie ;return from interrupt
    ;*********************************************
    HATA MOVWF TEMP
    clrf Flags
    RETURN
    ;----------------------------------------------------------------------------
    ;=====================================================================
    MainLoop: Bank0 ;select bank0
    ;********************************
    bSf PORTB,1 ;BULUTOTH MODUL ILETISIM MODUNA GECIRILIYO
    BSF MOTOR_ENABLE ;MOTOR DEVREDISINA CIKARTILIYOR
    Bank1 ;select bank 1
    bsf PIE1,RCIE ;ENABLE receive interrupt
    Bank0 ;select bank 0
    clrwdt

    MOVF TMR2,W
    BTFSS STATUS,Z
    GOTO MainLoop
    ;************************************
    PASPAS clrwdt
    moVf TMR2,W
    BTFSC STATUS,Z
    GOTO PASPAS
    INCF CONN_TIME,F
    MOVF CONN_TIME,W
    BTFSS STATUS,Z
    GOTO MainLoop

    BTFSC ReceivedCR
    GOTO DONDUR

    CALL InitRxBuffer
    CALL InitTxBuffer

    BTFSS STA
    GOTO MainLoop
    BSF LED
    MOVLW 'B'
    call PutTxBuffer
    MOVLW 'A'
    call PutTxBuffer
    MOVLW 'G'
    call PutTxBuffer
    MOVLW 'L'
    call PutTxBuffer
    MOVLW 'A'
    call PutTxBuffer
    MOVLW 'N'
    call PutTxBuffer
    MOVLW 'T'
    call PutTxBuffer
    MOVLW 'I'
    call PutTxBuffer
    MOVLW ' '
    call PutTxBuffer
    MOVLW 'K'
    call PutTxBuffer
    MOVLW 'U'
    call PutTxBuffer
    MOVLW 'R'
    call PutTxBuffer
    MOVLW 'U'
    call PutTxBuffer
    MOVLW 'L'
    call PutTxBuffer
    MOVLW 'D'
    call PutTxBuffer
    MOVLW 'U'
    call PutTxBuffer
    MOVLW .13
    call PutTxBuffer
    MOVLW .10
    call PutTxBuffer
    CALL BEKLE500MS
    BCF LED
    CALL BEKLE1SN
    GOTO MainLoop
    ;**************************************
    DONDUR MOVF RxEndPtr,W
    MOVWF FSR
    DECF FSR,F
    MOVF INDF,W
    XORLW '+'
    BTFSS STATUS,Z
    GOTO CIK
    DECF FSR,F
    MOVF INDF,W
    XORLW '+'
    BTFSS STATUS,Z
    GOTO CIK
    DECF FSR,F
    MOVF INDF,W
    XORLW '+'
    BTFSS STATUS,Z
    GOTO CIK

    CLRF TEMP_H
    CLRF TEMP_L

    DECF FSR,F ;BIRLER
    MOVF INDF,W
    ANDLW 00FH
    MOVWF TEMP_L

    DECF FSR,F ;ONLAR
    MOVF INDF,W
    ANDLW 00FH
    MOVWF TEMP
    BTFSC STATUS,Z
    GOTO ZIPYUZLER

    ZIPONLAR MOVLW .10
    ADDWF TEMP_L,F
    BTFSC STATUS,C
    INCF TEMP_H
    DECFSZ TEMP,F
    GOTO ZIPONLAR

    ZIPYUZLER DECF FSR,F
    MOVF INDF,W
    ANDLW 00FH
    MOVWF TEMP
    BTFSC STATUS,Z
    GOTO YON

    ZIPYUZ MOVLW .100
    ADDWF TEMP_L,F
    BTFSC STATUS,C
    INCF TEMP_H
    DECFSZ TEMP,F
    GOTO ZIPYUZ

    YON DECF FSR,F
    MOVF INDF,W
    XORLW 'R'
    BTFSS STATUS,Z
    GOTO D1
    BSF MOTOR_DIR ;YON BILGISI
    GOTO DON1

    D1 MOVF INDF,W
    XORLW 'L'
    BTFSS STATUS,Z
    GOTO CIK
    BCF MOTOR_DIR ;YON BILGISI

    DON1 MOVF TEMP_H,W
    ADDWF TEMP_L
    BTFSC STATUS,Z
    GOTO CIK

    DON2 CLRWDT
    BCF MOTOR_ENABLE
    BSF MOTOR_STEP
    BCF LED
    CALL BEKLEHIZ
    BCF MOTOR_STEP
    BSF LED
    CALL BEKLEHIZ

    DECF TEMP_L,F
    MOVF TEMP_L,W
    XORLW .255
    BTFSS STATUS,Z
    GOTO DON2
    DECF TEMP_H,F
    MOVF TEMP_H,W
    XORLW .255
    BTFSS STATUS,Z
    GOTO DON2

    CIK CALL InitRxBuffer
    CALL InitTxBuffer
    BCF ReceivedCR
    MOVLW 'I'
    call PutTxBuffer
    MOVLW 'S'
    call PutTxBuffer
    MOVLW 'L'
    call PutTxBuffer
    MOVLW 'E'
    call PutTxBuffer
    MOVLW 'M'
    call PutTxBuffer
    MOVLW ' '
    call PutTxBuffer
    MOVLW 'T'
    call PutTxBuffer
    MOVLW 'A'
    call PutTxBuffer
    MOVLW 'M'
    call PutTxBuffer
    MOVLW 'A'
    call PutTxBuffer
    MOVLW 'M'
    call PutTxBuffer
    MOVLW '.'
    call PutTxBuffer
    MOVLW '.'
    call PutTxBuffer
    MOVLW '.'
    call PutTxBuffer
    MOVLW .13
    call PutTxBuffer
    MOVLW .10
    call PutTxBuffer
    CALL BEKLE1SN
    GOTO MainLoop
    Main:
    BANKSEL T1CON ;
    MOVLW B'00110001'
    MOVWF T1CON

    BANKSEL T2CON ;
    MOVLW B'11111111'
    MOVWF T2CON

    BANKSEL PORTA
    call SetupSerial ;set up serial port and buffers
    CLRF PORTB
    BANKSEL BAUDCTL
    bsf STATUS,7
    CLRF ANSEL
    CLRF ANSELH
    movlw B'00000000' ; B'00001000
    movwf BAUDCTL
    BCF STATUS,7
    BANKSEL TRISB
    MOVLW B'00000000'
    MOVWF TRISB
    MOVLW B'00000000'
    MOVWF TRISA
    movlw B'10111010' ;0xc0 ;set tris bits for TX and RX
    MOVWF TRISC
    BCF OPTION_REG,5
    BCF OPTION_REG,3
    BCF OPTION_REG,0
    BANKSEL PORTA
    CLRF PORTB
    CLRF FLAG_CEVAP
    call InitTxBuffer ;initialize transmit buffer
    call InitRxBuffer ;initialize transmit buffer
    GOTO MainLoop
    ;*******************************************************

    ;**********************************************************

    MAIN1 BCF STATUS,7
    Bank1 ;select bank 1
    bsf PIE1,RCIE ;ENABLE receive interrupt
    Bank0 ;select bank 0
    CLRWDT
    goto MainLoop ;repeat main loop to check for data

    ;----------------------------------------------------------------------------
    ;Set up serial port and buffers.

    SetupSerial:
    Bank1 ;select bank 1
    movlw B'10111010' ;0xc0 ;set tris bits for TX and RX
    MOVWF TRISC
    movlw SPBRG_VAL ;set baud rate
    movwf SPBRG
    movlw b'00100000' ;115200=00100100 24 enable transmission and high baud rate
    movwf TXSTA
    Bank0 ;select bank0
    movlw b'10010000' ;enable serial port and reception
    movwf RCSTA
    clrf Flags ;clear all flag bits

    call InitTxBuffer ;initialize transmit buffer
    call InitRxBuffer ;initialize receive buffer

    movlw 0xc0 ;enable global and peripheral ints
    movwf INTCON
    Bank1 ;select bank1
    movlw 0x30 ;enable TX and RX interrupts
    movwf PIE1
    return
    ;----------------------------------------------------------------------------
    ;Initialize transmit buffer

    InitTxBuffer: Bank0
    movlw LOW TxBuffer ;take address of transmit buffer
    movwf TxStartPtr ;and place in transmit start pointer
    movwf TxEndPtr ;and place in transmit end pointer
    bcf Flags,TxBufFull ;indicate Tx buffer is not full
    bsf Flags,TxBufEmpty ;indicate Tx buffer is empty
    return

    ;----------------------------------------------
    ;Initialize receive buffer

    InitRxBuffer: Bank0
    movlw LOW RxBuffer ;take address of receive buffer
    movwf RxStartPtr ;and place in receive start pointer
    movwf RxEndPtr ;and place in receive end pointer
    bcf Flags,RxBufFull ;indicate Rx buffer is not full
    bsf Flags,RxBufEmpty ;indicate Rx buffer is empty
    return

    ;----------------------------------------------
    ;Add a byte (from WREG) to the end of the transmit buffer

    PutTxBuffer:
    Bank1 ;select bank 1
    bcf PIE1,TXIE ;disable transmit interrupt
    Bank0 ;select bank 0
    btfsc Flags,TxBufFull ;check if buffer full
    goto ErrTxBufFull ;and go handle error if full

    BANKISEL TxBuffer ;bank bit for indirect addressing
    movwf BufferData ;save WREG data into BufferData
    movf TxEndPtr,W ;get EndPointer
    movwf FSR ;and place into FSR
    movf BufferData,W ;get BufferData
    movwf INDF ;and store in buffer

    ;test if buffer pointer needs to wrap around to beginning of buffer memory

    movlw LOW TxBuffer+TX_BUF_LEN-1 ;get last address of buffer
    xorwf TxEndPtr,W ;and compare with end pointer
    movlw LOW TxBuffer ;load first address of buffer
    btfss STATUS,Z ;check if pointer is at last address
    incf TxEndPtr,W ;if not then increment pointer
    movwf TxEndPtr ;store new end pointer value

    ;test if buffer is full

    subwf TxStartPtr,W ;compare with start pointer
    btfsc STATUS,Z ;check if the same
    bsf Flags,TxBufFull ;if so then indicate buffer full
    bcf Flags,TxBufEmpty ;buffer cannot be empty
    Bank1 ;select bank 1
    bsf PIE1,TXIE ;enable transmit interrupt
    Bank0 ;select bank 0
    BCF STATUS,7
    return

    ;error because attempting to store new data and the buffer is full
    ;can do special error handling here - this code simply ignores the byte

    ErrTxBufFull: Bank1 ;select bank 1
    bsf PIE1,TXIE ;enable transmit interrupt
    Bank0 ;select bank 0
    BCF STATUS,7
    return ;no save of data because buffer full

    ;----------------------------------------------
    ;Add a byte (from WREG) to the end of the receive buffer

    PutRxBuffer:; Bank0 ;select bank 0
    BANKISEL RxBuffer ;bank bit for indirect addressing
    movwf BufferData ;save WREG into BufferData
    movf RxEndPtr,W ;get EndPointer
    movwf FSR ;and place into FSR
    movf BufferData,W ;get BufferData
    movwf INDF ;store in buffer

    ;test if buffer pointer needs to wrap around to beginning of buffer memory

    movlw LOW RxBuffer+RX_BUF_LEN-1 ;get last address of buffer
    xorwf RxEndPtr,W ;and compare with end pointer
    btfsC STATUS,Z ;check if pointer is at last address
    GOTO SIL
    incf RxEndPtr,f ;if not then increment pointer
    RETURN
    SIL ; CALL InitRxBuffer ;test if buffer is full
    movlw 0E0H ;GELEN BILGININ BASI ILE SONU ALINIYOR
    movwf RxEndPtr ;and place in receive end pointer
    bcf Flags,RxBufFull ;indicate Rx buffer is not full
    bsf Flags,RxBufEmpty ;indicate Rx buffer is empty
    return

    ;error because attempting to store new data and the buffer is full
    ;can do special error handling here - this code simply ignores the byte

    ErrRxBufFull: return ;no save of data because buffer full

    ;----------------------------------------------
    ;Remove and return (in WREG) the byte at the start of the transmit buffer

    GetTxBuffer: Bank0 ;select bank 0
    btfsc Flags,TxBufEmpty ;check if transmit buffer empty
    goto ErrTxBufEmpty ;and go handle error if empty

    BANKISEL TxBuffer ;bank bit for indirect addressing
    movf TxStartPtr,W ;get StartPointer
    movwf FSR ;and place into FSR

    ;test if buffer pointer needs to wrap around to beginning of buffer memory

    movlw LOW TxBuffer+TX_BUF_LEN-1 ;get last address of buffer
    xorwf TxStartPtr,W ;and compare with start pointer
    movlw LOW TxBuffer ;load first address of buffer
    btfss STATUS,Z ;check if pointer is at last address
    incf TxStartPtr,W ;if not then increment pointer
    movwf TxStartPtr ;store new pointer value
    bcf Flags,TxBufFull ;buffer cannot be full

    ;test if buffer is now empty

    xorwf TxEndPtr,W ;compare start to end
    btfsc STATUS,Z ;check if the same
    bsf Flags,TxBufEmpty ;if same then buffer will be empty
    movf INDF,W ;get data from buffer

    return

    ;error because attempting to read data from an empty buffer
    ;can do special error handling here - this code simply returns zero

    ErrTxBufEmpty: retlw 0 ;tried to read empty buffer

    ;----------------------------------------------
    ;Remove and return (in WREG) the byte at the start of the receive buffer

    GetRxBuffer: Bank0 ;select bank 0
    btfsc Flags,RxBufEmpty ;check if receive buffer empty
    goto ErrRxBufEmpty ;and go handle error if empty

    Bank1 ;select bank 1
    ; bcf PIE1,RCIE ;disable receive interrupt
    Bank0 ;select bank 0

    BANKISEL RxBuffer ;bank bit for indirect addressing
    movf RxStartPtr,W ;get StartPointer
    movwf FSR ;and place into FSR

    ;test if buffer pointer needs to wrap around to beginning of buffer memory

    movlw LOW RxBuffer+RX_BUF_LEN-1 ;get last address of buffer
    xorwf RxStartPtr,W ; and compare with start pointer
    movlw LOW RxBuffer ;load first address of buffer
    btfss STATUS,Z ;check if pointer is at last address
    incf RxStartPtr,W ;if not then increment pointer
    movwf RxStartPtr ;store new pointer value
    bcf Flags,RxBufFull ;buffer cannot be full

    ;test if buffer is now empty

    xorwf RxEndPtr,W ;compare start to end
    btfsc STATUS,Z ;check if the same
    bsf Flags,RxBufEmpty ;if same then buffer will be empty
    movf INDF,W ;get data from buffer

    Bank1 ;select bank 1
    bsf PIE1,RCIE ;enable receive interrupt
    Bank0 ;select bank 0
    return

    ;error because attempting to read data from an empty buffer
    ;can do special error handling here - this code simply returns zero

    ErrRxBufEmpty: Bank1 ;select bank 1
    bsf PIE1,RCIE ;enable receive interrupt
    Bank0 ;select bank 0
    retlw 0 ;tried to read empty buffer

    ;---------------------------------------------------------------

    ;*************************
    BEKLE1SN CLRF TEMP2
    CLRF TEMP3
    CLRF TMR1L
    MOVLW .20
    MOVWF TEMP1


    B11 CLRWDT
    DECFSZ TEMP2,F
    GOTO B11
    DECFSZ TEMP3,F
    GOTO B11



    DECFSZ TEMP1,F
    GOTO B11
    RETLW 0
    BEKLE500MS CLRF TEMP2
    CLRF TEMP3
    CLRF TMR1L
    MOVLW .10
    MOVWF TEMP1

    B111 CLRWDT
    DECFSZ TEMP2,F
    GOTO B111
    DECFSZ TEMP3,F
    GOTO B111

    DECFSZ TEMP1,F
    GOTO B111
    RETLW 0
    ;*****************************************************
    ;*****************************************************
    BEKLE5SN NOP
    CLRF TMR1H
    CLRF TMR1L
    MOVLW .96
    MOVWF TEMP1
    B101 CLRWDT
    BTFSS TMR1H,7
    GOTO B101
    CLRF TMR1H
    DECFSZ TEMP1,F
    GOTO B101
    RETLW 0
    ;*****************************************************


    ;****************************************************************
    BEKLEHIZ MOVLW M_HIZ
    MOVWF TEMP1
    MOVLW .25
    MOVWF TEMP
    B1H CLRWDT
    DECFSZ TEMP,F
    GOTO B1H
    MOVLW .25
    MOVWF TEMP
    DECFSZ TEMP1,F
    GOTO B1H
    RETURN
    ;**************************************************************


    END
     
Yüklüyor...

Sayfayı Paylaş