' set up constants to use in the code numRows con 4 ' number of rows numCols con 4 ' number of columns colOffset con 0 ' first column pin in column port ' set up variables: rows var byte ' the row counter cols var byte ' the column counter ' the following vars are probably not neccesary if we just send out the values as we get them. ' switchArray var word(16) ' array of input values thisSwitch var byte ' the switch we're dealing with ' set up ADC parameters DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 20 ' set up ADC variables ADCVar var word ADCByte var byte ' set pins RA0-RA3 as input : TRISA = %00001111 ' set pins RC0-RC3 as output (and RC6 as output for serial comm.): TRISC = %10110000 ' set adcon? ADCON1 = %10000010 ' set porta analog and right justify result Pause 500 main: 'send out a message showing that this is the beginning of the loop Serout2 portc.6, 16468, [255] ' loop over the columns, turning on one at a time for cols = 0 to 3 ' set this column high to check the switches in it: PORTC = 1 << cols ' loop over the rows, reading one switch at a time: for rows = 0 to 3 ' calculate this switch's position in the array: (not neccessary if we send out values as we get them) thisSwitch = (cols * numCols) + rows ' read the analog value in adcin rows, ADCVar ' store the analog value in the array 'not bothering with this, since i'm just sending them out as they are read ' serout stuff ADCVar = ADCVar - 700 ADCByte = ADCVar.lowbyte Serout2 portc.6, 16468, [ADCByte] next 'set this column low to prep for the next column loop: PORTC = 0 next goto main