4. Move the advertising light left and right

Publisher:asdfrewqppLatest update time:2016-09-22 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. The experimental task 
is to move a single light left and right. The hardware circuit is shown in Figure 4.4.1. The eight light-emitting diodes L1-L8 are connected to the P1.0-P1.7 interfaces of the single-chip computer. When the output is "0", the light-emitting diodes light up. At the beginning, P1.0→P1.1→P1.2→P1.3→┅→P1.7→P1.6→┅→P1.0 lights up, and the cycle repeats. 
2. Circuit schematic diagram 
 
Figure 4.4.1 
3. Hardware connection on the system board 
Connect P1.0-P1.7 in the "single-chip system" area to the L1-L8 port in the "eight-way LED indicator module" area with an 8-core cable. The requirements are: P1.0 corresponds to L1, P1.1 corresponds to L2, ..., P1.7 corresponds to L8.
4. Program design content 
We can use the output port instruction MOV P1, A or MOV P1, #DATA. As long as the accumulator value or constant value is given, and then the above instruction is executed, the output control action can be achieved.
The data sent each time is different. The specific data is shown in Table 1 below
P1.7 
P1.6 
P1.5 
P1.4 
P1.3 
P1.2 
P1.1 
P1.0 
illustrate 
L8 
L7 
L6 
L5 
L4 
L3 
L2 
L1 
1
1
1
1
1
1
1
L1 Bright
1
1
1
1
1
1
1
L2 Bright
1
1
1
1
1
1
1
L3 Bright
1
1
1
1
1
1
1
L4 Bright
1
1
1
1
1
1
1
L5 Bright
1
1
1
1
1
1
1
L6 Bright
1
1
1
1
1
1
1
L7 Bright
1
1
1
1
1
1
1
L8 Bright
Table 1
5.       Flowchart 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
Figure 4.4.2
6. Assembly source program 
                   ORG 0 
START: MOV R2,#8 
                   MOV A,#0FEH 
                   SETB C 
LOOP: MOV P1,A 
                   LCALL DELAY 
                   RLC A 
                   DJNZ R2,LOOP 
                   MOV R2,#8 
LOOP1: MOV P1,A 
                   LCALL DELAY            
                   RRC A 
                   DJNZ R2 ,LOOP1 
                   LJMP START 
DELAY: MOV R5,#20; 
D1: MOV R6,#20 
D2: MOV R7,#248 
                   DJNZ R7,$ 
                   DJNZ R6,D2 
                   DJNZ R5,D1 
                   RET 
                   END 
7. C language source program 
#include  
unsigned char i; 
unsigned char temp; 
unsigned char a,b; 
  
void delay(void) 

  unsigned char m,n,s; 
  for(m=20;m>0;m --) 
  for(n=20;n>0;n--) 
  for(s=248;s>0;s--); 

void main(void) 

  while(1) 
    { 
      temp=0xfe; 
      P1= temp; 
      delay(); 
      for(i=1;i<8;i++) 
        { 
          a=temp<           b=temp>>(8-i); 
          P1=a|b; 
          delay(); 
        } 
      for( i=1;i<8;i++) 
        { 
          a=temp>>i; 
          b=temp<<(8-i); 
          P1=a|b; 
          delay(); 
        } 
    } 
}
Reference address:4. Move the advertising light left and right

Previous article:3. Multi-way switch status indication
Next article:1. Flashing lights

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号