pic16f single chip source code, LED0 - LED5 light up in a row

Publisher:760802csyLatest update time:2019-10-30 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

//
// Experiment description: LED0 - LED5 flowing water lighting
//
// Notes:
//
//-------------------------------------------------------------------------------------------

#include "pic.h"

__CONFIG(FOSC_HS&WDTE_OFF&LVP_OFF); //External crystal WDT OFF

#define _XTAL_FREQ 8000000L //8MHz crystal


#define LED0 PORTCbits.RC2 //LED macro definition
#define LED1 PORTCbits.RC1
#define LED2 PORTCbits.RC0
#define LED3 PORTAbits.RA5
#define LED4 PORTAbits.RA3
#define LED5 PORTAbits.RA2

//-------------------------------------------------------------------------------
// Main program
//-------------------------------------------------------------------------------
void main(void)
{        
        ADCON1= 0b11001110; //RA0 for AN0 

        TRISA = 0b11010011; //RA2 RA3 RA5 output
        TRISB = 0b11111100; //RB0 RB1 output
        TRISC = 0b11011000; //RC0-RC2 output
        
        LED0 = 1; //LED0-LED5 light up
        LED1 = 1;
        LED2 = 1;
        LED3 = 1;
        LED4 = 1;
        LED5 = 1;
        __delay_ms(800); //delay
        LED0 = 0; //LED0-LED5 off
        LED1 = 0;
        LED2 = 0;
        LED3 = 0;
        LED4 = 0;
        LED5 = 0;
        __delay_ms(10); //delaywhile
        
        (1)
        {
                LED0 = 0; //LED5 light up
                LED1 = 0;
                LED2 = 0;
                LED3 = 0;
                LED4 = 0;
                LED5 = 1;
                __delay_ms(200); //delay
                LED0 = 0; //LED4-LED5 light up
                LED1 = 0;
                LED2 = 0;
                LED3 = 0;
                LED4 = 1;
                LED5 = 1;
                __delay_ms(200); //Delay
                LED0 = 0; //LED3-LED5 light up
                LED1 = 0;
                LED2 = 0;
                LED3 = 1;
                LED4 = 1;
                LED5 = 1;
                __delay_ms(200); //Delay
                LED0 = 0; //LED2-LED5 light up
                LED1 = 0;
                LED2 = 1;
                LED3 = 1;
                LED4 = 1;
                LED5 = 1;
                __delay_ms(200); //Delay
                LED0 = 0; //LED1-LED5 light up
                LED1 = 1;
                LED2 = 1;
                LED3 = 1;
                LED4 = 1;
                LED5 = 1;
                __delay_ms(200); //Delay
                LED0 = 1; //LED0-LED5 on
                LED1 = 1;
                LED2 = 1;
                LED3 = 1;
                LED4 = 1;
                LED5 = 1;
                __delay_ms(200); //Delay
                LED0 = 0; //LED0-LED5 off
                LED1 = 0;
                LED2 = 0;
                LED3 = 0;
                LED4 = 0;
                LED5 = 0;
                __delay_ms(200); //Delay
        }
}


//-------------------------------------------------------------------------------

Reference address:pic16f single chip source code, LED0 - LED5 light up in a row

Previous article:HC-SR04 ultrasonic module 51+PIC microcontroller routine
Next article:pic16f877 tm0 makes the LED flash every 10ms

Recommended ReadingLatest update time:2024-11-15 13:47

LED Light Emitting Diode Tester
  At present, LED light-emitting diodes are used not only as power switch indicators, but also as a light source.   The simple circuit described in this article can quickly test light-emitting diodes and distinguish whether they are low-current or high-power. Low-current light-emitting diodes use only 1-2mA of current
[Power Management]
LED Light Emitting Diode Tester
LED dimming system circuit design based on STC89C52 single chip microcomputer
The arrangement of the LEDs  and the specifications of the LED light source determine the basic driver requirements. The main function of an LED driver is to limit the current flowing through the LED under a certain range of operating conditions, regardless of how the input and output voltages vary. The most common me
[Power Management]
LED dimming system circuit design based on STC89C52 single chip microcomputer
H-bridge paves new way for LED lighting
The H-bridge is a classic circuit for driving a DC motor in a user-defined manner, such as forward/reverse direction or RPM controlled by PWM assistance of four discrete/integrated switches or electromechanical relays. It is widely used in machinery and power electronics. This Design Idea is a new implementation of th
[Power Management]
H-bridge paves new way for LED lighting
STM32 learning notes: using library functions to drive LED lights
1. Familiar with the GPIO structure The following structure is what I got from the official manual: view plain copy print? typedef struct { u16 GPIO_Pin; GPIOSpeed_TypeDef GPIO_Speed; GPIOMode_TypeDef GPIO_Mode; } GPIO_InitTypeDef; 2. Programming steps 1. First, define a GPIO_InitTypeDef structure and name the
[Microcontroller]
STM32 learning notes: using library functions to drive LED lights
LED Flash Supercapacitor Reference Design for High-Resolution Camera Phones
Battery life is becoming one of the most critical factors in system performance and reliability, and the introduction of supercapacitors will help extend battery life in two major application areas. First, they can dramatically reduce the cost of battery replacement in vehicles such as trucks, cars, boats and electric
[Power Management]
LED Flash Supercapacitor Reference Design for High-Resolution Camera Phones
Vehicle-mounted LEDs are climbing the "big mountain" that is a barrier to cost, and vehicle-mounted displays have become a new "growth pole"
Taking advantage of the trend of new energy vehicles and its advantages in brightness, contrast, power consumption and other aspects, automotive LEDs have experienced a wave of independent market trends even during the trough period of the industry. Moving forward to 2024, LED companies are still actively laying out
[Embedded]
崧盛电子IPO申请获受理 创业板或增LED驱动电源行业新兵
6月22日,深圳市崧盛电子股份有限公司(简称“崧盛股份”)创业板IPO申请获深交所受理。 据悉,崧盛股份于去年6月在新三板终止其股票挂牌。顶着市场竞争加剧、价格战趋于白热化以及肺炎疫情、中美贸易摩擦等多方问题形成压力,该公司踏上了创业板上市之路。面对这条路上的重重挑战,崧盛股份能否如愿以偿? 据招股书显示,崧盛股份是一家专注于中、大功率LED驱动电源产品的研发、生产和销售业务,是目前国内中、大功率LED驱动电源产品的主要供应商之一。公司产品主要供应下游LED 照明生产厂商用于制造中、大功率LED照明产品,终端产品主要应用于城市路桥、高速公路、隧道、机场等大型户外LED照明设施,以及工业厂房、仓库等LED工业照明设施,同时正向植
[Mobile phone portable]
Linux driver - LED blinking
Connect the development board and PC, then turn on the power switch of the S3C development board. After successful startup, execute the build.sh script file to compile and install the LED driver. The build script file will automatically upload the driver's .ko file to the S3C development board and install it. T
[Microcontroller]
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号