PIC microcontroller loop program application example

Publisher:和谐共处Latest update time:2011-02-24 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Here we introduce a timing program to illustrate the application of loop programs on PIC microcontrollers. The author still takes the PIC16F84 microcontroller as an example to establish its timing source program list. The timer source program only needs to change the constant setting of one instruction to make the timing time change continuously from minutes to 3.8 hours (4MHz crystal oscillator condition). For the hardware circuit of the PIC16F84 microcontroller, please see the experimental programmer 1.01 experimental board circuit in the 32nd issue of this newspaper. On this experimental board circuit, if the reader changes the frequency of the crystal oscillator (2MHz, 1MHz, 500kHz), it is easy to see that the timing time increases proportionally, which is very intuitive and interesting for understanding the performance of the PIC microcontroller. If one more loop is set on this source program, the timing time can be extended to more than 1 month.
The PIC16F84 microcontroller timing source program can be directly assembled under the MPLAB integrated development environment software. The HEX file generated after assembly can be used to solidify the source program on the experimental programmer 1.01 and the experimental results can be directly observed on the corresponding experimental board. The source program list for PIC16F84 microcontroller is as follows (each file can be customized):
LIST P=PIC16F84
#INCLUDE P16F84INC
COUNT1 EQU 0x1F
COUNT2 EQU 0x1E
COUNT3 EQU 0x1D
COUNT4 EQU 0x1C
ORG 0
START CLRW ; equivalent to MOVLW 0
BSF STATUS, 5; select body 1
MOVWF TRISB ; set port B to output
BCF STATUS, 5; reset STATUS to current body 0
CLRF PORTB ; timing start function M1 BTFSS PORTA, 1 ; judge the D1 bit of port A, jump when D1=1 , and execute sequentially
when D1=0 GOTO M2 GOTO M1 M2 MOVLW 0xAA ; select the timing bit of port B, LED lights up and starts timing MOVWF PORTB ; Port B outputs DELY CLRW at 0x10101010 ; Equivalent to MOVLW 0 MOVLW 0xFF MVOWF COUNT1 MVOWF COUNT2 MVOWF COUNT3 MOVLW 0 ; Equivalent to CLRW instruction MOVLW 0x02 ; 0x02 sends W (maximum timing is 0xFF) MOVWF COUNT4 ; Timing value control (fine adjustment) LOOP DECFSZ COUNT1, 1 ; CPUNT decreases by 1, jumps to GOTO LOOP DECFSZ COUNT2, 1 ; Same as above, here d=1, GOTO LOOP DECFSZ COUNT3, 1 ; Same as above GOTO LOOP DECFSZ COUNT4, 1 ; Same as above, but the value in COUNT4 can be freely selected GOTO LOOP CLRW ; Same as MOVLW 0 MOVLW 0x02; Timer ends and displays MOVWF PORTB M3 GOTO M3 END; Program ends Description: The constant settings in this source program can be changed by the reader at will, and any time setting can be achieved after the change.


























Reference address:PIC microcontroller loop program application example

Previous article:Features of PIC8-bit 8-pin microcontrollers 12C5×× and 12CE5×× series
Next article:Application of PIC16F877 Microcontroller--A/D Converter

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号