PIC16F1826 timer to achieve breathing light effect main program

Publisher:ww313618Latest update time:2020-09-07 Source: 51heiKeywords:PIC16F1826 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

void main(void)

{

    TMR0IF=0; //Clear TMR0 interrupt flag

    TMR0=255; //Set the interrupt initial value to 255

    unsigned int k = 1;

    unsigned int TIMER0 = 0,TIMER1 = 0,TIMER2 = 0;

    unsigned char Flag_1 = 1;

    unsigned char Flag_2 = 1;

    unsigned char Flag_3 = 1;

    Pin_Init();

      Answ_Out = 0;

      Light1 = 0;

      Light2 = 0;

      Light3 = 0;

      Light4 = 0;

    while(1)

    {

        if( (TMR0IF == 1) && (Flag_1 ==1) ) // Enable timer overflow interrupt

        {

            TIMER0++; //Counter+1

            TMR0IF = 0; // Timer overflow flag cleared

            TMR0 = 255;

        }

        if(TIMER0 == k ) //If the counter value is equal to the set value

        {

            Light4 = 1; //light off

        }

        if(TIMER0 == 100 ) //Counter increases to 90

        {

            Light4 = 0; //Light on

            TIMER0 = 0;

            k++; //Set value initialization

        }

        if( k == 99 )

        {

            Light4 = 0;

            k =1;

            Flag_3 = 1;

            Flag_1 = 0;

        }

        if( (TMR0IF == 1) && (Flag_2 ==1) ) // Enable timer overflow interrupt

        {

            TIMER1++; //Counter+1

            TMR0IF = 0; // Timer overflow flag cleared

            TMR0 = 255;

        }

        if( TIMER1 == 40040)

        {

            Light4 = 1;

            TIMER1 = 0;

            Flag_1 = 1;

            Flag_2 = 0;

        }

        if( (TMR0IF == 1) && (Flag_3 ==1) ) // Enable timer overflow interrupt

        {

            TIMER2++; //Counter+1

            TMR0IF = 0; // Timer overflow flag cleared

            TMR0 = 255;

        }

        if(TIMER2 == k ) //If the counter value is equal to the set value

        {

            Light4 = 0; //Light on

        }

        if(TIMER2 == 100 ) //Counter increases to 90

        {

            Light4 = 1; //light off

            TIMER2 = 0;

            k++; //Set value initialization

        }

        if( k == 99 )

        {

            Light4 = 0;

            k =1;

            Flag_2 = 1;

            Flag_3 = 0;

        }

    }

}


Keywords:PIC16F1826 Reference address:PIC16F1826 timer to achieve breathing light effect main program

Previous article:PIC multi-channel ADC interrupt mode
Next article:PIC HEX file format analysis

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号