Design of single chip flashing light

Publisher:创意火舞Latest update time:2012-09-12 Source: 21ic Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;********************************************************
;* This program is a LED light cycle flashing program, use the INT key to switch*
;* Flashing mode*www.dangdangdz.com
;********************************************************
include
;*----
MODESEL equ 20h
MODESELB equ 21h
Count equ 22h
Count1 equ 23h
Count2 equ 24h
PORTDB equ 25h

;*-----

org 0
goto start
org 4
goto ISR

org 10
start
clrf PORTD ; clear port D
movlw 00h
movwf MODESEL ; initialize mode select register
movwf MODESELB
movlw b\'10010000\'
movwf INTCON ; initialize interrupt control
bsf STATUS,RP0
clrf TRISD ; set port D to output
movlw b\'10111111\'
OPTION ; select INT falling edge to be valid

bcf STATUS,RP0
call FMsel
movwf PORTDB
movwf PORTD
main btfsc PORTB,0 ;
goto $+6 ;
call Delay ; key debounce
btfsc PORTB,0
goto $+3 ; /
call FMsel ;/
movwf PORTDB
movf MODESELB,W ;
movwf MODESEL ;
call LongDelay
bcf STATUS,C
rlf PORTDB,1
btfsc STATUS,C
bsf PORTDB,0
movf PORTDB,W
movwf PORTD
goto main

;*----------
Delay ; call instruction takes 2 instruction cycles
clrf Count ; clear Count takes 1 instruction cycle
Dloop
decfsz Count,f ; these two lines of instructions will delay
goto Dloop ; (256 * 3) -1 instruction cycle
return ; return takes 2 instruction cycles

;*----------------
LongDelay
clrf Count
clrf Count1
movlw 0x01
movwf Count2
LDloop
decfsz Count,f
goto LDloop
decfsz Count1,f
goto LDloop
decfsz Count2,f
goto LDloop
return

[page]

;*---------------
FMsel
movf MODESEL,w
movwf MODESELB
movf MODESEL,w
addwf PCL
retlw b\'11111000\'
retlw b\'11110000\'
retlw b\'11100000\ '
retlw b\'11000000\'
retlw b\'10000000\'
movlw 00h
movwf MODESELB
bsf INTCON,GIE
retlw b\'11111000\'
return

;*-------------
ISR
btfss INTCON,INTF
goto $+3
bcf INTCON,INTF
incf MODESEL
retfie
end

Programming method of single chip microcomputer controlling LED light flashing

1: Program start (START)

2: A=00000000B

3: PORT 0

4: Delay (DELAY)

5: A=11111111B

6: PORT 0

7: Delay

8: Back to the beginning

Delay subroutine programming method:

1: R6=0

2:DEL1

3: R7=0

4: $

5: R7-1

6: R7=0 is not equal to 0, return 2

7: R6-1

8: R6=0 is not equal to 0, return 4

Return to the main program

Keywords:MCU Reference address:Design of single chip flashing light

Previous article:Single chip microcomputer dynamic digital display technology
Next article:C language source code of frequency meter based on single chip microcomputer

Recommended ReadingLatest update time:2024-11-16 22:52

Small resistance tester based on single chip microcomputer design
1. Introduction In the process of circuit testing, it is often encountered that there is a large error between the experimental data and the theoretical value due to the neglect of the influence of some small resistances, thus affecting the test effect. For example, copper resistance often exists in inducto
[Test Measurement]
Small resistance tester based on single chip microcomputer design
C51 MCU writes an external interrupt (entry-level MCU)
Code section void main() { /*---------------EA,IT,EX must write-------------*/ EA=1; // Enable general interrupt IT1=1; //interrupt trigger mode             //=0 is low level trigger, =1 is falling edge trigger   EX1=1; //External interrupt enable bit       while(1) {     led1=0;     } }     void int1
[Microcontroller]
C51 MCU writes an external interrupt (entry-level MCU)
PIC microcontroller basic learning program design
PIC microcontroller (Peripheral Interface Controller) is an integrated circuit (IC) used to develop and control peripheral devices. It is a CPU with decentralized (multi-tasking) functions. This content describes the learning of programming in PIC microcontrollers. 1. Basic format of PIC microcontroller program
[Microcontroller]
Design of Motor Control System Based on 51 Single Chip Microcomputer
O Introduction Motor control has a wide range of applications in monitoring equipment, medical equipment, electric valves, electric curtains, household appliances, rotating lamps, etc. Therefore, it is very meaningful to design a motor control system with good controllability and high precision. This article int
[Microcontroller]
Design of Motor Control System Based on 51 Single Chip Microcomputer
The rise of Renesas MCU in recent years
Friends who often read my official WeChat public account articles should have noticed that I have shared a lot about Renesas MCU this year. Again, you will find that Renesas Electronics has developed rapidly in recent years, with a large number of online and offline activities, and new MCU products cons
[Automotive Electronics]
AVR MCU download error using progisp flash verify error at :0h
Atmega16 uses progisp to download and reports flash verify error at :0h   After a lot of hard work to find the cause, I finally found a solution, you can refer to it. First, make sure the ATmega16 microcontroller is not constantly in reset and that all pins are properly connected. Secondly, do not check "Automatically
[Microcontroller]
Design of DC Motor PWM Speed ​​Control System Based on 51 Single Chip Microcomputer
Design ideas The main functions of the DC motor PWM control system include: realizing the acceleration, deceleration, forward rotation, reverse rotation and emergency stop of the DC motor, and adjusting the speed of the motor, which can easily realize the intelligent control of the motor. Main circuit: DC motor PWM
[Microcontroller]
Design of DC Motor PWM Speed ​​Control System Based on 51 Single Chip Microcomputer
SHT11 Temperature and Humidity Sensor AVR MCU Program
#include "shtxx.h"  void shtxx_init(void)  {      shtxx_temp = shtxx_humi = 0;      SHTXX_ SCK _LOW();      SHTXX_DAT_1();     shtxx_reconnect();  }  void shtxx_reconnect(void)  {      SHTXX_DAT_1();      SHTXX_SCK_LOW();      for(uint8 i=0; i 9; i++)      {          SHTXX_SCK_HIGH(); SHTXX_SCK_LOW();      }      SHT
[Microcontroller]
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号