PIC16F84A single chip microcomputer LED light circuit and source program

Publisher:码梦小子Latest update time:2014-11-19 Source: 21icKeywords:PIC16F84ALED Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The following is an example of controlling the on and off of any of the 8 LEDs connected to the port register PORTB of the PIC16F84A microcontroller to introduce the writing of the relevant C language program. The circuit is shown in the figure below.

PIC16F84A MCU lighting circuit diagram PIC16F84A FLASH LED
The C language source program generated by using MPLABIDEV7.40 integrated development environment and PICC compiler is also called source file.
When writing C source program, you need to define the hardware header file (also called include header file or header file). Because the standard register addresses and their bit addresses that users often use are defined in the Pic.h header file. According to the syntax rules of the C language compiler to compile the source program, when writing the C language program, you must use the #include statement to include this pic.h header file into your own source program. That is, for the PIC intermediate product microcontroller, the beginning of the C language program is a fixed format #include. When the compiler compiles and processes the #include statement, it will copy the content of pic.h to your source program, so that PICC will think that the port address and the bit address of the standard register used by the user have been defined, and the source program will legally use these standard registers and their corresponding bits.

The program list for lighting up 8 LEDs connected to PORTB of PIC16F84A microcontroller and lighting up the LEDs connected to positions 1, 2, and 6 respectively is as follows (source file name is PIC01.C):

PIC16F84A MCU lighting circuit and source program PIC16F84A FLASH LED

PIC16F84A MCU lighting circuit and source program PIC16F84A FLASH LED

Description: The above is a complete C program that can execute the LED lighting in the above figure. It mainly consists of the bit definition of the port register PORTB, the definition of the delay function delay(); the main function main(), the delay function voiddelay() and various statements.

The description text starting with the symbol "∥" in the third line of the C program is a comment, which can be written in one line or in multiple lines. Comments can be written anywhere in the program to help read and understand the program, explain the relevant functions and precautions of the program, and explain the relevant algorithms. Comments should be as simple as possible. When compiling, comments do not generate code. C programs can also use the content between the beginning of "/#" and the end of "#/" as comments, which is equivalent to the comments starting with the symbol "∥". The
first line of the above program is the header file with the #include statement at the beginning of the boot program.
The second line is the bit definition of the PIC microcontroller PORTB port, which refers to 8 bits here, that is, (&add)*8.
The third line is the comment of the bit definition of the port register PORTB in the second line.
The fourth to sixth lines are the definitions of the three bits RB0, RB1, and RB6 of the port register PORTB, so that they can be assigned values ​​in the subsequent program.
The seventh line is the definition comment of the three bits RB0, RB1, and RB6.
The eighth line is the definition of the delay function. The functions from the ninth line to the end (see the relevant comments).

Keywords:PIC16F84ALED Reference address:PIC16F84A single chip microcomputer LED light circuit and source program

Previous article:Touch button design based on 8-bit MCU
Next article:Development of an Embedded Radar Transmitter Fault Monitoring System

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号