Advertising light design using table method

Publisher:Jinyu521Latest update time:2013-03-12 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Experimental tasks

Let's use the table-fetching method to implement the advertising light, so that port P1 can make a single light change: move left 2 times, move right 2 times, and flash 2 times (delay time 0.2 seconds).

2. Circuit diagram

Click to browse the next page

Figure 4.5.1

3. Hardware connection on the system board

Use an 8-core cable to connect P1.0-P1.7 in the "MCU System" area to the L1-L8 ports in the "Eight-way LED Indicator Module" area. The requirements are: P1.0 corresponds to L1, P1.1 corresponds to L2, ..., P1.7 corresponds to L8.

4. Programming content

When programming with a table, use the following instructions to complete

(1) Use the MOV DPTR, #DATA16 instruction to set the data pointer register to the beginning of the table.

(2) Using the instruction MOVC A, @A + DPTR, the program counter PC can be pointed to the data to be retrieved from the table based on the value of the accumulator plus the value of DPTR.

Therefore, as long as the control code is built into a table, and the MOVC function is used to perform the code retrieval operation, some complex control actions can be easily processed. The table retrieval process is shown in the figure below:

Click to browse the next page

Program flowchart[page]

6. Assembly source program

                            ORG 0

START: MOV DPTR,#TABLE

LOOP: CLR A

                            MOVC A,@A+DPTR

                            CJNE A,#01H,LOOP1

                            JMP START

LOOP1: MOV P1,A

                           MOV R3,#20

                            LCALL DELAY

                            INC DPTR

                           JMP LOOP

DELAY: MOV R4,#20

D1: MOV R5,#248

                            DJNZ R5,$

                            DJNZ R4,D1

                           DJNZ R3,DELAY

                            RET

TABLE: DB 0FEH,0FDH,0FBH,0F7H

                            DB 0EFH,0DFH,0BFH,07FH

                           DB 0FEH,0FDH,0FBH,0F7H

                            DB 0EFH,0DFH,0BFH,07FH               

                           DB 07FH,0BFH,0DFH,0EFH

                            DB 0F7H,0FBH,0FDH,0FEH

                            DB 07FH,0BFH,0DFH,0EFH

                            DB 0F7H,0FBH,0FDH,0FEH

                            DB 00H, 0FFH,00H, 0FFH

                            DB 01H

                            END

7. C language source program

#include

unsigned char code table[]={0xfe,0xfd,0xfb,0xf7,

                            0xef,0xdf,0xbf,0x7f,

                            0xfe,0xfd,0xfb,0xf7,

                            0xef,0xdf,0xbf,0x7f,

                            0x7f,0xbf,0xdf,0xef,

                            0xf7,0xfb,0xfd,0xfe,

                            0x7f,0xbf,0xdf,0xef,

                            0xf7,0xfb,0xfd,0xfe,

                            0x00,0xff,0x00,0xff,

                            0x01};

unsigned char i;

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)

    {

      if(table[i]!=0x01)

        {

          P1=table[i];

          i++;

          delay();

        }

        else

          {

            i=0;

          }

    }

}

The above is the full source code of the advertising light design

Reference address:Advertising light design using table method

Previous article:Single chip microcomputer IO parallel port directly drives LED display technology
Next article:Using software delay to realize 00-59 seconds single chip computer timing

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号