معلومات
العضو
إحصائية
العضو
مع اني لم اجرب البرنامجين التاليين ساضعهما في المنتدى
لكي اجدهما اذا ما تعطل جهازي
لاني غالبا مااكتب برامج طويلة ومعقدة نوعا ما ثم اضيعها عندما احتاج اليها
حيث البرنامج الاول لجهاز الارسال
يتحكم في الاتجاه والدفع والسرعة مع مؤشر للسرعة
كود:
list p=16F84A
#include
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
PORTB EQU 0x0006
TRISB EQU 0x0086 ;
STATUS EQU 0x0003 ;
PORTA EQU 0x0005 ;
TRISA EQU 0x0085 ;
OPTION_REG EQU 0x0081 ;
AA EQU 0x000C
BB EQU 0x000D
CC EQU 0Eh
SPEED EQU 0Fh
WSTOR EQU 10h
STORSTATUS EQU 11h
#DEFINE BANK1 BSF STATUS,05
#DEFINE BANK0 BCF STATUS,05
org 00H
GOTO STAR
ORG 04H
MOVWF WSTOR
SWAPF STATUS,W
MOVWF STORSTATUS
BCF INTCON,0
;*****************
BCF STATUS,Z
MOVLW 10h
SUBWF SPEED,w
BTFSC STATUS,Z
GOTO ZIT
BTFSC PORTB,4
INCF SPEED
;*****************
ZIT
BCF STATUS,Z
MOVLW 0h
SUBWF SPEED,w
BTFSC STATUS,Z
GOTO ZOT
BTFSC PORTB,5
DECF SPEED
ZOT
;*****************
SWAPF STORSTATUS,W
MOVWF STATUS
SWAPF WSTOR,F
SWAPF WSTOR,W
RETFIE
STAR
BANK1
BCF OPTION_REG,7
MOVLW b'11111111'
MOVWF TRISB
MOVLW b'11111110'
MOVWF TRISA
BSF INTCON,3
BSF INTCON,7
BANK0
CLRF SPEED
boucle
BSF PORTA,0 ;
CALL T1ms;
;;;;;;;;;;
BCF PORTA,0
CALL T1ms ;
CALL T1ms ;
;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms
;;;;;;;;;;
BCF PORTA,0
CALL T1ms ;
;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
CALL T1ms
CALL T1ms
;;;;;;;;;;
BCF PORTA,0
CALL T1ms ;
;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
;;;;;;;;;;
BTFSS PORTB,0 ;
BSF PORTA,0;
BTFSC PORTB,0
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSS PORTB,1
BSF PORTA,0
BTFSC PORTB,1
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSS PORTB,2
BSF PORTA,0
BTFSC PORTB,2
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSS PORTB,3
BSF PORTA,0
BTFSC PORTB,3
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSS PORTB,0 ;
BSF PORTA,0;
BTFSC PORTB,0
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSS PORTB,1
BSF PORTA,0
BTFSC PORTB,1
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSS PORTB,2
BSF PORTA,0
BTFSC PORTB,2
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSS PORTB,3
BSF PORTA,0
BTFSC PORTB,3
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSC SPEED,0 ;
BSF PORTA,0;
BTFSS SPEED,0
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSC SPEED,1
BSF PORTA,0
BTFSS SPEED,1
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSC SPEED,2
BSF PORTA,0
BTFSS SPEED,2
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSC SPEED,3
BSF PORTA,0
BTFSS SPEED,3
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSC SPEED,0 ;
BSF PORTA,0;
BTFSS SPEED,0
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSC SPEED,1
BSF PORTA,0
BTFSS SPEED,1
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSC SPEED,2
BSF PORTA,0
BTFSS SPEED,2
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;
BSF PORTA,0 ;
CALL T1ms;
BTFSC SPEED,3
BSF PORTA,0
BTFSS SPEED,3
BCF PORTA,0
CALL T1ms
BCF PORTA,0
CALL T1ms
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
BCF PORTA,0
CALL T20MS
;*********************
BCF STATUS,Z
MOVLW 0
SUBWF SPEED,W
BTFSC STATUS,Z
CALL LED1
;;;;;;;;;;;;;;;
MOVLW 1
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED1
;;;;;;;;;;;;;;;
MOVLW 2
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED2
;;;;;;;;;;;;;;;
MOVLW 3
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED2
;;;;;;;;;;;;;;;
MOVLW 4
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED3
;;;;;;;;;;;;;;;
MOVLW 5
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED3
;;;;;;;;;;;;;;;
MOVLW 6
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED4
;;;;;;;;;;;;;;;
MOVLW 7
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED4
;;;;;;;;;;;;;;;
MOVLW 8
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED5
;;;;;;;;;;;;;;;
MOVLW 9
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED5
;;;;;;;;;;;;;;;
MOVLW 0Ah
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED6
;;;;;;;;;;;;;;;
MOVLW 0Bh
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED6
;;;;;;;;;;;;;;;
MOVLW 0Ch
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED7
;;;;;;;;;;;;;;;
MOVLW 0Dh
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED7
;;;;;;;;;;;;;;;
MOVLW 0Eh
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED4
;;;;;;;;;;;;;;;
MOVLW 0Fh
SUBWF SPEED,w
BTFSC STATUS,Z
CALL LED4
;;;;;;;;;;;;;;;
GOTO boucle
;************************
NOMBRE0
MOVLW b'00000010'
MOVWF PORTA
RETURN
LED1
MOVLW b'00000100'
MOVWF PORTA
RETURN
LED2
MOVLW b'00001000'
MOVWF PORTA
RETURN
LED3
MOVLW b'10011110'
MOVWF PORTB
RETURN
LED4
MOVLW b'00010000'
MOVWF PORTB
RETURN
LED5
MOVLW b'00100000'
MOVWF PORTB
RETURN
LED6
MOVLW b'01000000'
MOVWF PORTB
RETURN
LED7
MOVLW b'10000000'
MOVWF PORTB
RETURN
T1ms
MOVLW 0xf9
MOVWF AA
LOOP1
NOP
DECFSZ AA
GOTO LOOP1
RETURN
T20MS
MOVLW 0x14
MOVWF BB
LOOP3
CALL T1ms
DECFSZ BB
GOTO LOOP3
RETURN
end
البرنامج الثانى لجهاز الاستقبال
كود:
list p=16F84A
#include <p16F84A.inc>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
PORTB EQU 0x0006
TRISB EQU 0x0086 ;
STATUS EQU 0x0003 ;
PORTA EQU 0x0005 ;
TRISA EQU 0x0085 ;
STATUS EQU 0X0003
AA EQU 0x000C
BB EQU 0x000D
CC EQU 0Eh
DD EQU 0Fh
ALPHA EQU 10h
BETA EQU 11h
WSTOR EQU 12h
STORSTATUS EQU 13h
DEBO EQU 14h
OPTION_REG EQU 0x0081
tmr0 EQU 01h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#DEFINE BANK1 BSF STATUS,05
#DEFINE BANK0 BCF STATUS,05
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ORG 00H
GOTO STAR
ORG 04H
MOVWF WSTOR
SWAPF STATUS,W
MOVWF STORSTATUS
;*****************
INCF DEBO
BCF STATUS,Z
MOVLW 12h
SUBWF DEBO,w
BTFSS STATUS,Z
GOTO CHANCE
;*****************
CLRF PORTA
CLRF PORTB
CLRF DEBO
CLRF TMR0
CHANCE
;*****************
BCF INTCON,2
BCF INTCON,0
SWAPF STORSTATUS,W
MOVWF STATUS
SWAPF WSTOR,F
SWAPF WSTOR,W
RETFIE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
STAR
BANK1
MOVLW b'00001111'
MOVWF TRISB
MOVLW b'11110000'
MOVWF TRISA
MOVLW b'10000101'
MOVWF OPTION_REG
BSF INTCON,5
BSF INTCON,7
;;;;;;;;;
BANK0
CLRF PORTB
CLRF PORTA
CLRF DEBO
CLRF TMR0
LOOPB
CLRF DD
BECHAR
BTFSC PORTB,0
INCF DD
BTFSS PORTB,0
GOTO LOOPB
CALL US200
MOVLW 0X05
BCF STATUS,2
SUBWF DD,W
BTFSS STATUS,2
GOTO BECHAR
CALL US100
CALL US50
;;;;;;;;;
CLRF DD
LOOP2
BTFSS PORTB,0
INCF DD
BTFSC PORTB,0
GOTO LOOPB
MOVLW 0X09
BCF STATUS,02
SUBWF DD,W
CALL US200
BTFSS STATUS,02
GOTO LOOP2
CALL US100
CALL US50
;;;;;;;;;;;
CLRF DD
LOOPG
BTFSC PORTB,0
INCF DD
BTFSS PORTB,0
GOTO LOOPB
CALL US200
MOVLW 0X04
BCF STATUS,2
SUBWF DD,W
BTFSS STATUS,2
GOTO LOOPG
;;;;;;;;;;;
CALL US200
CALL US200
CALL US100
BTFSC PORTB,0
GOTO BECHAR
;;;;;;;;;;;
CALL T1ms
BTFSS PORTB,0
GOTO LOOPB
;;;;;;;;;;;
CALL T1ms
BTFSS PORTB,0
GOTO LOOPB
;;;;;;;;;;;
CALL T1ms
BTFSS PORTB,0
GOTO LOOPB
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
CALL US50
CLRF ALPHA
BTFSC PORTB,0
BSF ALPHA,0
BTFSS PORTB,0
BCF ALPHA,0
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
BTFSC PORTB,0
BSF ALPHA,1
BTFSS PORTB,0
BCF ALPHA,1
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
CALL US50
BTFSC PORTB,0
BSF ALPHA,2
BTFSS PORTB,0
BCF ALPHA,2
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
BTFSC PORTB,0
BSF ALPHA,3
BTFSS PORTB,0
BCF ALPHA,3
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
CALL US50
CLRF BETA
BTFSC PORTB,0
BSF BETA,0
BTFSS PORTB,0
BCF BETA,0
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
BTFSC PORTB,0
BSF BETA,1
BTFSS PORTB,0
BCF BETA,1
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
CALL US50
BTFSC PORTB,0
BSF BETA,2
BTFSS PORTB,0
BCF BETA,2
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
BTFSC PORTB,0
BSF BETA,3
BTFSS PORTB,0
BCF BETA,3
;;;;;;;;;;
MOVF ALPHA,W
BCF STATUS,2
SUBWF BETA,W
BTFSS STATUS,2
GOTO LOOPB
MOVF BETA,W
MOVWF PORTA
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
CLRF ALPHA
BTFSC PORTB,0
BSF ALPHA,0
BTFSS PORTB,0
BCF ALPHA,0
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
CALL US50
BTFSC PORTB,0
BSF ALPHA,1
BTFSS PORTB,0
BCF ALPHA,1
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
BTFSC PORTB,0
BSF ALPHA,2
BTFSS PORTB,0
BCF ALPHA,2
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
CALL US50
BTFSC PORTB,0
BSF ALPHA,3
BTFSS PORTB,0
BCF ALPHA,3
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
CLRF BETA
BTFSC PORTB,0
BSF BETA,0
BTFSS PORTB,0
BCF BETA,0
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
BTFSC PORTB,0
BSF BETA,1
BTFSS PORTB,0
BCF BETA,1
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
BTFSC PORTB,0
BSF BETA,2
BTFSS PORTB,0
BCF BETA,2
;;;;;;;;;;
CALL TEST
;;;;;;;;;;
CALL T1ms
BTFSC PORTB,0
BSF BETA,3
BTFSS PORTB,0
BCF BETA,3
;;;;;;;;;;
vv
BANK1
MOVLW b'00001111'
MOVWF TRISB
BANK0
MOVF ALPHA,W
BCF STATUS,2
SUBWF BETA,W
BTFSS STATUS,2
GOTO LOOPB
RLF BETA,F
RLF BETA,F
RLF BETA,F
RLF BETA,w
MOVWF PORTB
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CALL MS18
CLRF DEBO
CLRF TMR0
GOTO LOOPB
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MS18
MOVLW 0x13 ; ajuste
MOVWF BB
loop3
MOVLW 0xF8; ajuste fine
MOVWF AA ;
lop1
NOP
DECFSZ AA
GOTO lop1
DECFSZ BB
GOTO loop3
RETURN
;;;;;;;;;;;;;;;;;;;;;
T1ms
MOVLW 0xF6
MOVWF AA
LOOP1
NOP
DECFSZ AA
GOTO LOOP1
RETURN
;;;;;;;;;;;;;;;;;;;;
US200
MOVLW 0x30
MOVWF AA
LOOP4
NOP
DECFSZ AA
GOTO LOOP4
RETURN
;;;;;;;;;;;;;;;;;;;
US100
MOVLW 0x17
MOVWF AA
LOP4
NOP
DECFSZ AA
GOTO LOP4
NOP
NOP
RETURN
;;;;;;;;;;;;;;;;
US50
MOVLW 0x9
MOVWF AA
LOPA
NOP
DECFSZ AA
GOTO LOPA
NOP
NOP
RETURN
;;;;;;;;;;;;;;;;
US5
NOP
NOP
NOP
NOP
NOP
RETURN
;;;;;;;;;;;;;;;;
TEST
CALL T1ms
BTFSC PORTB,0
GOTO LOOPB
;;;;;;;;;;
CALL T1ms
BTFSS PORTB,0
GOTO LOOPB
RETURN
;;;;;;;;;;;;;;;;
END