'**************************************************************** '* Name : RB-4970-DEMO * '* Author : Joel Murphy * '* Notice : Creative Commons Attribution-Share Alike * '* Date : 01/2010 * '* Version : 1.0 * '* Notes : PIC16F88 INTRC 8MHz * '* : * '**************************************************************** ' Development of working code for interfacing the RB-4970 ' include "modedefs.bas" OSCCON = %01110110 'set the internal oscillator to 8MHz define OSC 8 ANSEL = %00000000 'set PortA digital TRISB = %00000000 'set In/Out TRISA = %00000010 ' >>>>>>>>> VARIABLES <<<<<<<<<<<< PTRN var byte[9] MODE VAR BYTE[2] Time var byte OutByte var byte ADDR CON %11110100 'bit2 is determined by the state of the ADR pin FREQ con %01001001 'set the PWM frequency to 60Hz, HighPass cutoff to 6.3KHz AMP con %10101010 'set the LED current drivers to 1.33X (also available: 1X, .66X, 2X) GAIN con %11010010 'set Midband Gain to medium, Input Signal Gain to 0dB LastPB var bit ' >>>>>>>>> PINS <<<<<<<<<<< 'var PortA.0 PB var PortA.1 'var PortA.2 'var PortA.3 'var PortA.4 'var PortA.5 'var PortA.6 'var PortA.7 'var PortB.0 SDA var PortB.1 'var PortB.2 LCD var PortB.3 SCL var PortB.4 'var PortB.5 'var PortB.6 'var PortB.7 ' >>>> INITIALIZE VARIABLES <<<< time = 0 lastpb = pb mode[0] = %00000000 'disable audio sync randomizer mode[1] = %00000100 'enable audio sync randomizer ' >>> PATTERN REGISTER BIT 7 IS INCORRECT ON THE DATASHEET! ' >>> IT SHOULD BE A 0 NOT A 1! ptrn[0] = %01100000 'disable I2C color control ptrn[1] = %01100001 'enable I2C color control ptrn[2] = %01100011 'drive LED 1 ptrn[3] = %01100101 'drive LED 2 ptrn[4] = %01101001 'drive LED 3 ptrn[5] = %01100111 'drive LEDs 2,1 ptrn[6] = %01101011 'drive LEDs 3,1 ptrn[7] = %01101101 'drive LEDs 3,2 ptrn[8] = %01101111 'drive LEDs 3,2,1 high lcd 'using Parallx Serial LCD 27977 pause 100 'wait for LCD to warm up Setup: serout2 lcd,84,[22,17,12] 'turn off cursor, trun on backlight, clear screen pause 5 'mandatory pause after sending 12 to LCD serout2 lcd,84,[148,"Pattern: "] outbyte = mode[0] gosub i2c_send outbyte = freq gosub i2c_send outbyte = amp gosub i2c_send outbyte = gain gosub i2c_send outbyte = ptrn[0] gosub i2c_send pause 100 goto main Main: if pb <> lastPB then pause 10 'debounce if pb <> lastpb then if pb = 1 then outbyte = ptrn[time] gosub i2c_send serout2 lcd,84,[157,bin4 ptrn[time]] time = time +1 if time = 9 then time = 0 endif endif lastpb = pb endif endif pause 50 goto main I2C_Send: i2cwrite sda,scl,addr,[outbyte],snafu serout2 lcd,84,[188," sent: ",bin8 outbyte] return Snafu: high scl high sda serout2 lcd,84,[188,"crash: ",bin8 outbyte] pause 100 return