PIC10F202 single-chip dual-color headlight control source program

Publisher:TranquilOasisLatest update time:2019-11-07 Source: 51heiKeywords:PIC10F202 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The two-color car light GP2 made by PIC10F202 is used for switch detection. GP0 and GP1 control two LEDs respectively. When powered on, the GP0 pure white lamp bead lights up. When the switch is powered off once, it switches to the GP1 warm white lamp bead. When the switch is powered off again, it flashes alternately.

The microcontroller source program is as follows:

#include

__CONFIG(0X010);

#define uchar unsigned char

#define uint unsigned int

#define TIME_MAX 1000

uint key2_time_cnt; //key debounce counter

uchar num;

uchar key_flag; 


void Delay_mS(uint n)

{

  uint j;

  uchar k;

    for(j=0;j      for(k=246;k>0;k--)

       NOP();

}

void key_scan()

{

   if(GP2==0) //button pressed

    {

      

       while(key2_time_cnt!=TIME_MAX)

        {       

          key2_time_cnt++;

        }

       key_flag=1;

     }

    else

     {

        key2_time_cnt=0;

        if(key_flag==1)

          {

            key_flag=0;

            num++;

            if(num>2)

             num=0;

          }

     }  

}

void main()

{

   TRISGPIO=0b00000100;

   GP0=1;

   GP1=0;


   while(1)

    {

      key_scan();     

      switch(num)

       {

        case 0: GP0=1; // white light is on

                 GP1=0; break;

        case 1: GP0=0;

                 GP1=1;break;//Huang Guangliang

        case 2: GP0=0;

                 GP1=1;

                 Delay_mS(5);

                 GP0=1;

                 GP1=0;

                 Delay_mS(5);break; //Alternate flashing              

       } 

    } 

}



Keywords:PIC10F202 Reference address:PIC10F202 single-chip dual-color headlight control source program

Previous article:PIC10F202 makes a button to switch two relays
Next article:(Haier) Neusoft MCU HR7P153 SOP-16 digital tube display program

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号