'**************************************************************** '* Name : OXO1.BAS * '* Author : Joe Farr * '* Notice : Copyright (c) 2008 Knight COmputer Services Ltd * '* : All Rights Reserved * '* Date : 25/10/2008 * '* Version : 1.0 * '* Notes : Source code for the OXO board hardware test * '* : * '**************************************************************** ' Which Microchip PIC are we using Device 16F887 ' This sets the oscilator configuration to use the internal one @CONFIG_REQ @__CONFIG _CONFIG1, INTRC_OSC_CLKOUT & WDT_OFF & DEBUG_OFF & FCMEN_OFF & IESO_OFF & BOR_OFF & LVP_OFF & CPD_OFF & CP_OFF & MCLRE_OFF & PWRTE_ON @__CONFIG _CONFIG2, WRT_OFF & BOR21V XTAL = 4 ALL_DIGITAL TRUE ' All I/O Ports are digital - Logic 1's or 0's ' We need some variables ' ALWAYS declare your variables at the start of the program. (The above instructions are for the compiler and don't generate any actual program code) Dim nRow As Byte Dim nCol As Byte Dim nDelay As Byte ' Bytes are 8 bits and can hold a value 0 to 255. ' There are many types of variables but try and declare your variables in size order - largest first ' as the compiler is more efficient. ' Next, we need to configure the PIC's input / output ports/ ' *** PORTC - This drives the OXO columns - There are 6 colums ((0)Red (1)Green, (2)Red (3)Green, (4)Red (5)Green) Symbol Columns = PORTC ' Give our port a meaningful name - Columns Output Columns ' Even tho we don't use all of PORTC, we set ALL of it to being an output. ' *** PORTD - This drives the OXO rows - There are 3 rows (Top, middle and bottom) Symbol Rows = PORTD ' Give our port a meaningful name - Rows Output Rows ' *** PORTE - We have connected our switches here... Symbol Switches = PORTE Input Switches ' Some notes on driving the OXO board. ' The board consists of 18 LEDs - 9 Red and 9 Green (Actually there are 9 physical LEDs - each with 2 colours) ' To light a LED, it must be given a small voltage. One of it's pins must be connected to +, and one pin to -. ' If both pins are connected to either + or -, OR the + and - are applied to the LED the wrong way around, it won't light. ' ' The board is formed from a matrix. ' A traditional board of course is made from a 3 x 3 matrix, but in this case, each "cell" on the board ' has to have 2 LED's (1 x Red, 1 x Green). ' To accomplish this, there are actually colums(0 To 5) and 3 Rows (0 To 2). ' To light the centre RED Led, column 2 must be set to +, and row 1 must be set to -. ' ' ' There are 2 switches for you to use. They are connected to bits 0 and 1 of PORT E ' When a switch is pressed, it's associated bit will go to logic 1 and then back to 0 when you release it. ' ' The sample code below cycles though every LED in turn. Looking at the pattern displayed and reading the ' code should explain how everything works. nDelay = 128 Again: For nCol = 0 To 5 Low Columns ' All off SetBit Columns, nCol ' Set just the desired bit needed on For nRow = 0 To 2 High Rows ' All Off ClearBit Rows, nRow ' Set just the desired bit needed on DelayMS nDelay ' Scan to see if a switch has been pressed If Switches <> 0 Then ' A switch is pressed If Switches.0 = 1 Then If nDelay + 1 > nDelay Then Inc nDelay DelayMS 100 End If End If If Switches.1 = 1 Then If nDelay - 1 < nDelay Then Dec nDelay DelayMS 100 End If End If End If Next nRow Next nCol GoTo Again