欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: GY-31 TCS3200顏色傳感器單片機(jī)源程序與資料下載 [打印本頁(yè)]

作者: Maxwell123    時(shí)間: 2019-3-10 02:39
標(biāo)題: GY-31 TCS3200顏色傳感器單片機(jī)源程序與資料下載
TCS3200的輔助設(shè)計(jì)電路原理圖如下:


單片機(jī)源程序如下:
  1. /*******************************************
  2. * 文件名: TCS3200顏色測(cè)試
  3. * 型號(hào):   GY-31
  4. * 功能:   讀取RGB值
  5. * 單片機(jī): STC89C52
  6. * 晶振:   11.0592m
  7. * 時(shí)間:   2011-3-20
  8. * LCD1602顯示R,G,B值
  9. /********************************************/
  10. //接線說(shuō)明:
  11. //模塊S2-----單片機(jī)P1.1
  12. //模塊S3-----單片機(jī)P1.0
  13. //模塊OUT----單片機(jī)P3.5(計(jì)數(shù)器1輸入)
  14. //模塊VCC----單片機(jī)VCC
  15. //模塊GND----單片機(jī)GND
  16. //**********************************************
  17. #include<REG52.H>   
  18. #include<math.h>       //Keil library  
  19. #include<stdio.h>      //Keil library   
  20. #include<INTRINS.H>
  21. #define uchar unsigned char
  22. #define uint  unsigned int   
  23. #define DataPort P0       //LCD1602 數(shù)據(jù)端口   
  24. sbit    LCM_RS=P2^0;   //LCD1602 控制端口        
  25. sbit    LCM_RW=P2^1;   //LCD1602 控制端口   
  26. sbit    LCM_EN=P2^2;   //LCD1602 控制端口

  27. /**引腳定義**/  
  28. sbit s2=P1^1;        //TCS3200 S2
  29. sbit s3=P1^0;        //TCS3200 S3
  30.                      //TCS3200 S0 模塊內(nèi)部默認(rèn)上拉
  31.                      //TCS3200 S1 模塊內(nèi)部默認(rèn)上拉
  32.                      //TCS3200 OE 模塊內(nèi)部接地
  33. sbit test_pin=P1^2;  //用示波器看這個(gè)引腳,可知道定時(shí)器中斷頻率
  34. //變量、常量定義
  35. uchar ge,shi,bai ;
  36. uchar rp=2,gp=2,bp=2; //定義比例因子,具體環(huán)境可以修改
  37. uchar count;          //顏色標(biāo)志位(0:紅 1:綠 2:藍(lán))

  38. //顯示數(shù)組
  39. uchar disp_R[3];  //紅
  40. uchar disp_G[3];  //綠
  41. uchar disp_B[3];  //藍(lán)

  42. //********定義函數(shù)*****************************
  43. void    delay(unsigned int k);
  44. void    InitLcd();
  45. void    WriteDataLCM(uchar dataW);
  46. void    WriteCommandLCM(uchar CMD,uchar Attribc);
  47. void    DisplayOneChar(uchar X,uchar Y,uchar DData);

  48. //*********LCD1602初始化**********************
  49. void InitLcd()               
  50. {            
  51.     WriteCommandLCM(0x38,1);   
  52.     WriteCommandLCM(0x08,1);   
  53.     WriteCommandLCM(0x01,1);
  54.     WriteCommandLCM(0x06,1);   
  55.     WriteCommandLCM(0x0c,1);
  56. }

  57. //**********檢測(cè)忙信號(hào)************************
  58. void WaitForEnable(void)   
  59. {                    
  60.     DataPort=0xff;        
  61.     LCM_RS=0;LCM_RW=1;_nop_();
  62.     LCM_EN=1;_nop_();_nop_();
  63.     while(DataPort&0x80);   
  64.     LCM_EN=0;               
  65. }
  66.                     
  67. //**********寫(xiě)命令至LCD***********************
  68. void WriteCommandLCM(uchar CMD,uchar Attribc)
  69. {                    
  70.     if(Attribc)WaitForEnable();   
  71.     LCM_RS=0;LCM_RW=0;_nop_();
  72.     DataPort=CMD;_nop_();   
  73.     LCM_EN=1;_nop_();_nop_();LCM_EN=0;
  74. }   
  75.                
  76. //**********寫(xiě)數(shù)據(jù)至LCD************************
  77. void WriteDataLCM(uchar dataW)
  78. {                    
  79.     WaitForEnable();        
  80.     LCM_RS=1;LCM_RW=0;_nop_();
  81.     DataPort=dataW;_nop_();   
  82.     LCM_EN=1;_nop_();_nop_();LCM_EN=0;
  83. }
  84.                     
  85. //*********寫(xiě)一個(gè)字符數(shù)據(jù)到指定的目標(biāo)***********
  86. void DisplayOneChar(uchar X,uchar Y,uchar DData)
  87. {                        
  88.     Y&=1;                        
  89.     X&=15;                        
  90.     if(Y)X|=0x40;                    
  91.     X|=0x80;            
  92.     WriteCommandLCM(X,0);        
  93.     WriteDataLCM(DData);        
  94. }

  95. //**********延時(shí)函數(shù)***************
  96. void delay(unsigned int k)   
  97. {                        
  98.     unsigned int i,j;               
  99.     for(i=0;i<k;i++)
  100.     {            
  101.     for(j=0;j<121;j++)            
  102.     {;}
  103.     }                        
  104. }                                    

  105. /*******************************************
  106. * 函數(shù)名稱(chēng): t0_init()
  107. * 函數(shù)功能: 定時(shí)器0初始化
  108. * 入口參數(shù): 無(wú)
  109. * 出口參數(shù): 無(wú)
  110. /********************************************/
  111. void t0_init()
  112. {
  113.      TMOD=0x51;        //T1計(jì)數(shù) T0定時(shí) 工作方式1
  114.      
  115.      TH1=0x00;        //計(jì)數(shù)初值
  116.      TL1=0x00;

  117.      TH0=0xE0;
  118.      TL0=0x00;        //11。0592M 晶振10ms
  119.      EA=1;            //開(kāi)中斷

  120.      ET0=1;        
  121.      TR0=1;           //啟動(dòng)
  122.      TR1=1;
  123. }

  124. //*********************************************
  125. //數(shù)值轉(zhuǎn)換出個(gè)十百千的ASCII碼
  126. //*********************************************
  127. void conversion(uint temp_data)  
  128. {  
  129.     bai=temp_data/100+0x30 ;
  130.     temp_data=temp_data%100;   //取余運(yùn)算
  131.     shi=temp_data/10+0x30 ;
  132.     ge=temp_data%10+0x30;      //取余運(yùn)算
  133. }

  134. /*******************************************
  135. * 函數(shù)名稱(chēng): c10ms_out()
  136. * 函數(shù)功能: 定時(shí)中斷0服務(wù)程序
  137.             修改顏色標(biāo)志disp_tc(0:紅 1:綠 2:藍(lán))
  138.             設(shè)置S0 S1 S2 選擇濾波器
  139.             計(jì)算脈沖,讀取色值
  140. * 入口參數(shù): 無(wú)
  141. * 出口參數(shù): 無(wú)
  142. /********************************************/
  143. void c10ms_out() interrupt 1
  144. {  uint temp;
  145.         test_pin=!test_pin; //測(cè)試定時(shí)器中斷頻率引腳,可以用示波器觀察
  146.         TR0=0;              //關(guān)閉定時(shí)
  147.         TR1=0;              //關(guān)閉計(jì)數(shù)
  148. //   count+1實(shí)現(xiàn)先檢測(cè)綠色,再檢測(cè)藍(lán)色,然后檢測(cè)紅色,循環(huán)檢測(cè)      
  149.         if(count==0)
  150.         {
  151.         count++;   
  152.         s2=1;s3=1;             //選擇濾波器為綠色     
  153.       
  154.         temp=(8<<TH1)+TL1;    //計(jì)算這段時(shí)間內(nèi) TCS230 的輸出脈沖數(shù)   
  155.         temp/=rp;            
  156.         conversion(temp);
  157.         disp_R[2]=ge;         //因?yàn)檫@次的中斷,是上次選擇濾波器的數(shù)值
  158.         disp_R[1]=shi;
  159.         disp_R[0]=bai;
  160.         }

  161.         else if(count==1)
  162.         {            
  163.         count++;
  164.         s2=0;s3=1;            //選擇濾波器為藍(lán)色

  165.         temp=(8<<TH1)+TL1;    //計(jì)算這段時(shí)間內(nèi) TCS230 的輸出脈沖數(shù)   
  166.         temp/=gp;            
  167.         conversion(temp);
  168.         disp_G[2]=ge;         //因?yàn)檫@次的中斷,是上次選擇濾波器的數(shù)值
  169.         disp_G[1]=shi;
  170.         disp_G[0]=bai;
  171.         }

  172.         else if(count==2)
  173.         {            
  174.         count=0;
  175.         s2=0;s3=0;            //選擇濾波器為紅色
  176.       
  177.         temp=(8<<TH1)+TL1;    //計(jì)算這段時(shí)間內(nèi) TCS230 的輸出脈沖數(shù)   
  178.         temp/=bp;        
  179.         conversion(temp);
  180.           disp_B[2]=ge;         //因?yàn)檫@次的中斷,是上次選擇濾波器的數(shù)值
  181.         disp_B[1]=shi;
  182.         disp_B[0]=bai;

  183.         }

  184.      //定時(shí)器計(jì)數(shù)器重賦初值
  185.      TH0=0xE0;
  186.      TL0=0x00; //11。0592M 晶振,為10ms
  187.      TL1=0x00;//計(jì)數(shù)器清零
  188.      TH1=0x00;//計(jì)數(shù)器清零
  189.      TR0=1;   //打開(kāi)定時(shí)器
  190.      TR1=1;   //打開(kāi)計(jì)數(shù)器
  191. }


  192. /*******************************************
  193. * 函數(shù)名稱(chēng): main()
  194. /********************************************/
  195. void main()
  196. {

  197.       delay(10);
  198.       InitLcd();      //lcd初始化
  199.       s2=0;           //初始設(shè)定S2引腳
  200.       s3=0;           //初始設(shè)定S3引腳
  201.       t0_init();      //定時(shí)計(jì)數(shù)初使化

  202.      while(1)
  203.      {
  204.      
  205.         DisplayOneChar(0,0,'G');
  206.         DisplayOneChar(1,0,':');
  207.         DisplayOneChar(2,0,disp_G[0]);
  208.         DisplayOneChar(3,0,disp_G[1]);
  209.         DisplayOneChar(4,0,disp_G[2]);         //綠

  210.         DisplayOneChar(6,0,'B');
  211.         DisplayOneChar(7,0,':');
  212.         DisplayOneChar(8,0,disp_B[0]);
  213.         DisplayOneChar(9,0,disp_B[1]);
  214.         DisplayOneChar(10,0,disp_B[2]);     //藍(lán)


  215.         DisplayOneChar(0,1,'R');
  216.         DisplayOneChar(1,1,':');
  217.         DisplayOneChar(2,1,disp_R[0]);
  218.         DisplayOneChar(3,1,disp_R[1]);
  219.         DisplayOneChar(4,1,disp_R[2]);         //紅               

  220.         delay(100) ;


  221.      }
  222. }
復(fù)制代碼

程序下載:
GY-31顏色模塊發(fā)送資料.7z (1.65 MB, 下載次數(shù): 111)


作者: 12LED    時(shí)間: 2021-12-10 19:07
有電路實(shí)圖嗎


作者: yhmjjm    時(shí)間: 2022-4-13 14:44
請(qǐng)問(wèn)一下,為什么上面的程序壓縮包里沒(méi)有啊
作者: heicad    時(shí)間: 2022-4-13 16:28
yhmjjm 發(fā)表于 2022-4-13 14:44
請(qǐng)問(wèn)一下,為什么上面的程序壓縮包里沒(méi)有啊

里面有,我找到了 在STC-GY-31顏色模塊測(cè)試 里面的STC51_TCS3200.C
作者: yhmjjm    時(shí)間: 2022-4-14 19:41
heicad 發(fā)表于 2022-4-13 16:28
里面有,我找到了 在STC-GY-31顏色模塊測(cè)試 里面的STC51_TCS3200.C

好的,謝謝




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1