Timer 1 basic experiment: Make the LED connected to the PB port flash in a cycle

Publisher:雅意盎然Latest update time:2016-10-29 Source: eefocusKeywords:Timer Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include

#include
unsigned char n=0;
void port_init(void) //Port initialization function
{
 DDRB = 0xFF; //Port B is defined as output
}

void timer1_init(void) //Timer 1 initialization: 0.5 second timing, prescaler 256
{
 TCCR1B = 0x00; //stop
 TCNT1H = 0xF8; //setup
 TCNT1L = 0x5F;
 TCCR1A = 0x00;
 TCCR1B = 0x04; //start Timer
}

void main(void)
{
 port_init(); //initialize output port
 CLI(); //disable all interrupts

 MCUCR = 0x00;
 GICR = 0x00;
 TIMSK = 0x05; //timer interrupt sources
 SEI(); //re-enable interrupts
       //all peripherals are now initialised
 timer1_init(); //Timer 1 initialization
 while(1) //loop
  {
  ;
  }
}


#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void) //定时中断入口
{
 TCNT1H = 0xF8;     //reload counter high value
 TCNT1L = 0x5F;     //reload counter low value
 if(n>=1)
  {
 n=0;
 PORTB=55;
 }
 else
  {
 PORTB=0xAA;
 n=n+1;
 }
}

Keywords:Timer Reference address:Timer 1 basic experiment: Make the LED connected to the PB port flash in a cycle

Previous article:How to drive LCD1602 to display and move left and right
Next article:IIC's PCF8563 practical clock program (iccavr)

Recommended ReadingLatest update time:2024-11-16 21:00

Explanation of the onboard LED light control program based on the STC15W series
Preface Hello, everyone. I am a beginner of STC15W series microcontrollers. I am very happy to share my learning experience with you on this platform. Now let’s get back to the topic. Let’s start learning about the STC15W4K56S4 microcontroller! 1. Introduction to STC15W4K56S4 MCU    This study is based on the S
[Microcontroller]
Explanation of the onboard LED light control program based on the STC15W series
GaN, a key material for high-power LEDs, begins to encroach on the silicon power MOSFET market
The era of super semiconductor material GaN (gallium nitride) is opening. It is more voltage-resistant than traditional silicon and GaAs (gallium arsenide), and has become one of the key materials for high-power LEDs . It is also favored in the RF field, including Cree , RF MD,
[Power Management]
GaN, a key material for high-power LEDs, begins to encroach on the silicon power MOSFET market
CL300 Series LED ± Symbol Display Components
CL300 series LED ± symbol display is a display function module composed of a strong drive CMOS integrated circuit and an LED ± symbol display. It has four functions of reversible counting, storage, decoding drive and LED display. Its principle block diagram is shown in the figure. Figure: LED, symbol
[Power Management]
CL300 Series LED ± Symbol Display Components
How to test the quality of LED lights with a multimeter
With the development of electronic technology, daily lighting keeps up with the times and incorporates electronic technology. In order to save energy, lamps also use LEDs (light-emitting diodes), which are made of dozens of high-energy LEDs connected in series and parallel. There are many ways to power LED lamps.
[Test Measurement]
GEC210 led water lamp C language to achieve ADS engineering
Software environment: ADS1.2 Development board: GEC210 Theoretical knowledge: Refer to the introduction of LED principle Because ADS needs to be entered from assembly by default, our code first calls a short assembly and then jumps directly to C language The source code is as follows led.c #define GPJ2CON (*
[Microcontroller]
GEC210 led water lamp C language to achieve ADS engineering
75% of LED lamps have problems due to LED driver power supply
At present, the penetration rate of LED lighting in general lighting fields such as indoor lighting, street and regional lighting, landscape lighting, commercial building lighting and billboard lighting is still relatively low, far lower than other types of lighting. "Reliability and price are a constraint on the rapi
[Power Management]
Eight advantages of LED light source
As the latest lighting technology, LED has advantages not only in terms of light quality, but also in terms of production, manufacturing and ease of use, which greatly surpass traditional light sources such as incandescent lamps and fluorescent lamps. Therefore, since its birth in the 1960s, it has been rapidly de
[Power Management]
A novel LED dynamic display method
LED is often used as a display in single-chip microcomputer application systems. When multiple LED displays are required, in order to simplify the circuit and reduce costs, the selection lines of all gates are often connected in parallel and controlled by an 8-bit I/O port, while the common cathode (positive) I/O li
[Power Management]
A novel LED dynamic display method
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号