TCS230颜色识别—原理—程序.doc_第1页
TCS230颜色识别—原理—程序.doc_第2页
TCS230颜色识别—原理—程序.doc_第3页
TCS230颜色识别—原理—程序.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/* 文件名: * 功能: * 说明: /*/#include #include #include 12864.h/颜色识别器色光滤波器选择:红色(S2,S3=0,0),蓝色(S2,S3=0,1),绿色(S2,S3=1,1)#define S2 _PC7#define S3 _PC6/变量、常量定义volatile uchar red=0,blue=0,green=0,flag=0,i=0,j=0,data5=0;volatile uint counter=0;/中断定义#pragma interrupt_handler interrupt_int2:4 #pragma interrupt_handler interrupt_timer1:15/* 函数名称: int2_init()* 函数功能: 外部中断2初始化* 入口参数: 无* 出口参数: 无/*/void int2_init() DDRD &= BIT(2);/中断引脚设置为输入 PORTD |= BIT(2); /设置输出口上拉 EICRA = 0X20; /下降沿触发/* 函数名称: timer1_init()* 函数功能: 定时器1初始化* 入口参数: 无* 出口参数: 无/*/void timer1_init() TCCR1B = 0X02;/ 设置分频数为8TCNT1H = 0x63;/ 设置计数初值, 定时20ms TCNT1L = 0xC0;/* 函数名称: port_init()* 函数功能: 端口初始化* 入口参数: 无* 出口参数: 无/*/void port_init() DDRA = 0XFF;/PORTA30为液晶数据线 DDRC = 0XFF;/控制S2与S3 /* 函数名称: main()/*/void main(void) port_init(); int2_init(); timer1_init(); Init_12864(); LcmClearTXT(); /文本区清RAM函数 Display_x_y_data(0,0,颜色识别:); Display_x_y_data(1,0,红色成分:); Display_x_y_data(2,0,蓝色成分:); Display_x_y_data(3,0,绿色成分:); S2=0;/先检测红色(S2,S3=0,0) S3=0; SEI(); EIMSK |= BIT(2); /打开外部中断 TIMSK |= BIT(2);/打开溢出中断 while(1); /* 函数名称: interrupt_int2() * 函数功能: * 入口参数: 无* 出口参数: 无/*/void interrupt_int2() counter+;/* 函数名称: interrupt_timer1()* 函数功能: * 入口参数: 无* 出口参数: 无/*/void interrupt_timer1() CLI();/关总中断 TCCR1B = 0X00;/定时器停止工作TIMSK &= BIT(2);/关闭溢出中断EIMSK &= BIT(2); /关闭外部中断 flag+;/实现先检测红色,再检测蓝色,然后检测绿色,循环检测if(flag=1) red=counter; data0=counter/100+0x30; counter=counter%100; data1=counter/10+0x30; counter=counter%10; data2=counter+0x30; Locate_x_y(1,5); for(i=0;i3;i+) Writedata(datai); S2=0;/下次检测蓝色(S2,S3=0,1)S3=1;else if(flag=2) blue=counter; data0=counter/100+0x30; counter=counter%100; data1=counter/10+0x30; counter=counter%10; data2=counter+0x30; Locate_x_y(2,5); for(i=0;i3;i+) Writedata(datai); S2=1;/下次检测绿色(S2,S3=1,1)S3=1; else if(flag=3) green=counter; data0=counter/100+0x30; counter=counter%100; data1=counter/10+0x30; counter=counter%10; data2=counter+0x30; Locate_x_y(3,5); for(i=0;i(blue+green) Display_x_y_data(0,5,红色); else if(blue+8red)&(blue+2green) Display_x_y_data(0,5,蓝色); else if(green-3blue) Display_x_y_data(0,5,黄色); else if(green+5red)&(greenblue) Display_x_y_data(0,5,绿色); /*else if(bluered)&(greenblue) Display_x_y_data(0,5,白色);*/ else Display_x_y_data(0,5,未知); /delay_ms(200); counter = 0;/清零外中断计数

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论