; TUTA3.ASM  27SEP07

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
; Configuration data 
; PICmicro MCU type: 16F1937 
; Oscillator: Oscillator: XTAL mode
; LCD display: off 
; 7-segment display: off 
; Version 3 board settings: J14 links: Digital 
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
; The following lines embed configuration data into the PICmicro
	LIST P=16F1937
  __CONFIG H'8007', H'FE4'  ; Internal osc mode
   __CONFIG H'8008', H'1EFF' 
 #DEFINE   BANK0   MOVLB 0
 #DEFINE   BANK1   MOVLB 1
 #DEFINE   BANK2   MOVLB 2
 #DEFINE   BANK3   MOVLB 3

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 
COUNT	EQU	H'20'	
STATUS	EQU	H'03'		; STATUS register
PORTA	EQU	H'0C'		;
TRISA	EQU	H'8C'		;
PORTB	EQU	H'0D'		;
TRISB	EQU	H'8D'		;
LATB    EQU	H'10D'		;
W	EQU	0		; Working register flag
F	EQU	1		; File register flag
C	EQU	0		; Carry flag
Z   	EQU 	2		; zero flag
COUNT	EQU	H'20'
TIMER	EQU	H'21'
DELAY   EQU	H'22'

	
	ORG	0		; Reset vector
	GOTO	5		; Goto start of program
	ORG	4		; Interrupt vector
	GOTO	5		; Goto start of program
	ORG	5		; Start of program memory
	CLRF	PORTB		; clear Port B data pins
	CLRF 	PORTA
	BANK1			; Page 1
	MOVLW	0x07
	MOVWF	H'99'		; Setup the OSCCON register to set int osc at 31KHz
	MOVLW	B'00000001'	; this binary value shows which bits are set to 1
				; in this case, only bit 0 is set to 1 and the value
	MOVWF	TRISA		; is used to set Port A with pin RA0 as input
				; and pins RA1, RA2, RA3 and RA4 as outputs
				; (but will not be used in this example)
	CLRF	TRISB		; Port B is set with all pins as outputs as before
	CLRF	PORTB		; set all Port B as output via Page 1
	BANK3
	CLRF	H'18C'; Disable all PortA analogue channnels as enabled by default. Note: if analoge pin is enabled then will not work as digital i/p
	
	BANK0	

BEGIN	CLRF	COUNT		; clear counter
LOOP	

	MOVLW	0x00	
	MOVWF DELAY;
Delay_0
 	DECFSZ	DELAY, f
 	GOTO	Delay_0
	
	
	MOVF	PORTA,W	; copy the value of PORTA into W
	ANDLW	B'00000001'	; the value is ANDed with binary 1 so that only
				; the status of the first bit (bit 0) of Port A will
				; have any effect
	ADDWF	COUNT,F	; the value of Port A bit 0 is added to the counter
				; if switch is pressed bit 0 = 1;
				; if switch is unpressed bit 0 = 0
	MOVF	COUNT,W	; copy the value of COUNT into W
	MOVWF	PORTB		; and set Port B to that value

	

	GOTO	LOOP		; in this example, the loop is repeated endlessly

	END			; final statement
	