efsanepold
Üye
- Katılım
- 8 Nis 2009
- Mesajlar
- 10
- Puanları
- 1
- Yaş
- 53
Selam arkadaşlar. Udeanın UFM-A12 WPA rf modülünü kullanmak istiyorum. Fakat yazdığım kodlar ile bir sonuç alamadım. Hata nerede yardımcı olursanız sevinirim. Kodlar aşağıdadır.
;***********************************************************************************
;
;usart modulu ile asenkron iletisim(verici)
;
;***********************************************************************************
LIST P=16F877A
INCLUDE <P16F877A.INC>
__config h'0A01'
cblock h'20'
TX_data
sayac1
sayac2
count
temp
endc
ORG 0X00
goto start
start
bcf STATUS,RP1
bsf STATUS,RP0 ; Bank 1 seç
banksel TRISB
movlw b'00000011'
movwf TRISB
banksel TRISD
clrf TRISD
banksel PORTD
clrf PORTD
banksel TRISA
clrf TRISA
banksel TRISC
bcf TRISC,6
movlw .103
movwf SPBRG
movlw 0x26
movwf TXSTA
movlw 0x90
bcf STATUS,RP0
movwf RCSTA
bsf STATUS,RP0
bcf PIE1,TXIE
bsf PIE1,RCIE
bcf STATUS,RP1
bcf STATUS,RP0 ; Bank 0 seç
movlw 0x05
movwf temp
;***************************************************
check_bt0
btfsc PORTB,0
goto check_bt1
clrf count
call send_start
check_bt1
btfsc PORTB,1
goto check_bt0
clrf count
call send_stop
goto check_bt0
;*****************************************************
send_start
movf count,w
call data_start
movwf TX_data
call _send
incf count,f
movlw 0x12
xorwf count,w
btfss STATUS,Z
goto send_start
clrf count
bsf PORTA,0
call delay
call delay
bcf PORTA,0
decfsz temp,f
goto send_start
movlw 0x05
movwf temp
return
;***********************************************
send_stop
movf count,w
call data_stop
movwf TX_data
call _send
incf count,f
movlw 0x12
xorwf count,w
btfss STATUS,Z
goto send_stop
clrf count
bsf PORTA,0
call delay
call delay
bcf PORTA,0
decfsz temp,f
goto send_stop
movlw 0x05
movwf temp
return
;***********************************************
_send
banksel PIR1
btfss PIR1,TXIF
goto $-1
bcf PIR1,TXIF
movf TX_data,w
banksel TXREG
movwf TXREG
return
;*************************************************
data_start
ADDWF PCL,f ; Modify program counter
RETLW 0x24;$
RETLW 0x52;R
RETLW 0x46;F
RETLW 0x50;P
RETLW 0x4F;O
RETLW 0x4C;L
RETLW 0x44;D
RETLW 0x45;E
RETLW 0x4D;M
RETLW 0x2E;.
RETLW 0x4C;L
RETLW 0x54;T
RETLW 0x44;D
RETLW 0x45;E
RETLW 0x4E;N
RETLW 0x44;D
RETLW 0x0D;CR
RETLW 0x0A;LR
;***************************************************
data_stop
ADDWF PCL,f
RETLW 0x24;$ ;pcl 12
RETLW 0x52;R
RETLW 0x46;F
RETLW 0x4D;M
RETLW 0x45;E
RETLW 0x44;D
RETLW 0x4C;L
RETLW 0x4F;O
RETLW 0x50;P
RETLW 0x2E;.
RETLW 0x44;D
RETLW 0x54;T
RETLW 0x4C;L
RETLW 0x45;E
RETLW 0x4E;N
RETLW 0x44;D
RETLW 0x0D;CR
RETLW 0x0A;LR
;***************************************************
delay
movlw h'ff'
movwf sayac1
dongu1
movlw h'ff'
movwf sayac2
dongu2
decfsz sayac2,F
goto dongu2
decfsz sayac1,F
goto dongu1
return
end
;***********************************************************************************
;
;usart modulu ile asenkron iletisim(alıcı)
;
;***********************************************************************************
LIST P=16F877A
INCLUDE <P16F877A.INC>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _LVP_OFF & _DEBUG_OFF & _CPD_OFF
LCD_DATA EQU PORTB
LCD_DATA_TRIS EQU TRISB
LCD_LINE0 EQU 0x000
LCD_LINE1 EQU 0x040
cblock h'20'
LCD_TEMP ; LCD alt programlarında kullanıyoruz
TABLE_INDEX ; Tablo satırlarını tutmak için
COUNT ; Sayaç için
DELAY ; DELAYxxx gecikme fonksiyonu için
X_DELAY ; X_DELAYxxx gecikme fonksiyonu için
sayac1
sayac2
rx_data
count
flags
reg_1
reg_2
reg_3
reg_4
reg_5
reg_6
reg_7
reg_8
reg_9
reg_10
reg_11
reg_12
reg_13
reg_14
reg_15
reg_16
reg_17
reg_18
WREG_TEMP
STATUS_TEMP
PCLATH_TEMP
endc
;************************************************************************************
;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 LCD_RW PORTD,6
#define LCD_RS PORTD,5
#define LCD_E PORTD,7
ORG 0x0000
clrf PCLATH
goto start
org 0x0004
movwf WREG_TEMP ;save WREG
movf STATUS,W ;store STATUS in WREG
clrf STATUS ;change to file register bank0
movwf STATUS_TEMP ;save STATUS value
movf PCLATH,W ;store PCLATH in WREG
movwf PCLATH_TEMP ;save PCLATH value
clrf PCLATH ;change to program memory page0
receive
Bank0
btfss PIR1,RCIF ;test RCIF receive interrupt
goto receive
movf RCREG,w ;get received data
movwf rx_data
movlw 0x00
xorwf count,w
btfss STATUS,Z
goto int_1
incf count,f
movf rx_data,w
movwf reg_1
goto int_sonu
int_1
movlw 0x01
xorwf count,w
btfss STATUS,Z
goto int_2
incf count,f
movf rx_data,w
movwf reg_2
goto int_sonu
int_2
movlw 0x02
xorwf count,w
btfss STATUS,Z
goto int_3
incf count,f
movf rx_data,w
movwf reg_3
goto int_sonu
int_3
movlw 0x03
xorwf count,w
btfss STATUS,Z
goto int_4
incf count,f
movf rx_data,w
movwf reg_4
goto int_sonu
int_4
movlw 0x04
xorwf count,w
btfss STATUS,Z
goto int_5
incf count,f
movf rx_data,w
movwf reg_5
goto int_sonu
int_5
movlw 0x05
xorwf count,w
btfss STATUS,Z
goto int_6
incf count,f
movf rx_data,w
movwf reg_6
goto int_sonu
int_6
movlw 0x06
xorwf count,w
btfss STATUS,Z
goto int_7
incf count,f
movf rx_data,w
movwf reg_7
goto int_sonu
int_7
movlw 0x07
xorwf count,w
btfss STATUS,Z
goto int_8
incf count,f
movf rx_data,w
movwf reg_8
goto int_sonu
int_8
movlw 0x08
xorwf count,w
btfss STATUS,Z
goto int_9
incf count,f
movf rx_data,w
movwf reg_9
goto int_sonu
int_9
movlw 0x09
xorwf count,w
btfss STATUS,Z
goto int_10
incf count,f
movf rx_data,w
movwf reg_10
goto int_sonu
int_10
movlw 0x0A
xorwf count,w
btfss STATUS,Z
goto int_11
incf count,f
movf rx_data,w
movwf reg_11
goto int_sonu
int_11
movlw 0x0B
xorwf count,w
btfss STATUS,Z
goto int_12
incf count,f
movf rx_data,w
movwf reg_12
goto int_sonu
int_12
movlw 0x0C
xorwf count,w
btfss STATUS,Z
goto int_13
incf count,f
movf rx_data,w
movwf reg_13
goto int_sonu
int_13
movlw 0x0D
xorwf count,w
btfss STATUS,Z
goto int_14
incf count,f
movf rx_data,w
movwf reg_14
goto int_sonu
int_14
movlw 0x0E
xorwf count,w
btfss STATUS,Z
goto int_15
incf count,f
movf rx_data,w
movwf reg_15
goto int_sonu
int_15
movlw 0x0F
xorwf count,w
btfss STATUS,Z
goto int_16
incf count,f
movf rx_data,w
movwf reg_16
goto int_sonu
int_16
movlw 0x11
xorwf count,w
btfss STATUS,Z
goto int_17
incf count,f
movf rx_data,w
movwf reg_17
goto int_sonu
int_17
movlw 0x12
xorwf count,w
btfss STATUS,Z
goto int_sonu
movf rx_data,w
movwf reg_18
int_sonu
Bank0
bcf PIR1,RCIF
clrf STATUS ;select bank 0
movf PCLATH_TEMP,W ;store saved PCLATH value in WREG
movwf PCLATH ;restore PCLATH
movf STATUS_TEMP,W ;store saved STATUS value in WREG
movwf STATUS ;restore STATUS
swapf WREG_TEMP,F ;prepare WREG to be restored
swapf WREG_TEMP,W ;restore WREG keeping STATUS bits
retfie
;******************************************************
start
Bank1
MOVLW 0x06
MOVWF ADCON1 ; all digital I/O
clrf TRISA
clrf TRISB
clrf TRISD
clrf TRISE
movlw b'10000000'
movwf TRISC
Bank1
movlw .103 ;4 mhz. 2400 baud rate
movwf SPBRG
movlw 0x24
movwf TXSTA
Bank0
movlw 0x90
movwf RCSTA
; bsf STATUS,RP0
; bcf PIE1,TXIE ;USART gönderme kesmesini aktifleştirir
Bank1
bsf PIE1,RCIE ;USART alma kesmesini aktifleştir
bsf INTCON,PEIE
bsf INTCON,GIE
clrf count
clrf rx_data
clrf reg_1
clrf reg_2
clrf reg_3
clrf PORTA
movlw 0x24
call _send
movlw 0x43
call _send
movlw 0x31
call _send
call delay
call delay
;*************************************************
;*************************************************
main
CALL LCDINIT ; Initialize LCDisplay
call LCDCLEAR
CALL MSG_1
wait
goto wait
;*************************************************
;*************************************************
_send
movwf TXREG
banksel PIR1
btfss PIR1,TXIF
goto $-1
bcf PIR1,TXIF
return
;=============================================================================
; LCDINIT
; LCD açılış rutini
; İsteğe göre değiştirilebilir(örneğin kürsör açık/kapalı vb.)
; Tablo 2 den komutlara bakınız.
;=============================================================================
LCDINIT
; Meşgul bayrağı henüz geçerli değil
BCF LCD_RS ; PORTA çıkışlarının tümü düşük.
BCF LCD_RW ; power-up gecikmesi
BCF LCD_E
MOVLW 0x01E
CALL X_DELAY500 ; 30 * 0.5mS = 15mS
; Meşgul bayrağı artık geçerli
MOVLW 0x038 ; 8-bit-arayüz, 2-satır
CALL LCDPUTCMD
MOVLW 0x000 ; disp. kapat, kürs. kapat, blink kapat
CALL LCDDMODE
CALL LCDCLEAR
MOVLW 0x004 ; disp.aç, kürs.kapat
CALL LCDDMODE
MOVLW 0x002 ; otomatik artış (shift-cursor)
CALL LCDEMODE
RETURN
;=============================================================================
; LCDBUSY
; Meşgul bayrağının busy-flag pasif olduğunu
;=============================================================================
LCDBUSY
bcf STATUS,RP1
bsf STATUS,RP0 ; Bank 1 seç
MOVLW 0x0FF ; PORTB giriş için ayarla
MOVWF LCD_DATA_TRIS
bcf STATUS,RP1
bcf STATUS,RP0 ; Bank 0 seç
BCF LCD_RS ; Komut saklıyıcısı seç
BSF LCD_RW ; Meşgul bayrağını okumaya ayarla
BSF LCD_E ; LCD E hattı yüksek yap
MOVF LCD_DATA, W ; Meşgul bayrağını oku
BCF LCD_E ; LCD E hattı düşük
ANDLW 0x80 ; Meşgul bayrağını kontrol et, Yüksek = Meşgul
BTFSS STATUS, Z
GOTO LCDBUSY
LCDNOTBUSY BCF LCD_RW
bcf STATUS,RP1
bsf STATUS,RP0 ; Bank 1 seç
MOVLW 0x000
MOVWF LCD_DATA_TRIS ; PORTB çıkış
bcf STATUS,RP1
bcf STATUS,RP0 ; Bank 0 seç
RETURN
;=============================================================================
; LCDCLEAR
; Paneli temizle ve kürsörü başa al (sol-üst köşe).
;
;=============================================================================
LCDCLEAR
MOVLW 0x001
CALL LCDPUTCMD
RETURN
;=============================================================================
; LCDEMODE
; Sets entry mode of display.
; Required entry mode must be set in W
; b0 : 0 = no display shift 1 = display shift
; b1 : 0 = auto-decrement 1 = auto-increment
; b2-7 : don't care
; OK
;=============================================================================
LCDEMODE
ANDLW 0x003 ; Strip upper bits
IORLW 0x004 ; Function set
CALL LCDPUTCMD
RETURN
;=============================================================================
; LCDDMODE
; Sets display control.
; Required display mode must be set in W
; b0 : 0 = cursor blink off 1 = cursor blink on
; b1 : 0 = cursor off 1 = cursor on
; b2 : 0 = display off 1 = display on (display data remains in DDRAM)
; b3-7 : don't care
; OK
;=============================================================================
LCDDMODE
ANDLW 0x007 ; Strip upper bits
IORLW 0x008 ; Function set
CALL LCDPUTCMD
RETURN
;=============================================================================
; LCDSDDA
; Sets the Display-Data-RAM address. DDRAM data is read/written after
; this setting.
; Required DDRAM address must be set in W
; b0-6 : required DDRAM address
; b7 : don't care
; OK
;=============================================================================
LCDSDDA
IORLW 0x080 ; Function set
CALL LCDPUTCMD
RETURN
;=============================================================================
LCDPUTCHAR
MOVWF LCD_TEMP ; W deki karekteri geçici değişkene at
CALL LCDBUSY ; LCD hazır olana kadar bekle
BCF LCD_RW; LCD okuma moduna al
BSF LCD_RS; Veri saklayıcısı seç
BSF LCD_E ; LCD E-hattı Yüksek
MOVF LCD_TEMP, W ; Geçici değişkeni tekrar W ye aktar
MOVWF LCD_DATA ; LCD ye veriyi gönder
BCF LCD_E ; LCD E-hattı düşük
RETURN
;=============================================================================
; LCDPUTCMD
; W deki komutu LCD ye gönderir
;=============================================================================
LCDPUTCMD
MOVWF LCD_TEMP ; W deki komutu geçici değişkene at
CALL LCDBUSY ; LCD hazır olana kadar bekle
BCF LCD_RW ; LCD okuma moduna al
BCF LCD_RS ; Komut saklayıcısı seç
BSF LCD_E ; LCD E-hattı yüksek
MOVF LCD_TEMP, W ; Geçici değişkeni tekrar W ye yükle
MOVWF LCD_DATA ; LCD ye komudu gönder
BCF LCD_E ; LCD E-hattı düşük
RETURN
;*****************************************************************************
;Gecikme rutinleri
;*****************************************************************************
DELAY500 MOVLW D'165' ; +1 1 cycle
MOVWF DELAY ; +2 1 cycle
DELAY500_LOOP DECFSZ DELAY, F ; step 1 1 cycle
GOTO DELAY500_LOOP ; step 2 2 cycles
DELAY500_END RETURN ; +3 2 cycles
X_DELAY500 MOVWF X_DELAY ; +1 1 cycle
X_DELAY500_LOOP CALL DELAY500 ; step1 wait 500uSec
DECFSZ X_DELAY, F ; step2 1 cycle
GOTO X_DELAY500_LOOP ; step3 2 cycles
X_DELAY500_END RETURN ; +2 2 cycles
;*****************************************************************************
MSG_1
MOVLW 0x000 ; 1. Satırın adresini W ye yükle
CALL LCDSDDA ; Kürsörü W deki satıra ve sol başa al
movf reg_1,w
CALL LCDPUTCHAR
movf reg_2,w
CALL LCDPUTCHAR
movf reg_3,w
CALL LCDPUTCHAR
movf reg_4,w
CALL LCDPUTCHAR
movf reg_5,w
CALL LCDPUTCHAR
movf reg_6,w
CALL LCDPUTCHAR
movf reg_7,w
CALL LCDPUTCHAR
movf reg_8,w
CALL LCDPUTCHAR
movf reg_9,w
CALL LCDPUTCHAR
movf reg_10,w
CALL LCDPUTCHAR
movf reg_11,w
CALL LCDPUTCHAR
movf reg_12,w
CALL LCDPUTCHAR
movf reg_13,w
CALL LCDPUTCHAR
movf reg_14,w
CALL LCDPUTCHAR
movf reg_15,w
CALL LCDPUTCHAR
movf reg_16,w
CALL LCDPUTCHAR
RETURN
;******************************************************
delay
movlw h'ff'
movwf sayac1
dongu1
movlw h'ff'
movwf sayac2
dongu2
decfsz sayac2,F
goto dongu2
decfsz sayac1,F
goto dongu1
return
end
;***********************************************************************************
;
;usart modulu ile asenkron iletisim(verici)
;
;***********************************************************************************
LIST P=16F877A
INCLUDE <P16F877A.INC>
__config h'0A01'
cblock h'20'
TX_data
sayac1
sayac2
count
temp
endc
ORG 0X00
goto start
start
bcf STATUS,RP1
bsf STATUS,RP0 ; Bank 1 seç
banksel TRISB
movlw b'00000011'
movwf TRISB
banksel TRISD
clrf TRISD
banksel PORTD
clrf PORTD
banksel TRISA
clrf TRISA
banksel TRISC
bcf TRISC,6
movlw .103
movwf SPBRG
movlw 0x26
movwf TXSTA
movlw 0x90
bcf STATUS,RP0
movwf RCSTA
bsf STATUS,RP0
bcf PIE1,TXIE
bsf PIE1,RCIE
bcf STATUS,RP1
bcf STATUS,RP0 ; Bank 0 seç
movlw 0x05
movwf temp
;***************************************************
check_bt0
btfsc PORTB,0
goto check_bt1
clrf count
call send_start
check_bt1
btfsc PORTB,1
goto check_bt0
clrf count
call send_stop
goto check_bt0
;*****************************************************
send_start
movf count,w
call data_start
movwf TX_data
call _send
incf count,f
movlw 0x12
xorwf count,w
btfss STATUS,Z
goto send_start
clrf count
bsf PORTA,0
call delay
call delay
bcf PORTA,0
decfsz temp,f
goto send_start
movlw 0x05
movwf temp
return
;***********************************************
send_stop
movf count,w
call data_stop
movwf TX_data
call _send
incf count,f
movlw 0x12
xorwf count,w
btfss STATUS,Z
goto send_stop
clrf count
bsf PORTA,0
call delay
call delay
bcf PORTA,0
decfsz temp,f
goto send_stop
movlw 0x05
movwf temp
return
;***********************************************
_send
banksel PIR1
btfss PIR1,TXIF
goto $-1
bcf PIR1,TXIF
movf TX_data,w
banksel TXREG
movwf TXREG
return
;*************************************************
data_start
ADDWF PCL,f ; Modify program counter
RETLW 0x24;$
RETLW 0x52;R
RETLW 0x46;F
RETLW 0x50;P
RETLW 0x4F;O
RETLW 0x4C;L
RETLW 0x44;D
RETLW 0x45;E
RETLW 0x4D;M
RETLW 0x2E;.
RETLW 0x4C;L
RETLW 0x54;T
RETLW 0x44;D
RETLW 0x45;E
RETLW 0x4E;N
RETLW 0x44;D
RETLW 0x0D;CR
RETLW 0x0A;LR
;***************************************************
data_stop
ADDWF PCL,f
RETLW 0x24;$ ;pcl 12
RETLW 0x52;R
RETLW 0x46;F
RETLW 0x4D;M
RETLW 0x45;E
RETLW 0x44;D
RETLW 0x4C;L
RETLW 0x4F;O
RETLW 0x50;P
RETLW 0x2E;.
RETLW 0x44;D
RETLW 0x54;T
RETLW 0x4C;L
RETLW 0x45;E
RETLW 0x4E;N
RETLW 0x44;D
RETLW 0x0D;CR
RETLW 0x0A;LR
;***************************************************
delay
movlw h'ff'
movwf sayac1
dongu1
movlw h'ff'
movwf sayac2
dongu2
decfsz sayac2,F
goto dongu2
decfsz sayac1,F
goto dongu1
return
end
;***********************************************************************************
;
;usart modulu ile asenkron iletisim(alıcı)
;
;***********************************************************************************
LIST P=16F877A
INCLUDE <P16F877A.INC>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _LVP_OFF & _DEBUG_OFF & _CPD_OFF
LCD_DATA EQU PORTB
LCD_DATA_TRIS EQU TRISB
LCD_LINE0 EQU 0x000
LCD_LINE1 EQU 0x040
cblock h'20'
LCD_TEMP ; LCD alt programlarında kullanıyoruz
TABLE_INDEX ; Tablo satırlarını tutmak için
COUNT ; Sayaç için
DELAY ; DELAYxxx gecikme fonksiyonu için
X_DELAY ; X_DELAYxxx gecikme fonksiyonu için
sayac1
sayac2
rx_data
count
flags
reg_1
reg_2
reg_3
reg_4
reg_5
reg_6
reg_7
reg_8
reg_9
reg_10
reg_11
reg_12
reg_13
reg_14
reg_15
reg_16
reg_17
reg_18
WREG_TEMP
STATUS_TEMP
PCLATH_TEMP
endc
;************************************************************************************
;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 LCD_RW PORTD,6
#define LCD_RS PORTD,5
#define LCD_E PORTD,7
ORG 0x0000
clrf PCLATH
goto start
org 0x0004
movwf WREG_TEMP ;save WREG
movf STATUS,W ;store STATUS in WREG
clrf STATUS ;change to file register bank0
movwf STATUS_TEMP ;save STATUS value
movf PCLATH,W ;store PCLATH in WREG
movwf PCLATH_TEMP ;save PCLATH value
clrf PCLATH ;change to program memory page0
receive
Bank0
btfss PIR1,RCIF ;test RCIF receive interrupt
goto receive
movf RCREG,w ;get received data
movwf rx_data
movlw 0x00
xorwf count,w
btfss STATUS,Z
goto int_1
incf count,f
movf rx_data,w
movwf reg_1
goto int_sonu
int_1
movlw 0x01
xorwf count,w
btfss STATUS,Z
goto int_2
incf count,f
movf rx_data,w
movwf reg_2
goto int_sonu
int_2
movlw 0x02
xorwf count,w
btfss STATUS,Z
goto int_3
incf count,f
movf rx_data,w
movwf reg_3
goto int_sonu
int_3
movlw 0x03
xorwf count,w
btfss STATUS,Z
goto int_4
incf count,f
movf rx_data,w
movwf reg_4
goto int_sonu
int_4
movlw 0x04
xorwf count,w
btfss STATUS,Z
goto int_5
incf count,f
movf rx_data,w
movwf reg_5
goto int_sonu
int_5
movlw 0x05
xorwf count,w
btfss STATUS,Z
goto int_6
incf count,f
movf rx_data,w
movwf reg_6
goto int_sonu
int_6
movlw 0x06
xorwf count,w
btfss STATUS,Z
goto int_7
incf count,f
movf rx_data,w
movwf reg_7
goto int_sonu
int_7
movlw 0x07
xorwf count,w
btfss STATUS,Z
goto int_8
incf count,f
movf rx_data,w
movwf reg_8
goto int_sonu
int_8
movlw 0x08
xorwf count,w
btfss STATUS,Z
goto int_9
incf count,f
movf rx_data,w
movwf reg_9
goto int_sonu
int_9
movlw 0x09
xorwf count,w
btfss STATUS,Z
goto int_10
incf count,f
movf rx_data,w
movwf reg_10
goto int_sonu
int_10
movlw 0x0A
xorwf count,w
btfss STATUS,Z
goto int_11
incf count,f
movf rx_data,w
movwf reg_11
goto int_sonu
int_11
movlw 0x0B
xorwf count,w
btfss STATUS,Z
goto int_12
incf count,f
movf rx_data,w
movwf reg_12
goto int_sonu
int_12
movlw 0x0C
xorwf count,w
btfss STATUS,Z
goto int_13
incf count,f
movf rx_data,w
movwf reg_13
goto int_sonu
int_13
movlw 0x0D
xorwf count,w
btfss STATUS,Z
goto int_14
incf count,f
movf rx_data,w
movwf reg_14
goto int_sonu
int_14
movlw 0x0E
xorwf count,w
btfss STATUS,Z
goto int_15
incf count,f
movf rx_data,w
movwf reg_15
goto int_sonu
int_15
movlw 0x0F
xorwf count,w
btfss STATUS,Z
goto int_16
incf count,f
movf rx_data,w
movwf reg_16
goto int_sonu
int_16
movlw 0x11
xorwf count,w
btfss STATUS,Z
goto int_17
incf count,f
movf rx_data,w
movwf reg_17
goto int_sonu
int_17
movlw 0x12
xorwf count,w
btfss STATUS,Z
goto int_sonu
movf rx_data,w
movwf reg_18
int_sonu
Bank0
bcf PIR1,RCIF
clrf STATUS ;select bank 0
movf PCLATH_TEMP,W ;store saved PCLATH value in WREG
movwf PCLATH ;restore PCLATH
movf STATUS_TEMP,W ;store saved STATUS value in WREG
movwf STATUS ;restore STATUS
swapf WREG_TEMP,F ;prepare WREG to be restored
swapf WREG_TEMP,W ;restore WREG keeping STATUS bits
retfie
;******************************************************
start
Bank1
MOVLW 0x06
MOVWF ADCON1 ; all digital I/O
clrf TRISA
clrf TRISB
clrf TRISD
clrf TRISE
movlw b'10000000'
movwf TRISC
Bank1
movlw .103 ;4 mhz. 2400 baud rate
movwf SPBRG
movlw 0x24
movwf TXSTA
Bank0
movlw 0x90
movwf RCSTA
; bsf STATUS,RP0
; bcf PIE1,TXIE ;USART gönderme kesmesini aktifleştirir
Bank1
bsf PIE1,RCIE ;USART alma kesmesini aktifleştir
bsf INTCON,PEIE
bsf INTCON,GIE
clrf count
clrf rx_data
clrf reg_1
clrf reg_2
clrf reg_3
clrf PORTA
movlw 0x24
call _send
movlw 0x43
call _send
movlw 0x31
call _send
call delay
call delay
;*************************************************
;*************************************************
main
CALL LCDINIT ; Initialize LCDisplay
call LCDCLEAR
CALL MSG_1
wait
goto wait
;*************************************************
;*************************************************
_send
movwf TXREG
banksel PIR1
btfss PIR1,TXIF
goto $-1
bcf PIR1,TXIF
return
;=============================================================================
; LCDINIT
; LCD açılış rutini
; İsteğe göre değiştirilebilir(örneğin kürsör açık/kapalı vb.)
; Tablo 2 den komutlara bakınız.
;=============================================================================
LCDINIT
; Meşgul bayrağı henüz geçerli değil
BCF LCD_RS ; PORTA çıkışlarının tümü düşük.
BCF LCD_RW ; power-up gecikmesi
BCF LCD_E
MOVLW 0x01E
CALL X_DELAY500 ; 30 * 0.5mS = 15mS
; Meşgul bayrağı artık geçerli
MOVLW 0x038 ; 8-bit-arayüz, 2-satır
CALL LCDPUTCMD
MOVLW 0x000 ; disp. kapat, kürs. kapat, blink kapat
CALL LCDDMODE
CALL LCDCLEAR
MOVLW 0x004 ; disp.aç, kürs.kapat
CALL LCDDMODE
MOVLW 0x002 ; otomatik artış (shift-cursor)
CALL LCDEMODE
RETURN
;=============================================================================
; LCDBUSY
; Meşgul bayrağının busy-flag pasif olduğunu
;=============================================================================
LCDBUSY
bcf STATUS,RP1
bsf STATUS,RP0 ; Bank 1 seç
MOVLW 0x0FF ; PORTB giriş için ayarla
MOVWF LCD_DATA_TRIS
bcf STATUS,RP1
bcf STATUS,RP0 ; Bank 0 seç
BCF LCD_RS ; Komut saklıyıcısı seç
BSF LCD_RW ; Meşgul bayrağını okumaya ayarla
BSF LCD_E ; LCD E hattı yüksek yap
MOVF LCD_DATA, W ; Meşgul bayrağını oku
BCF LCD_E ; LCD E hattı düşük
ANDLW 0x80 ; Meşgul bayrağını kontrol et, Yüksek = Meşgul
BTFSS STATUS, Z
GOTO LCDBUSY
LCDNOTBUSY BCF LCD_RW
bcf STATUS,RP1
bsf STATUS,RP0 ; Bank 1 seç
MOVLW 0x000
MOVWF LCD_DATA_TRIS ; PORTB çıkış
bcf STATUS,RP1
bcf STATUS,RP0 ; Bank 0 seç
RETURN
;=============================================================================
; LCDCLEAR
; Paneli temizle ve kürsörü başa al (sol-üst köşe).
;
;=============================================================================
LCDCLEAR
MOVLW 0x001
CALL LCDPUTCMD
RETURN
;=============================================================================
; LCDEMODE
; Sets entry mode of display.
; Required entry mode must be set in W
; b0 : 0 = no display shift 1 = display shift
; b1 : 0 = auto-decrement 1 = auto-increment
; b2-7 : don't care
; OK
;=============================================================================
LCDEMODE
ANDLW 0x003 ; Strip upper bits
IORLW 0x004 ; Function set
CALL LCDPUTCMD
RETURN
;=============================================================================
; LCDDMODE
; Sets display control.
; Required display mode must be set in W
; b0 : 0 = cursor blink off 1 = cursor blink on
; b1 : 0 = cursor off 1 = cursor on
; b2 : 0 = display off 1 = display on (display data remains in DDRAM)
; b3-7 : don't care
; OK
;=============================================================================
LCDDMODE
ANDLW 0x007 ; Strip upper bits
IORLW 0x008 ; Function set
CALL LCDPUTCMD
RETURN
;=============================================================================
; LCDSDDA
; Sets the Display-Data-RAM address. DDRAM data is read/written after
; this setting.
; Required DDRAM address must be set in W
; b0-6 : required DDRAM address
; b7 : don't care
; OK
;=============================================================================
LCDSDDA
IORLW 0x080 ; Function set
CALL LCDPUTCMD
RETURN
;=============================================================================
LCDPUTCHAR
MOVWF LCD_TEMP ; W deki karekteri geçici değişkene at
CALL LCDBUSY ; LCD hazır olana kadar bekle
BCF LCD_RW; LCD okuma moduna al
BSF LCD_RS; Veri saklayıcısı seç
BSF LCD_E ; LCD E-hattı Yüksek
MOVF LCD_TEMP, W ; Geçici değişkeni tekrar W ye aktar
MOVWF LCD_DATA ; LCD ye veriyi gönder
BCF LCD_E ; LCD E-hattı düşük
RETURN
;=============================================================================
; LCDPUTCMD
; W deki komutu LCD ye gönderir
;=============================================================================
LCDPUTCMD
MOVWF LCD_TEMP ; W deki komutu geçici değişkene at
CALL LCDBUSY ; LCD hazır olana kadar bekle
BCF LCD_RW ; LCD okuma moduna al
BCF LCD_RS ; Komut saklayıcısı seç
BSF LCD_E ; LCD E-hattı yüksek
MOVF LCD_TEMP, W ; Geçici değişkeni tekrar W ye yükle
MOVWF LCD_DATA ; LCD ye komudu gönder
BCF LCD_E ; LCD E-hattı düşük
RETURN
;*****************************************************************************
;Gecikme rutinleri
;*****************************************************************************
DELAY500 MOVLW D'165' ; +1 1 cycle
MOVWF DELAY ; +2 1 cycle
DELAY500_LOOP DECFSZ DELAY, F ; step 1 1 cycle
GOTO DELAY500_LOOP ; step 2 2 cycles
DELAY500_END RETURN ; +3 2 cycles
X_DELAY500 MOVWF X_DELAY ; +1 1 cycle
X_DELAY500_LOOP CALL DELAY500 ; step1 wait 500uSec
DECFSZ X_DELAY, F ; step2 1 cycle
GOTO X_DELAY500_LOOP ; step3 2 cycles
X_DELAY500_END RETURN ; +2 2 cycles
;*****************************************************************************
MSG_1
MOVLW 0x000 ; 1. Satırın adresini W ye yükle
CALL LCDSDDA ; Kürsörü W deki satıra ve sol başa al
movf reg_1,w
CALL LCDPUTCHAR
movf reg_2,w
CALL LCDPUTCHAR
movf reg_3,w
CALL LCDPUTCHAR
movf reg_4,w
CALL LCDPUTCHAR
movf reg_5,w
CALL LCDPUTCHAR
movf reg_6,w
CALL LCDPUTCHAR
movf reg_7,w
CALL LCDPUTCHAR
movf reg_8,w
CALL LCDPUTCHAR
movf reg_9,w
CALL LCDPUTCHAR
movf reg_10,w
CALL LCDPUTCHAR
movf reg_11,w
CALL LCDPUTCHAR
movf reg_12,w
CALL LCDPUTCHAR
movf reg_13,w
CALL LCDPUTCHAR
movf reg_14,w
CALL LCDPUTCHAR
movf reg_15,w
CALL LCDPUTCHAR
movf reg_16,w
CALL LCDPUTCHAR
RETURN
;******************************************************
delay
movlw h'ff'
movwf sayac1
dongu1
movlw h'ff'
movwf sayac2
dongu2
decfsz sayac2,F
goto dongu2
decfsz sayac1,F
goto dongu1
return
end