LED single light flashing experiment of PIC microcontroller under proteus+MPLAB combination

Publisher:创新火花Latest update time:2019-11-27 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

First put the circuit diagram, pay attention to the selection of capacitors on both sides of the crystal oscillator, and pay attention to the resistance value between the LED and the voltage.

The program is: Note that you must include the pic.h file, you must first determine the size of _XTAL_FREQ before using the __delay_ms macro, and pay attention to the magical effect of LED=~LED.


/*

Function: Make the LED flash at a certain time interval

*/

#include

#define _XTAL_FREQ 4000000UL //Oscillator frequency

#define LED RC5 //Because the LED light is connected to the RC5 pin


void main()

{

    TRISC = 0x00; //Set all PORTC to output

    PORTC = 0xff; //Set the output of PORTC to 1

    while(1)

    {

        LED=~LED; // Wonderful, one sentence realizes the flashing of the light. In the past, when I wrote it myself, I had to write it to turn on first, then delay, then turn it off, and then delay again. Here, one sentence solves it.

        __delay_ms(150); //This delay function is defined in the pic.h file. Before using it, you must first set the size of _XTAL_FREQ, the unit is Hz

    }

}

Reference address:LED single light flashing experiment of PIC microcontroller under proteus+MPLAB combination

Previous article:PIC microcontroller i2c program
Next article:PIC microcontroller learning independent buttons

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号