51 MCU Course Design: Color Copy Display Based on TCS230/3200

Publisher:温柔浪漫Latest update time:2021-06-29 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This program displays the data read from the color recognition module on LCD1602, and generates corresponding PWM waves to operate the three-color lights to display different colors, so as to achieve color replication and display. The wiring methods of each module are introduced in detail in the source code. At the same time, related project files and materials can be downloaded at the bottom of the article.


Regarding the problem of garbled characters when pasting and copying: If garbled characters appear in the comments when the program is copied to the Keil compiler, you can first create a .c file, that is, do not edit it in Keil, then open the .c file with Notepad, copy the source code into it, and then add the file in Keil.


/******************************************************************************************

                               Based on TCS3200/230 color reproduction display

 * Purpose: Used for color copy display, the TCS3200 module converts the acquired data into the corresponding PWM wave to display it on the three-color light and also displays it on the LCD1602

 *Wiring method 

    P0 is LCD1602 data port

    P2.5 connects to LCD1602 RS

    P2.6 connects to LCD1602 RW

    P2.7 connects to LCD1602 EN

 *Three-color light connection method

    P1.5 to the red terminal

    P1.6 connects to the green terminal

    P1.7 connects to the blue terminal

 *TCS3200 connection method

    Module S2-----MCU P1.1

    Module S3-----MCU P1.0

    Module OUT----MCU P3.5 (Counter 1 input)

    Module VCC----MCU VCC

    Module GND----MCU GND

******************************************************************************************/

#include

#include //Keil library  

#include //Keil library

#include

#define uchar unsigned char

#define uint unsigned int

#define DataPort P0 //LCD1602 data port

sbit LCM_RS=P2^5; //LCD1602 control port

sbit LCM_RW=P2^6; //LCD1602 control port

sbit LCM_EN=P2^7; //LCD1602 control port

sbit Red=P1^5;        

sbit Green=P1^6;

sbit Blue=P1^7;

/**Pin definition**/  

sbit s2=P1^1; //TCS3200 S2 

sbit s3=P1^0; //TCS3200 S3

                     //TCS3200 S0 module internal default pull-up

                     //TCS3200 S1 module internal default pull-up

                     //TCS3200 OE module internal grounding

sbit test_pin=P1^2; //Use an oscilloscope to observe this pin to know the timer interrupt frequency

//Definition of variables and constants

uchar ge,shi,bai ;

uchar rp=3,gp=3,bp=6; //Define the scale factor, which can be modified in specific environment

uchar count; //Color flag (0: red 1: green 2: blue)

uint RC=0,GC=0,BC=0;

// Display array

uchar disp_R[3]; //red

uchar disp_G[3]; //green

uchar disp_B[3]; //blue

//********Define function*********************************

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);

//************LCD1602 initialization************************

void InitLcd()

{

    WriteCommandLCM(0x38,1);

    WriteCommandLCM(0x08,1);

    WriteCommandLCM(0x01,1);

    WriteCommandLCM(0x06,1);

    WriteCommandLCM(0x0c,1);

}

//**********Detect busy signal****************************

void WaitForEnable(void)

{

    DataPort=0xff;

    LCM_RS=0;LCM_RW=1;_nop_();

    LCM_EN=1;_nop_();_nop_();

    while(DataPort&0x80);

    LCM_EN=0;

}

//**********Write command to 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;

}

//**********Write data to LCD************************

void WriteDataLCM(uchar dataW)

{

    WaitForEnable();

    LCM_RS=1;LCM_RW=0;_nop_();

    DataPort=dataW;_nop_();

    LCM_EN=1;_nop_();_nop_();LCM_EN=0;

}

//************Write a character data to the specified target************

void DisplayOneChar(uchar X,uchar Y,uchar DData)

{

    Y&=1;

    X&=15;

    if(Y)X|=0x40;

    X|=0x80;

    WriteCommandLCM(X,0);

    WriteDataLCM(DData);

}

//**********Delay function***************

void delay(unsigned int k)

{

    unsigned int i,j;

    for(i=0;i    {

        for(j=0;j<121;j++)

        {;}

    }

}            

/***********************************************

* Function name: t0_init()

* Function: Timer 0 initialization

* Input parameters: None

* Export parameters: None

/************************************************/

void t0_init()

{

    TMOD=0x51; //T1 counts T0 timing working mode 1

    TH1=0x00; //Counting initial value

    TL1=0x00;

    TH0=0xE0;

    TL0=0x00; //11.0592M crystal oscillator 10ms

    EA=1; //Enable interrupt

    ET0=1;        

    TR0=1; //Start

    TR1=1;

}

//************************************************

// Convert the value into ASCII code of tens, hundreds, and thousands

//************************************************

void conversion(uint temp_data)  

{  

    bai=temp_data/100+0x30;

    temp_data=temp_data%100; //Remainder operation

    shi=temp_data/10+0x30;

    ge=temp_data%10+0x30; // remainder operation

}

/***********************************************

* Function name: main()

/************************************************/

void main()

{

    delay(10); 

    InitLcd(); //lcd initialization

    s2=0; //Initial setting of S2 pin

    s3=0; //Initial setting of S3 pin

    t0_init(); //Timer counting initialization?

    while(1)

    {

        uint count = 0;

        /**********************The dumbest way

        Display various colors through the main function loop

        ******************/

        while(1)

        {

            if(count<=RC)

            {

                Red = 0;

            }

            else

            {

                Red = 1;

            }

            if(count<=BC)

            {

                Blue = 0;

            }

            else

            {

                Blue = 1;

            }

            if(count<=GC)

            {

                Green = 0;

            }

            else

            {

                Green = 1;

            }

                  

            count++;

            if(count>=256)

            {

                count = 0;

            }

        }   

    }

}

/***********************************************

* Function name: c10ms_out() 

* Function: Timer interrupt 0 service routine

            Modify the color flag disp_tc (0: red 1: green 2: blue)

            Set S0 S1 S2 Select filter

            Count pulses and read color values

* Input parameters: None

* Export parameters: None

/************************************************/

void c10ms_out() interrupt 1

{

    uint temp;

    test_pin=!test_pin; //Test the timer interrupt frequency pin, which can be observed with an oscilloscope

    TR0=0; //Turn off timing

    TR1=0; //Close the count

    // count+1 detects green first, then blue, then red, and repeats the detection       

    if(count==0)

    {

        count++;    

        s2=1;s3=1; //Select filter as green     

        temp=(8<        temp/=rp;

        GC=temp;

        conversion(temp);

        disp_R[2]=ge;         

        disp_R[1]=shi;

        disp_R[0]=bai;

    }

    else if(count==1)

    {            

        count++;

        s2=1;s3=0; //Select filter as blue

        temp=(8<        temp/=gp;

        BC=temp;

        conversion(temp);

        disp_G[2]=ge;         

        disp_G[1]=shi;

        disp_G[0]=bai;

    }

    else if(count==2)

    {            

        count=0;

        s2=0;s3=0; //Select filter as red

        temp=(8<        temp/=bp;

        RC=temp;

        conversion(temp);

        disp_B[2]=ge;         

        disp_B[1]=shi;

        disp_B[0]=bai;

    }

    DisplayOneChar(0, 0, 'T');

    DisplayOneChar(1, 0, 'C');

    DisplayOneChar(2, 0, 'S');

    DisplayOneChar(3, 0, '2');

    DisplayOneChar(4, 0, '3');

    DisplayOneChar(5, 0, '0');

    DisplayOneChar(10, 0, 'R'); 

    DisplayOneChar(11, 0, '['); 

    DisplayOneChar(12, 0, disp_R[0]); 

    DisplayOneChar(13, 0, disp_R[1]); 

    DisplayOneChar(14, 0, disp_R[2]);

    DisplayOneChar(15, 0, ']');

    DisplayOneChar(0, 1, 'G'); 

    DisplayOneChar(1, 1, '['); 

    DisplayOneChar(2, 1, disp_G[0]); 

    DisplayOneChar(3, 1, disp_G[1]); 

    DisplayOneChar(4, 1, disp_G[2]);

    DisplayOneChar(5, 1, ']');

    DisplayOneChar(10, 1, 'B'); 

    DisplayOneChar(11, 1, '['); 

    DisplayOneChar(12, 1, disp_B[0]); 

    DisplayOneChar(13, 1, disp_B[1]); 

    DisplayOneChar(14, 1, disp_B[2]);

    DisplayOneChar(15, 1, ']');

    //Re-initialize the timer counter

    TH0=0x01;

    TL0=0x00; //11.0592M crystal oscillator, 10ms

    TL1=0x00; //Counter clear

    TH1=0x00; //Counter clear

    TR0=1; //Turn on the timer

    TR1=1; //Open the counter

}


Reference address:51 MCU Course Design: Color Copy Display Based on TCS230/3200

Previous article:The smallest fragment of a single chip microcomputer [with pictures] [very detailed]
Next article:51 single chip microcomputer course design: temperature and humidity alarm based on DHT11

Recommended ReadingLatest update time:2024-11-15 15:25

Microcontroller literacy: the relationship between MCS51 and 8051/8031, etc.
We always talk about 8051, 8031, and now there is 89C51 and 89s51. What is the relationship between them? MCS51 refers to the general name of a series of single- chip microcomputers produced by the American INTEL company (yes, the famous INTEL) . This series of single-chip microcomputers includes many varieties, su
[Power Management]
Experiment 7 Design a clock using the timer of the 51 microcontroller
1. Using the experimental board and accessories, design a clock. The time is displayed on the LCD1602 and updated by seconds. Three buttons can be designed on the experimental board to adjust the hours, minutes, and seconds. Its functions are: function selection key, value increase and value decrease key. Use the AT24C
[Microcontroller]
Using 89c51 single chip microcomputer to program an adjustable perpetual calendar
Recently I need to write the biggest project since I started learning microcontrollers for a week. It feels quite challenging. The topic is as follows: 1) Project 1 (Remote Clock Control System) Project background: Time is very important to everyone, especially in today's fast-developing world. Every city has a ce
[Microcontroller]
Anti-interference design of single chip microcomputer C8051f064 in power monitoring instrument
    The single-chip microcomputer c8051f064 is a new type of single-chip microcomputer launched by Cygnal (now SILIConlab) around 2000. It has the advantages of fast running speed and compatibility with the 8051 instruction system. As soon as it was launched, it was welcomed by the majority of 8031 ​​users in China. M
[Microcontroller]
51 MCU tutorial: 8*8 dot matrix display of characters, numbers, and simple Chinese characters
Dot matrix display experiment 1. What is a dot matrix? With the previous method, one IO port can only control one LED. What if we need to control more LEDs with fewer IO ports? So there is dot matrix. The 8X8 dot matrix is ​​composed of 64 light-emitting diodes, and each light-emitting diode is placed at the interse
[Microcontroller]
51 MCU tutorial: 8*8 dot matrix display of characters, numbers, and simple Chinese characters
51 MCU driving stepper motor protues simulation
Circuit Diagram: protues仿真文件和完整代码下载地址:http://www.51hei.com/bbs/dpj-20399-1.html 下面是部分程序代码: #include"reg51.h" #include"intrins.h" #include"math.h" #include"absacc.h" #define  PORTA  XBYTE #define  PORTB  XBYTE #define  PORTC  XBYTE #define  PORTC0 XBYTE #define nop _nop_() #define Right_RUN  1 #define Left
[Microcontroller]
51 MCU driving stepper motor protues simulation
Resistance-temperature measurement system of carbon black composite conductive material based on 51 single chip microcomputer
0 Preface With the rapid development of the electronics industry and information technology, the demand for polymer materials with conductive functions is becoming more and more urgent. Conductive composite materials have the characteristics of light weight, no corrosion, easy to process into various complex shapes,
[Microcontroller]
Resistance-temperature measurement system of carbon black composite conductive material based on 51 single chip microcomputer
MCS-51 MCU Timer/Counter Basics
The MCS-51 sub-series microcontroller has two timer/counters, namely timer/counter 0 and 1. In addition to the above two timer/counters, the 52 sub-series microcontroller (8032/8052) also has a timer/counter 2, which has stronger functions than the previous two. 1 Timer/Counter 0 and 1 In the dedicated register TM
[Microcontroller]
MCS-51 MCU Timer/Counter Basics
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号