RS232 Switch Project




Download code


;=======Switch.ASM Rev.B =================================22/12/04==
;	standard crystal 4.0MHz XT
;	Bergthaller Iulian (c)2004
;------------------------------------------------------------
;	configure programmer
	LIST P=16F628;f=inhx8m
	#include "P16F628.INC"  ; Include header file
	__CONFIG	_PWRTE_ON  & _WDT_OFF & _HS_OSC & _BODEN_ON & _LVP_OFF & _CP_OFF & _MCLRE_OFF
;------------------------------------------------------------
;	cpu init
	cblock 0x20	; Beginn General Purpose-Register
;-------------------------- counters	
	count1
	count2
	count3
	count4
	count5
;-------------------------- registrii transfer
	trunk
;--------------------------
	endc
;--------------------------
#DEFINE comu	PORTA,0
#DEFINE comd	PORTA,1
#DEFINE comt	PORTA,2
#DEFINE comp	PORTA,3
#DEFINE enab	PORTB,2
#DEFINE rsrx	PORTB,0
#DEFINE cdet 	PORTB,1
#DEFINE rstx	PORTB,3
;--- Reset --------------------------------------------------
	org	h'00'
	goto	init		; reset -> init
;--- Interrupt ----------------------------------------------
	org	h'04'
	goto	init		; no interrupt
;************************************************************
init	clrf	PORTA
	clrf	PORTB
	movlw	0x07		; Turn comparators off and enable pins for I/O 
	movwf	CMCON	
	bcf	STATUS,RP1
	bsf	STATUS,RP0	; Bank 1
	movlw	B'00000000'
	movwf	TRISA
	movlw	B'00000011'
	movwf	TRISB
	bcf	STATUS,RP0	; Bank 0
	movlw	0x00
	movwf	PORTA
	movwf	trunk

;************************************************************************
	movlw	0x01
	movwf	PORTA
	call	pause
	bsf	rstx
;************************************************************************
nou	clrf	PORTA
	call	pause
wait	nop
	btfsc	cdet
	goto	wait ; asteapta apel
	movlw	0x2A ;	cca. 8s
	movwf	count3
b3	movlw	0xFA
	movwf	count1
b1	movlw	0xFA	  
	movwf	count2
b2	nop
	nop
	btfss	rsrx
	goto	c_unu
	decfsz	count2,F	
	goto	b2		
	decfsz	count1,F	
	goto	b1		
	decfsz	count3,F    
	goto	b3          
; afiseaza port
;
	bsf	enab
	call	halta
	call	prt
	call	sau
; asteapta selectie
;
	call	ser_rx
	movlw	0x34
	subwf	trunk,W
	btfss	STATUS,Z ;test zero bit
	goto	trei
	call	halta
	call	prt
	movlw	0x34
	call	ser_tx
	movlw	0x20 ; _
	call	ser_tx
	call	conectat
	call	press
	bcf	enab ; deconectare ser_tx
	call	halta
	bsf	comp
	call	halta
	goto	rep
; next_port
;
trei	movlw	0x33
	subwf	trunk,W
	btfss	STATUS,Z ;test zero bit
	goto	doi
	call	halta
	call	prt
	movlw	0x33
	call	ser_tx
	movlw	0x20 ; _
	call	ser_tx
	call	conectat
	call	press
	bcf	enab ; deconectare ser_tx
	call	halta
	bsf	comt
	call	halta
	goto	rep
; next_port
;
doi	movlw	0x32
	subwf	trunk,W
	btfss	STATUS,Z ;test zero bit
	goto	unu
	call	halta
	call	prt
	movlw	0x32
	call	ser_tx
	movlw	0x20 ; _
	call	ser_tx
	call	conectat
	call	press
	bcf	enab ; deconectare ser_tx
	call	halta
	bsf	comd
	call	halta
	goto	rep
; next_port
;
unu	movlw	0x31
	subwf	trunk,W
	btfss	STATUS,Z ;test zero bit
	goto	rep
	call	halta
	call	prt
	movlw	0x31
	call	ser_tx
	movlw	0x20 ; _
	call	ser_tx
	call	conectat
	call	press
	bcf	enab ; deconectare ser_tx
	call	halta
c_unu	bsf	comu
rep	btfsc	cdet
	goto	nou
	call	pause
	goto	rep
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ser_rx
	btfsc	rsrx
	goto	ser_rx
	clrf	trunk
	call	haltb
	movlw	0x08
	movwf	count5
wdh2	call	halta
	nop
	nop
	nop
	bcf	STATUS,C
	btfsc	rsrx
	bsf	STATUS,C	
	rrf	trunk,F
	decfsz	count5,F
	goto	wdh2
	return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;***************************************************
sau
	movlw	0x3C ; <
	call	ser_tx
	movlw	0x34 ; 4
	call	ser_tx
	movlw	0x2F ; /
	call	ser_tx
	movlw	0x33 ; 3
	call	ser_tx
	movlw	0x2F ; /
	call	ser_tx
	movlw	0x32 ; 2
	call	ser_tx
	movlw	0x2F ; /
	call	ser_tx
	movlw	0x31 ; 1
	call	ser_tx
	movlw	0x3E ; >
	call	ser_tx
	retlw	0x00
;***************************************************
prt
	movlw	0x0A ; LF
	call	ser_tx
	movlw	0x50 ; P
	call	ser_tx
	movlw	0x6F ; o
	call	ser_tx
	movlw	0x72 ; r
	call	ser_tx
	movlw	0x74 ; t
	call	ser_tx
	movlw	0x3A ; :
	call	ser_tx
	retlw	0x00
;***************************************************
conectat
	movlw	0x63 ; c
	call	ser_tx
	movlw	0x6F ; o
	call	ser_tx
	movlw	0x6E ; n
	call	ser_tx
	movlw	0x65 ; e
	call	ser_tx
	movlw	0x63 ; c
	call	ser_tx
	movlw	0x74 ; t
	call	ser_tx
	movlw	0x61 ; a
	call	ser_tx
	movlw	0x74 ; t
	call	ser_tx
	movlw	0x0D ; enter
	call	ser_tx
	movlw	0x0A ; LF
	call	ser_tx
	retlw	0x00
;***************************************************
press
	movlw	0x50 ; P
	call	ser_tx
	movlw	0x72 ; r
	call	ser_tx
	movlw	0x65 ; e
	call	ser_tx
	movlw	0x73 ; s
	call	ser_tx
	movlw	0x73 ; s
	call	ser_tx
	movlw	0x20 ; _
	call	ser_tx
	movlw	0x65 ; e
	call	ser_tx
	movlw	0x6E ; n
	call	ser_tx
	movlw	0x74 ; t
	call	ser_tx
	movlw	0x65 ; e
	call	ser_tx
	movlw	0x72 ; r
	call	ser_tx
	movlw	0x0D ; enter
	call	ser_tx
	movlw	0x0A ; LF
	call	ser_tx
	retlw	0x00
;**********************************************************************
ser_tx
	movwf	trunk
	movlw	0x08	
	movwf	count4
	call	ein	; Start bit
wdh4	btfsc	trunk,0
	call	null
	btfss	trunk,0
	call	ein
	rrf	trunk,F
	decfsz	count4,F	
	goto 	wdh4
	call	null	; Stop bit
	retlw	0x00
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ein	bcf	rstx
	call	halta
 	retlw	0x00
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
null	bsf	rstx
	call	halta
 	retlw	0x00
;************************************************************************
;************************************************************************
;	Subrutine de intarziere				 				*
;************************************************************************
halta	movlw	0x1F	; 92us
	movwf	count1
q0	decfsz	count1,F	
	goto 	q0
 	retlw	0x00
;________________________________________________________________________
haltb	movlw	0x10	; 47us
	movwf	count1
q1	decfsz	count1,F	
	goto 	q1		
 	retlw	0x00
;________________________________________________________________________
pause	movlw	0x08 ;	cca. 2s
hopa	movwf	count3
d3	movlw	0xFA
	movwf	count1
d1	movlw	0xFA	  
	movwf	count2
d2	nop
	decfsz	count2,F	
	goto	d2		
	decfsz	count1,F	
	goto	d1		
	decfsz	count3,F    
	goto	d3          
	retlw	0x00
;************************************************************************
;============================================================
	end
;============================================================


Back to my home page

Last updated December, 2004

© Copyright 2002-2004 Bergthaller Iulian-Alexandru
eXTReMe Tracker