

	list	p=16f690, r=dec, l=0

;***** INCLUDES ***********************************************************

	include "p16f690.inc"
	include "base.inc"

;***** CONFIG ************************************************************

	__CONFIG _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF
	__IDLOCS 0100h			; version

	EXPAND_MACROS	EXP_COND	; macro expansion mode

;***** DEFINES ************************************************************
#define DEBUG				; for some debug message
;#define NO_DELAY			; for fast simulation
;#define NO_RS232			; for fast simulation

xtal_freq	EQU	4 MHz  		; crystal frequency
core_freq	EQU	xtal_freq/4	; core operating frequency


; ----- portc -------------------------------------------------------------

#define		RS232_TxD	PORTC,4		; out
#define		RS232_RxD	PORTC,5		; in


; ----- portb -------------------------------------------------------------

#define		PORTB_0		PORTB,0		; free
#define		PORTB_1		PORTB,1		; free
#define		PORTB_2		PORTB,2		; free
#define		PORTB_3		PORTB,3		; free
#define		PORTB_4		PORTB,4		; free
#define		PORTB_5		PORTB,5		; free
#define		PORTB_6		PORTB,6		; free
#define		PORTB_7		PORTB,7		; free


;***** MACROS *************************************************************

	include "wait.mac"
	include	"rs232.mac"


;***** CONSTANT DEFINITIONS ***********************************************
option_val	EQU	00000010b	; Timer source : intclk / 8
trisc_val	EQU	11101111b	; TRISC value
trisb_val	EQU	11111111b	; TRISB value (all input)
intcon_val	EQU	00100000b	; Interrupt control


;***** VARIABLE DEFINITIONS ***********************************************
	cblock	0Ch
		w_temp			; variable used for context saving
		status_temp		; variable used for context saving
		fsr_temp		; variable used for context saving

		TEMP			; dummy register
	endc




;***** ENTRY POINT ********************************************************
		ORG	000h		; processor reset vector
		clrwdt
		clrf	PORTC		; clear latch
		clrf	PORTB		; clear latch
		goto	start


;***** IT HANDLER *********************************************************
;* Interrupt handler
;* <comment>
;**************************************************************************
;		ORG	004h		; interrupt vector location
;		movwf	w_temp		; save off current W register contents
;		swapf	STATUS,w	; move STATUS register into W register
;		movwf	status_temp	; save off contents of STATUS register

;		movf	FSR,w		; save FSR
;		movwf	fsr_temp
;--------------------------------------------------------------------------

		; <IT Code>

;--------------------------------------------------------------------------
;		movf	fsr_temp,w	; restore FSR
;		movwf	FSR

;		swapf	status_temp,w	; retrieve copy of STATUS register
;		movwf	STATUS		; restore pre-isr STATUS register contents
;		swapf	w_temp,f
;		swapf	w_temp,w	; restore pre-isr W register contents
;		retfie			; return from interrupt




;***** REAL PROGRAM START *************************************************
start
;----- set configuration --------------------------------------------------
		bank1
		ERRORLEVEL -302
	;	movlw	option_val
	;	movwf	OPTION_REG	; set OPTION_REG
		movlw	trisc_val
		movwf	TRISC		; set TRISC
		movlw	trisb_val
		movwf	TRISB		; set TRISB

		bank0
		MOVLW    b'00010000'
		MOVWF    PORTC            


		bank0
		ERRORLEVEL +302
		movlw	intcon_val	
		movwf	INTCON		; set INTCON

;----- inits --------------------------------------------------------------


		RS232_INIT	9600, 8, 1


;----- main cycle  --------------------------------------------------------


		movlw	4
		movwf	TEMP
main_cycle
		movlw  'P' 
		RS232_SENDW
		movlw  'I' 
		RS232_SENDW
		movlw  'C' 
		RS232_SENDW
		movlw  ':' 
		RS232_SENDW
		movlw  '\n' 
		RS232_SENDW
		movlw  '\r' 
		RS232_SENDW



		WAIT	500 Millisec, 0

;		movlw	00100b		; togle led
;		xorwf	PORTA,f

;		decfsz	TEMP,f
;		goto	main_cycle


;run	
;		RS232_RECEIVE


;		sublw	'\r'
;		btfss	STATUS,Z
;		goto	cont_1
		
		
;		movlw	'\r'		; convert: 0x0d -> 0x0d, 0x0a
;		RS232_SENDW
;		movlw	'\n'
;		RS232_SENDW
;		goto	run

;cont_1		movf	RS232_RecvBuffer,w
;		sublw	'A' -1		; convert: 'A-Z' -> 'a-z'
;		btfsc	STATUS,C
;		goto	send_1

;		movf	RS232_RecvBuffer,w
;		sublw	'Z'
;		btfss	STATUS,C
;		goto	send_1

;		movf	RS232_RecvBuffer,w
;		addlw	32
;		goto	send_2

;send_1		movf	RS232_RecvBuffer,w
;send_2		RS232_SENDW
;		goto	run









;**************************************************************************

	include "wait.inc"
	include "rs232.inc"

	end				  ; end of program








