5. Advertising lights (using meter reading method)

Publisher:CoboroLatest update time:2016-09-22 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Experimental task 
: Use the table to make the port P1 change a single light: move left 2 times, move right 2 times, and flash 2 times (delay time 0.2 seconds).
2. Circuit diagram 
 
Figure 4.5.1
3. Hardware connection on the system board 
  Use an 8-core cable to connect P1.0-P1.7 in the "single-chip 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. Program design content 
When using a table for programming, the following instructions must be used to complete
(1).   Use the instruction MOV DPTR, #DATA16 to make the data pointer register point to the beginning of the table.
(2).   Use the instruction MOVC A, @A + DPTR, according to the value of the accumulator plus the value of DPTR, the program counter PC can be pointed to the data to be retrieved from the table.
Therefore, as long as the control code is built into a table and MOVC A, @A + DPTR is used to perform code retrieval operations, some complex control actions can be easily processed. The table retrieval process is shown in the figure below:
5.       Program flow chart 
  
  
  
  
  
  
  
  
  
  
  
 
Figure 4.5.2
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
                            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 !=0x01)          {            P1=table ;            i++;            delay();          }          else            {              i=0;            }      }  }





  







  















Reference address:5. Advertising lights (using meter reading method)

Previous article:6. Alarm generator
Next article:3. Multi-way switch status indication

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号