//模块S2—–单片机P1.1
//模块S3-----单片机P1.0//模块OUT----单片机P3.5(计数器1输入)//模块VCC----单片机VCC//模块GND----单片机GND//K4按一次进入份额因子调理形式,再按退出;探测时按K8重置//K1+,K5-操控R份额因子 K2+,K6-操控B份额因子 K3+,K7-操控G份额因子#include#include //Keil library #include //Keil library #include #define uchar unsigned char#define uint unsigned int #define DataPort P0 //LCD1602 数据端口sbit LCM_RS=P2^6; //LCD1602 操控端口 sbit LCM_RW=P2^5; //LCD1602 操控端口 sbit LCM_EN=P2^7; //LCD1602 操控端口/**引脚界说**/ sbit s2=P1^1; //TCS3200 S2 sbit s3=P1^0; //TCS3200 S3//TCS3200 S0 模块内部默许上拉//TCS3200 S1 模块内部默许上拉//TCS3200 OE 模块内部接地sbit test_pin=P2^2; //用示波器看这个引脚,可知道守时器中止频率sbit K8=P1^7;sbit K1=P2^1;sbit K2=P2^0;sbit K3=P1^2; sbit K4=P1^3;sbit K5=P1^4;sbit K6=P1^5;sbit K7=P1^6;//变量、常量界说uchar ge,shi,bai ;uchar rp=3,gp=3,bp=6; //界说份额因子,详细环境能够修正uchar count; //色彩标志位(0:红 1:绿 2:蓝)uint ryz,gyz,byz;//别离界说赤色因子 绿色因子 蓝色因子//显现数组uchar disp_R[3]; //红uchar disp_G[3]; //绿uchar disp_B[3]; //蓝uchar disp_rp[3];uchar disp_bp[3];uchar disp_gp[3];//********界说函数*****************************void delay(unsigned int k);void InitLcd();void WriteDataLCM(uchar dataW);void WriteCommandLCM(uchar CMD,uchar Attribc);void DisplayOneChar(uchar X,uchar Y,uchar DData);void baipingheng();//白平衡子程序void DisplayRGB();//显现份额因子//*********LCD1602初始化**********************void InitLcd() { WriteCommandLCM(0x38,1); WriteCommandLCM(0x08,1); WriteCommandLCM(0x01,1);WriteCommandLCM(0x06,1); WriteCommandLCM(0x0c,1);}//**********检测忙信号************************void WaitForEnable(void) { DataPort=0xff; LCM_RS=0;LCM_RW=1;_nop_();LCM_EN=1;_nop_();_nop_();while(DataPort&0x80); LCM_EN=0; }//**********写指令至LCD***********************void WriteCommandLCM(uchar CMD,uchar Attribc){ if(Attribc)WaitForEnable(); LCM_RS=0;LCM_RW=0;_nop_();DataPort=CMD;_nop_(); LCM_EN=1;_nop_();_nop_();LCM_EN=0;} //**********写数据至LCD************************void WriteDataLCM(uchar dataW){ WaitForEnable(); LCM_RS=1;LCM_RW=0;_nop_();DataPort=dataW;_nop_(); LCM_EN=1;_nop_();_nop_();LCM_EN=0;}//*********写一个字符数据到指定的方针***********void DisplayOneChar(uchar X,uchar Y,uchar DData){ Y&=1; X&=15; if(Y)X|=0x40; X|=0x80; WriteCommandLCM(X,0); WriteDataLCM(DData); }//**********延时函数***************void delay(unsigned int k) { unsigned int i,j; for(i=0;i