资源简介
TCS3200 C程序详细注释,我在网上找了很久都没找到,最后自己研究了下,花了不少时间终于写出来了,其实很简单,在些发给大看学习下,让大家少起弯路...
代码片段和文件信息
#define F_CPU 16000000UL
#include
#include
#include
#define uint unsigned int
#define uchar unsigned char
//================TCS3200引脚IO口===========================
#define OE PD1
#define L2 PD3
#define L3 PD2
volatile uint times = 0; //脉冲计数
//===================I/O口初始化============================
void GPIO_Init()
{
DDRD = 0xfe; //PD0 外部中断
PORTD = 0xfe;
DDRC = 0xff;
}
//====================液晶程序==============================
uchar LCD_number[]=“0123456789.RGB“;
//-----------------------写数据----------------------------
void Write_Date(uchar date)
{
PORTA |= (1< PORTF = date;
_delay_ms(1);
PORTA |=(1< _delay_ms(2);
PORTA &= ~(1< }
//------------------------写指令----------------------------
void Write_Com(uchar com)
{
PORTA &= ~(1< PORTF = com;
_delay_ms(1);
PORTA |=(1< _delay_ms(2);
PORTA &= ~(1< }
//-----------------------LCD初始化--------------------------
void LCD_Init()
{
DDRF = 0xff;
DDRA = 0xff;
PORTA |= (1< PORTA &= ~(1< PORTA &= ~(1<
Write_Com(0x30);
_delay_ms(1);
Write_Com(0x0c);
_delay_ms(1);
Write_Com(0x01);
_delay_ms(20);
Write_Com(0x06);
_delay_ms(1);
Write_Com(0x80);
}
//===================外部中断初始化=========================
void Int_Init()
{
EICRA |= (1< EIMSK |= (1< sei();
}
//===================TCS3200测颜色=========================
float TCS3200(uchar t)
{
float P1;
if(t==1) //R
{
PORTD &= ~(1< PORTD &= ~(1< }
else if(t==2) //G
{
PORTD |= (1< PORTD |= (1< }
else if(t==3) //B
{
PORTD &= ~(1< PORTD |= (1< }
else //无
{
PORTD |= (1< PORTD &= ~(1<
}
_delay_ms(10);
times = 0;
PORTD &=~(1< _delay_ms(40);
PORTD |= (1< P1 = times;
times = 0;
PORTD &=~(1< _delay_ms(40);
PORTD |= (1< P1 += times;
times = 0;
PORTD &=~(1< _delay_ms(40);
PORTD |= (1< P1 += times;
times = 0;
PORTD &=~(1< _delay_ms(40);
PORTD |= (1< P1 += times;
P1/=4.0; //取四次的平均值
return P1;
}
//===================主函数=================================
int main()
{
float P = 0.0;
float P1P2P3;
uint temp;
GPIO_Init();
Int_Init();
LCD_Init();
//----------------------白平衡调整-----------------------------
P = TCS3200(1);
P1 = 255.0/P;
P = TCS3200(2);
P2 = 255.0/P;
P = TCS3200(3);
P3 = 255.0/P;
while(1)
{
_delay_ms(700); //每秒钟判断一次
Write_Com(0x80); //液晶第一行
P=TCS3200(1);
temp= P1*P; //转换R
Write_Date(LCD_number[11]); //显示
Write_Date(LCD_number[temp/100%10]);
Write_Date(LCD_number[temp/10%10]);
Write_Date(LCD_number[temp%10]);
//-------------------------------------
Write_Com
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1463 2011-06-15 17:21 TCS3200\default\dep\TCS3200.o.d
文件 1961 2011-06-15 17:21 TCS3200\default\Makefile
文件 13 2011-06-15 17:21 TCS3200\default\TCS3200.eep
文件 35679 2011-06-15 17:21 TCS3200\default\TCS3200.elf
文件 14340 2011-06-15 17:21 TCS3200\default\TCS3200.hex
文件 105026 2011-06-15 17:21 TCS3200\default\TCS3200.lss
文件 31585 2011-06-15 17:21 TCS3200\default\TCS3200.map
文件 13052 2011-06-15 17:21 TCS3200\default\TCS3200.o
文件 2813 2011-06-14 22:14 TCS3200\TCS3200.aps
文件 236 2011-06-15 17:23 TCS3200\tcs3200.aws
文件 3770 2011-06-15 17:23 TCS3200\TCS3200.c
目录 0 2011-06-15 17:09 TCS3200\default\dep
目录 0 2011-06-15 17:21 TCS3200\default
目录 0 2011-06-15 17:23 TCS3200
----------- --------- ---------- ----- ----
209938 14
评论
共有 条评论