'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
'*  Notice  : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 2012.01.29.                                       *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'***************************************************************

        Set_Defaults PROTON_4			' Configure ports for PROTON dev board using a 4MHz crystal
        Device 16F877        		
        
        Dim BUF1 as Byte				' Working buffer 1 for button command
		Dim BUF2 as Byte				' Working buffer 2 for button command
		Dim BUF3 as Byte				' Working buffer 3 for button command        
		Dim BUF4 as Byte				' Working buffer 4 for button command 
        Dim BUF5 as Byte				' Working buffer 5 for button command 
        Dim BUF6 as Byte				' Working buffer 6 for button command 
        Dim BUF7 as Byte				' Working buffer 7 for button command
        Dim BUF8 as Byte				' Working buffer 8 for button command 
        Symbol SW1	= PORTB.1
		Symbol SW2	= PORTB.2
		Symbol SW3	= PORTB.3
		Symbol SW4	= PORTB.4
        Symbol SW5	= PORTB.5
        Symbol SW6	= PORTB.6
        Symbol SW7	= PORTB.7
        Symbol SW8	= PORTB.0
        Symbol LED1 = PORTD.1,PORTD.0
        Symbol LED2 = PORTD.2,PORTD.0
        Symbol LED3 = PORTD.3,PORTD.0
        Symbol LED4 = PORTD.4,PORTD.0
        Symbol LED5 = PORTD.5,PORTD.0
        Symbol LED6 = PORTD.6,PORTD.0
		Symbol LED7 = PORTD.7,PORTD.0
		Symbol LED8 = PORTD.0,PORTD.1,PORTD.2,PORTD.3,PORTD.4,PORTD.5,PORTD.6,PORTD.7
        Delayms 500						' Wait for PICmicro to stabilise
        ALL_DIGITAL = True				' Set ports to digital mode
        Clear							' Clear buffers
        Low PORTD						' ALL LEDs off
		TRISD = %00000000
        TRISB = %11111111				' Set PORTB 0-7 outputs
		PORTB_PULLUPS = OFF				' Enable PORTB pull-ups
Chk1:	Delayms 25
		Button SW1,0,40,5,BUF1,0,Chk0	' Check Button 1 (Skip to 2 if Not Pressed)
		Toggle LED1						' Toggle LED if pressed		
Chk2:	Button SW2,0,40,5,BUF2,0,Chk7	' Check Button 2 (Skip to 3 if Not Pressed)
		Toggle LED2						' Toggle LED if pressed		
Chk3:	Button SW3,0,40,5,BUF3,0,Chk1	' Check Button 3 (Skip to 1 if Not Pressed)
		Toggle LED3						' Toggle LED if pressed
Chk4:	Button SW4,0,40,5,BUF4,0,Chk5	' Check Button 1 (Skip to 2 if Not Pressed)
		Toggle LED4						' Toggle LED if pressed		
Chk5:   Button SW5,0,40,5,BUF5,0,Chk4	' Check Button 2 (Skip to 3 if Not Pressed)
		Toggle LED5						' Toggle LED if pressed		
Chk6:   Button SW6,0,40,5,BUF6,0,Chk3	' Check Button 3 (Skip to 1 if Not Pressed)
		Toggle LED6						' Toggle LED if pressed
Chk7:   Button SW7,0,40,5,BUF7,0,Chk2	' Check Button 1 (Skip to 2 if Not Pressed)
		Toggle LED7						' Toggle LED if pressed		
Chk0:   Button SW8,0,40,5,BUF8,0,Chk6	' Check Button 2 (Skip to 3 if Not Pressed)
		Toggle LED8						' Toggle LED if pressed		
        Goto Chk1						' Do it forever
