program ColorSensor
dim R1 as byte
dim R2 as byte
dim G1 as byte
dim G2 as byte
dim B1 as byte
dim B2 as byte
dim C1 as byte
dim C2 as byte
DIM RX AS WORD
DIM GX AS WORD
DIM BX AS WORD
DIM CX AS WORD
DIM K2 AS WORD
DIM RX1 AS STRING[5]
DIM GX1 AS STRING[5]
DIM BX1 AS STRING[5]
DIM CX1 AS STRING[5]
DIM K3 AS STRING[5]
main:
TRISD.6=0
PORTD.6=1
LCD_CONFIG(PORTB,7,6,5,4,PORTB,1,2,3)
LCD_OUT(1,1," COLOR")
I2C_Init(100000)
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X02)
I2C_WR(0X00)
I2C_Stop
I2C_Start
I2C_WR(0xE8)
I2C_WR(0X06)
I2C_WR(0XFF)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X07)
I2C_WR(0XFF)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X08)
I2C_WR(0XFF)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X09)
I2C_WR(0XFF)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X0A)
I2C_WR(0XFF)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X0B)
I2C_WR(0XFF)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X0C)
I2C_WR(0XFF)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X0D)
I2C_WR(0XFF)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X0E)
I2C_WR(0XFF)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X0F)
I2C_WR(0XFF)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X10)
I2C_WR(0XFF)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X11)
I2C_WR(0XFF)
I2C_Stop
RUN:
I2C_Start
I2C_WR(0XE8)
I2C_WR(0X01)
I2C_WR(0X01)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0x40)
I2C_Repeated_Start
i2c_wr(0xE9)
R1=i2c_rd(0)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0x41)
I2C_Repeated_Start
i2c_wr(0xE9)
R2=i2c_rd(0)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0x42)
I2C_Repeated_Start
i2c_wr(0xE9)
G1=i2c_rd(0)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0x43)
I2C_Repeated_Start
i2c_wr(0xE9)
G2=i2c_rd(0)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0x44)
I2C_Repeated_Start
i2c_wr(0xE9)
B1=i2c_rd(0)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0x45)
I2C_Repeated_Start
i2c_wr(0xE9)
B2=i2c_rd(0)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0x46)
I2C_Repeated_Start
i2c_wr(0xE9)
C1=i2c_rd(0)
I2C_Stop
I2C_Start
I2C_WR(0XE8)
I2C_WR(0x47)
I2C_Repeated_Start
i2c_wr(0xE9)
C2=i2c_rd(0)
I2C_Stop
Test:
RX=R1+R2
LCD_OUT(1,1,"RED=")
WORDTOSTR(RX,RX1)
LCD_OUT(2,4,RX1)
DELAY_MS(500)
LCD_CMD(LCD_CLEAR)
GX=G1+G2
LCD_OUT(1,1,"GREEN=")
WORDTOSTR(GX,GX1)
LCD_OUT(2,4,GX1)
DELAY_MS(500)
LCD_CMD(LCD_CLEAR)
BX=B1+B2
LCD_OUT(1,1,"BLUE=")
WORDTOSTR(BX,BX1)
LCD_OUT(2,4,BX1)
DELAY_MS(500)
LCD_CMD(LCD_CLEAR)
CX=C1+C2
LCD_OUT(1,1,"CLEAR=")
WORDTOSTR(CX,CX1)
LCD_OUT(2,4,CX1)
DELAY_MS(500)
LCD_CMD(LCD_CLEAR)
goto run
END.