;**********************************************************************
;   This file is a basic code template for assembly code generation   *
;   on the PICmicro PIC16F874. This file contains the basic code      *
;   building blocks to build upon.                                    *  
;                                                                     *
;   If interrupts are not used all code presented between the ORG     *
;   0x004 directive and the label main can be removed. In addition    *
;   the variable assignments for 'w_temp' and 'status_temp' can       *
;   be removed.                                                       *                         
;                                                                     *
;   Refer to the MPASM User's Guide for additional information on     *
;   features of the assembler (Document DS33014).                     *
;                                                                     *
;   Refer to the respective PICmicro data sheet for additional        *
;   information on the instruction set.                               *
;                                                                     *
;   Template file assembled with MPLAB V4.00 and MPASM V2.20.00.      *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Filename:	    SevenSegment.asm                                  *
;    Date:          January 30, 2006                                  *
;    File Version:  1                                                 *
;                                                                     *
;    Author:        CDR Charles B. Cameron                            *
;    Company:       United States Naval Academy                       *
;                                                                     * 
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files required:  p16f874.inc                                     *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:        This is a demonstration of the use of the          *
;                  table-lookup in order to retrieve a desired        *
;                  pattern and output it to a seven-segment display   *
;                  Assume Port B bits 6 through 0 correspond to       *
;                  segments a through g, respctively.                 *
;                     a                                               *
;                    ---       Correspondence between segments        *
;                 f|     |b    and segment letters                    *
;                  |  g  |                                            *
;                    ---                                              *
;                 e|     |c                                           *
;                  |     |                                            *
;                    ---                                              *
;                     d                                               *
;                                                                     *
;                                                                     *
;**********************************************************************


	list      p=16f874            ; list directive to define processor
	#include <p16f874.inc>        ; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _HS_OSC & _WRT_ENABLE_ON & _LVP_ON & _CPD_OFF

; '__CONFIG' directive is used to embed configuration data within .asm file.
; Watch dog timer is disabled by default.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.






;***** VARIABLE DEFINITIONS

TRISBMask equ B'10000000' 	; Set up Port B for outputs on bits RB6 through RB0
XXX		equ H'20'			; Storage for X
X_init	equ D'9'			; Initial value for X





;**********************************************************************
		ORG     0x000             ; processor reset vector
		clrf    PCLATH            ; ensure page bits are cleared

		; Initialize Port B
		bcf		STATUS,RP1	; Select Bank 1
		bsf		STATUS,RP0
		movlw	TRISBMask
		movwf	TRISB
		bcf		STATUS,RP0	; Select Bank 0
		
		; Initialize X
		movlw	X_init
		movwf	XXX	
		
main
		; Retrieve X
		movf	XXX,W
		call	GetLCDPattern
		movwf	PORTB
		goto	main
		
GetLCDPattern
		addwf	PCL
		retlw	H'7E'	; 7-segment pattern for 0
		retlw	H'30'	; 7-segment pattern for 1
		retlw	H'6D'	; 7-segment pattern for 2
		retlw	H'79'	; 7-segment pattern for 3
		retlw	H'33'	; 7-segment pattern for 4
		retlw	H'5B'	; 7-segment pattern for 5
		retlw	H'5F'	; 7-segment pattern for 6
		retlw	H'70'	; 7-segment pattern for 7
		retlw	H'7F'	; 7-segment pattern for 8
		retlw	H'7B'	; 7-segment pattern for 9
	
; remaining code goes here










		END                       ; directive 'end of program'


