Programming implementation of P0 water lamp

Publisher:HarmonyInLifeLatest update time:2012-08-29 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include 

#include
#inclde
void delay(unsigned char time) //The function must be declared, otherwise the following error will occur:
void main()
{
 P0 = 0xfe; //P must be uppercase
while(1)
{
 delay(200);
 P0 = _cror_(P0,1);
 }
}
void delay()
{
 unsigned char I,j;
    for(i=0;i<=time;i++)
       {
        for(j=0;j<=200;j++)
          { _nop_(); //Null instruction, calculated according to the machine cycle of the microcontroller
          }
       }
 }
Another way to achieve this:
Application of sbit
Data Type Notes:

Data Types
Number of digits
Number of bytes
Numerical range
illustrate
bit
1
0 or 1
Position type
Signed char
8
1
-128——+127
Signed byte type
Unsigned char
8
1
0~255
Character or eight-bit unsigned integer
enum
16
2
-32768~+32767
Enumeration
Signed short
16
2
-32768~+32767
Signed short integer
Unsigned short
16
2
0~6535
Unsigned short integer
Signed int
16
2
-32768~32767
Unsigned int
Signed long
Unsigned long
float
Spit
1
0 1
Position type
Sfr
8
1
0~255
8-bit special function register
Sfr16

Program code:
#include
#include
#include
sbit P0_0 = P0^0; // I/O port definition method, the difference between the two, if not defined in this way, it will be said that it is not defined
    sbit P0_1 = P0^1;
   sbit P0_2 = P0^2;
   sbit P0_3 = P0^3;
   sbit P0_4 = P0^4;
   sbit P0_5 = p0^5;
   sbit P0_6 = P0^6;
   sbit P0_7 = P0^7;
void delay(unsigned char time); //Function declaration, important
void main()
{
   while(1)
{
P0_0 = 0;
delay(200);
P0_1 = 0;
delay(200);
P0_3 = 0;
delay(200);
P0_4 = 0;
delay(200);
P0_5 = 0;
delay(200);
P0_6 = 0;
delay(200);
P0_7 = 0;
delay(200);
}
void delay(unsigned char time)
{
   unsigned char i,j;
   for(i=0;i<=time;i++)
{
      for(j=0;j<=200;j++)
         {
           _nop_()
         }
     }
}
   
Control the on and off procedure:
#include// Port definition is already included in this header file, so P0 can be directly assigned
 #include
#include
void delay(unsigned char time);
void delay(unsigned char time)
{
   unsigned i,j;
   for(i=0;i<=time;i++)
      {
        for(j=0;j<=200;j++)
           {
            _nop_();
           }
       }
}
void main()
{
 while(1)
   {
    P0 = 0x00;
    delay(200);
    P0 = 0xff;
    delay(200);
   }
}
Reference address:Programming implementation of P0 water lamp

Previous article:Small RTOS keyboard scanner
Next article:Single chip remote synchronization lamp circuit + program

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号