Make a 15-channel output colored light

Publisher:灵感驿站Latest update time:2018-05-08 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

//I want to make a 15-channel color light, use P0.0~P0.7 and P2.0~P2.6 ports for output; the preset number is 15 1s (decimal 32767).
//Set two buttons +1 (P3.3) and -1 (P3.4).
//You can subtract to decimal 32047. If you continue to press the -1 button after reaching 32047, you can return to 32767 and subtract again.
//The same is true for addition. After adding to 32767, press the +1 button to return to 32047 and add 1 again.
//Set another button (P2.7). When P2.7 is grounded, subtract the decimal number 1712 from the currently displayed number to display it.
//Looking for a single-chip color light program.

Best answer:
//===========================
#include
sbit K_1 = P3^3; //+
sbit K_2 = P3^4; //-
sbit D_1 = P2^7; //Display mode selection
//----------------------------
void delay_ms(unsigned int n)
{
    unsigned char j;
    while(n--) for(j = 0; j < 230; j++); //230 is obtained from experimental test!
}

void main()
{
    unsigned int m;
    m = 32767;
    while(1) {
      if (D_1 == 1) {
        P2 = ~(m / 256); 
        P0 = ~(m % 256);
      }
      else {
        P2 = ~ ((m - 1712) / 256);       
        P0 = ~((m - 1712) % 256);
      }
      if (K_1 == 0) {
        delay_ms(10);
        if (K_1 == 0) {
          m++;
          if (m > 32767) m = 32047;
          while(K_1 == 0);
      } }
      if (K_2 == 0) {
        delay_ms(10);
        if (K_2 == 0) {
          m--;
          if (m < 32047) m = 32767;
          while(K_2 == 0);
    } } }
}
//============================= 
The PROTEUS simulation screen of this program is as follows: Make a 15-channel output colored light - Non-famous blogger - Electronic Information Corner


Reference address:Make a 15-channel output colored light

Previous article:On the Accuracy of Single Chip Microcomputer Measuring Signal Frequency
Next article:Determine the order in which the microcontroller keys are pressed

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号