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

標題: 有沒有大佬幫忙看看這個單片機程序我寫的是用tcs230然后用數(shù)碼管顯示 [打印本頁]

作者: forky    時間: 2024-5-17 13:04
標題: 有沒有大佬幫忙看看這個單片機程序我寫的是用tcs230然后用數(shù)碼管顯示
我現(xiàn)在為了測試我上面的tcs傳感器的程序簡便使用數(shù)碼管檢驗我的顏色傳感器是否可以識別,我結果無論是什么顏色都顯示1,但是我的數(shù)碼管直接不亮,有大佬可以幫我看一下是單片機程序的問題還是我傳感器的問題?

#include <reg52.h>
#include<math.h>       //Keil library  
#include<stdio.h>      //Keil library        
#include<INTRINS.H>
#define uchar unsigned char

sbit S2 = P0^0;
sbit S3 = P0^1;
sbit OUT = P0^2;
sbit S0 = P0^3;
sbit S1 = P0^4;
sbit P2_0 = P2^0;
sbit P2_1 = P2^1;
sbit P2_2 = P2^2;
sbit P2_3 = P2^3;
int white_balance_red,white_balance_green,white_balance_blue;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
                        0xf8,0x80,0x90};

void delay(unsigned int t) {
    unsigned int i, j;
    for (i = 0; i < t; i++)
        for (j = 0; j < 125; j++);
}


unsigned int read_pulse() {
          return 100;
}


void perform_white_balance() {

    S2 = 0;
    S3 = 0;
    delay(100);
    white_balance_red = read_pulse();
    S2 = 1;
    S3 = 1;
    delay(100);
    white_balance_green = read_pulse();
    S2 = 0;
    S3 = 1;
    delay(100);
    white_balance_blue = read_pulse();
}
unsigned char recognize_color() {
    unsigned int red_pulse, green_pulse, blue_pulse;
    red_pulse = read_pulse();
    green_pulse = read_pulse();
    blue_pulse = read_pulse();
    red_pulse -= white_balance_red;
    green_pulse -= white_balance_green;
    blue_pulse -= white_balance_blue;
    if (red_pulse > 200 && green_pulse > 200 && blue_pulse > 200) {
        return 'W';
    } else if (red_pulse > green_pulse && red_pulse > blue_pulse) {
        return 'R';
    } else if (green_pulse > red_pulse && green_pulse > blue_pulse) {
        return 'G';
    } else if (blue_pulse > red_pulse && blue_pulse > green_pulse) {
        return 'B';
    } else if (red_pulse > 150 && green_pulse > 100 && blue_pulse < 100) {
        return 'Y';
    } else if (red_pulse < 50 && green_pulse < 50 && blue_pulse < 50) {
        return 'K';
    } else {
        return 'U';
    }
}



void main() {
    unsigned char color;
    perform_white_balance();
    while (1) {   
        color = recognize_color_with_white_balance();
        switch (color) {
            case 'W':   
                                                                  P0=table[0];
                                                                  P2_0 = 0;
                                                                  delay(5);
                                                                  P2_0 = 1;
                break;
            case 'R':   P0=table[0];
                        P2_0 = 0;
                        delay(5);
                        P2_0 = 1;
                break;
            case 'G':   P0=table[0];
                                                                                                P2_0 = 0;
                                                                                                delay(5);
                                                                                                P2_0 = 1;
                break;
            case 'B':   P0=table[0];
                                                                                                P2_0 = 0;
                                                                                                delay(5);
                                                                                                P2_0 = 1;
               break;
            case 'Y':   P0=table[0];
                                                                                                P2_0 = 0;
                                                                                                delay(5);
                                                                                                P2_0 = 1;

                                OLED_Clear();
                break;
            case 'K':   P0=table[0];
   P2_0 = 0;
   delay(5);
   P2_0 = 1;

                break;
        }
    }
}




作者: rundstedt    時間: 2024-5-17 14:30
white_balance_red這幾個變量名字太長了吧,標準c語言支持31字符長度變量,這么寫沒問題。但是C51他不標準啊!查下最多支持幾個字符?
作者: 人中狼    時間: 2024-5-17 15:33
編譯沒報錯嗎
作者: lkc8210    時間: 2024-5-17 17:57
你這代碼只會顯示0,絕不會顯示1
看不到哪里有讀取tcs230的代碼
作者: forky    時間: 2024-5-17 19:08
發(fā)表于 2024-5-17 14:30
white_balance_red這幾個變量名字太長了吧,標準c語言支持31字符長度變量,這么寫沒問題。但是C51他不標準 ...

他可以支持255個但是前32個有效,但是我在keil上可以編譯但燒入到單片機上我的顏色傳感器沒反應

作者: forky    時間: 2024-5-17 19:29
發(fā)表于 2024-5-17 14:30
white_balance_red這幾個變量名字太長了吧,標準c語言支持31字符長度變量,這么寫沒問題。但是C51他不標準 ...

我現(xiàn)在把變量名改短了但是我的數(shù)碼管還是不會顯示
作者: forky    時間: 2024-5-17 21:14
lkc8210 發(fā)表于 2024-5-17 17:57
你這代碼只會顯示0,絕不會顯示1
看不到哪里有讀取tcs230的代碼

打錯了是0,我的目的就是為了檢驗我的tcs230能不能用
作者: forky    時間: 2024-5-17 21:22
人中狼 發(fā)表于 2024-5-17 15:33
編譯沒報錯嗎

沒有報錯就是用不了
作者: forky    時間: 2024-5-17 21:57
lkc8210 發(fā)表于 2024-5-17 17:57
你這代碼只會顯示0,絕不會顯示1
看不到哪里有讀取tcs230的代碼

怎么提取呀我不太會
作者: 人中狼    時間: 2024-5-17 22:15
recognize_color_with_white_balance();這個代碼在哪里
作者: forky    時間: 2024-5-17 23:30
人中狼 發(fā)表于 2024-5-17 22:15
recognize_color_with_white_balance();這個代碼在哪里

好像沒有那是用recognize_color就好了嘛
作者: 人中狼    時間: 2024-5-18 19:03
forky 發(fā)表于 2024-5-17 23:30
好像沒有那是用recognize_color就好了嘛

while (1) {   
        color = recognize_color_with_white_balance();
        switch (color) {
感覺你的問題很隨意,答復的也很隨意




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