	ERRORLEVEL -302
	TITLE "Name Badge (c) 2009 Doug Jackson."
;
;*************************************************************************************
;
; Namebadge - Badges for the kids!  - Sian's Version
;
;	Copyright (c) 2009
;	Doug Jackson
;	35 Fred Lane Crescent
;	GORDON, ACT, 2906
;	Australia
;
;       doug@doug.com
;
; Revision:	1.0
; Date:		23 Sep 2009
; Notes:	None
;
;*************************************************************************************
; Revision History
;*************************************************************************************
;  Date  	By	What
;*************************************************************************************
;

; CPU configuration
; 	(It's a 16F88, Internal oscillator,
; 	watchdog timer off, power-up timer on)

	processor 16f88
	include	  <p16f88.inc>
	__CONFIG    _CONFIG1, _INTRC_IO & _CP_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _WDT_OFF & _BODEN_OFF
	__CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF

	PAGE;

;		__CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC


;
;*************************************************************************************
;	Hardware Constants
;*************************************************************************************
;
S1		EQU	B'00110010'	; some constants are defined
S2		EQU	B'01001001'	; for the characters
S3		EQU	B'01001001'	
S4		EQU	B'01001001'	; 'S'
S5		EQU	B'00100110'

I1		EQU	B'00000000'	; some constants are defined
I2		EQU	B'01000001'	; for the characters
I3		EQU	B'01111111'	
I4		EQU	B'01000001'	; 'I'
I5		EQU	B'00000000'

A1		EQU	B'00011111'	; some constants are defined
A2		EQU	B'00100100'	; for the characters
A3		EQU	B'01000100'	
A4		EQU	B'00100100'	; 'A'
A5		EQU	B'00011111'

N1		EQU	B'01111111'	; some constants are defined
N2		EQU	B'00000110'	; for the characters
N3		EQU	B'00001100'	
N4		EQU	B'00110000'	; 'N'
N5		EQU	B'01111111'

FALSE EQU 0
TRUE  EQU 1


;
;*************************************************************************************
;    	Ram Variable assignments
;*************************************************************************************
;
TEMP		EQU	0x030	; a temporary register
J		EQU	0x031	; delay loop counter
K		EQU	0x032	; delay loop counter
T2		EQU	0x033
TEMP1	EQU	0x034;

	PAGE
;
;*************************************************************************************
;   	Code Starts Here	
;*************************************************************************************
;
	org 0x0000

RESET	GOTO START	; Reset vector location

;
;*************************************************************************************
;	Interrupt Vectors
;*************************************************************************************
;
;   No vectored interrupts are used in this system.



	PAGE
;
;*************************************************************************************
; Start:
;       Set up all inputs and outputs as designed.
;       and do a self test.
;*************************************************************************************
;
START
;	bsf		STATUS,RP0;
;	movlw	b'00010000'	; increase speed to 128kHz
;	movwf	OSCCON
;	bcf		STATUS,RP0

	clrf	TMR0		; clear Timer 0
	clrf	INTCON		; Dissable interrupts

	clrf	CCP1CON		; disable capture compare module

	clrf	ADCON0
	clrf 	ANSEL		; disable adc module


	bsf 	STATUS, RP0	; Bank 1
	movlw	b'00000001'	; the lower 1 bit of port b is an input
	movwf	TRISB
	movlw	b'00000000'	; and all other bits are outputs			
	movwf	TRISA
	bcf 	STATUS, RP0	; select bank 0 again..

	bsf		STATUS, RP0	; select bank 1
	movlw	B'11000000'	; port B pullups are dissabled
	movwf	OPTION_REG	;   Interrupt of rising edge of RB0
						;   Timer 0 increment from internal clock	
						;   with a prescaler of 1:2
	bcf	STATUS, RP0		; bank 0

	call 	LEDTEST		; do a short self test.

	PAGE
;
;*************************************************************************************
; 	Main Loop.  This is where most of the work is done.
;*************************************************************************************
;
MAINLOOP
			; enable interrupts on port B
	movfw	PORTB
	movlw	B'00010000'	; Leave the GIE bit off, we simply want to
						; wake from sleep,  not jump to an interrupt
						; routine.
						; and enable INT (PB0) interrupts.
	movwf	INTCON		; set the interrupt reg.

	
;	sleep			 	; wait for an interrupt.
	

						; yay, we have a button down...

	movlw	b'00000000'	; dissable interrupts
	movwf	INTCON

        
aaa
	Call	Display	;        and display it.
	clrf	PORTA
	clrf	PORTB
	call	short_delay	;	 (causing a pleasing display)
	goto aaa
	goto MAINLOOP


	

;*************************************************************************************
; Outchar - pump out a single scan line       
;		.
; Input: 
; Output:	
; Comments:	none
;*************************************************************************************
outchar

        movwf TEMP1
		andlw 0x1f
		movwf TEMP
		rlf TEMP,0
       	movwf T2
		
		movf TEMP1,w
		andlw 0x60
		movwf TEMP
		rrf TEMP,1
		rrf TEMP,1
		rrf TEMP,1
		rrf TEMP,1
		rrf TEMP,0
		movwf PORTA
		movf T2,0
		movwf PORTB

	RETURN


;*************************************************************************************
; Display       
;		.
; Input: 
; Output:	
; Comments:	none
;*************************************************************************************
Display

        movlw S1
		call outchar
        movlw S2
		call outchar
        movlw S3
		call outchar
        movlw S4
		call outchar
        movlw S5
		call outchar

        movlw I1
		call outchar
        movlw I2
		call outchar
        movlw I3
		call outchar
        movlw I4
		call outchar
        movlw I5
		call outchar

        movlw A1
		call outchar
        movlw A2
		call outchar
        movlw A3
		call outchar
        movlw A4
		call outchar
        movlw A5
		call outchar

        movlw N1
		call outchar
        movlw N2
		call outchar
        movlw N3
		call outchar
        movlw N4
		call outchar
        movlw N5
		call outchar
 


	return
		
	PAGE


;
;*************************************************************************************
; LEDTEST    - 	Test all LED display possibilities, validates all Display hardware
;		and firmware.
; Input:   	none
; Output:	Various LED patterns
; Comments:	none
;*************************************************************************************
;
LEDTEST
        clrf PORTA
        clrf PORTB

        movlw b'00000010'
       	movwf PORTB
 		Call short_delay
        movlw b'00000100'
       	movwf PORTB
 		Call short_delay
        movlw b'00001000'
       	movwf PORTB
 		Call short_delay
        movlw b'00010000'
       	movwf PORTB
 		Call short_delay
        movlw b'00100000'
       	movwf PORTB
 		Call short_delay
		clrf  PORTB
        movlw b'00000001'
       	movwf PORTA
 		Call short_delay
        movlw b'00000010'
       	movwf PORTA
 		Call short_delay
        
        clrf PORTA
		clrf PORTB

	return



;
;*************************************************************************************
; var_delay  - 	Variable delay routine.   Waste some time executing a nested loop
; Input:   	'W' - Delay period (Unitless...)
; Output:	Time wasted.
; Comments:	none
;*************************************************************************************
;
var_delay	movwf	J
jloop2		movwf	K	
kloop2		decfsz	K,f
		goto kloop2
		decfsz	J,f
		goto jloop2
		return


;
;*************************************************************************************
; short_delay  	Fixed delay time wait.    Waste some time executing a nested loop
; Input:   	None
; Output:	Time wasted.
; Comments:	none
;*************************************************************************************
;
short_delay	movlw	d'20'	; 20 is a fairly short delay.
		movwf	J
jloop1		movwf	K	
kloop1		decfsz	K,f
		goto kloop1
		decfsz	J,f
		goto jloop1
		return

	PAGE		
;
;*************************************************************************************
; delay        	Fixed delay time wait.    Waste some time executing a nested loop
; Input:   	None
; Output:	Time wasted.
; Comments:	none
;*************************************************************************************
;
delay		movlw	d'50'	; A fiarly long delay.
		movwf	J
jloop		movwf	K	
kloop		decfsz	K,f
		goto kloop
		decfsz	J,f
		goto jloop
		return



	end

