Microcontroller C language programming: TIMER0 and TIMER1 control strip LED

Publisher:心灵律动Latest update time:2013-08-02 Source: 21icKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/* Name: TIMER0 and TIMER1 control the LED strip

Description: Timer T0 controls the previous set of LED strips at a faster scrolling speed

Timer T1 controls the next set of LED strips at a slower scrolling speed

*/

#include

#include

#define uchar unsigned char

#define uint unsigned int

uchar tc0=0,tc1=0;

//Main program

void main()

{

P0=0xfe;

P2=0xfe;

TMOD=0x11; //Timer 0 and Timer 1 both work in mode 1

 

TH0=(65536-15000)/256; //Timer 0: 15ms 

TL0=(65536-15000)%256;

TH1=(65536-50000)/256; //Timer 1: 50ms 

TL1=(65536-50000)%256;

IE=0x8a;

TR0=1; //Start the timer

TR1=1;

while(1);

//T0 interrupt function

void Time0() interrupt 1

{

TH0=(65536-15000)/256; //Restore the initial value of timer 0

TL0=(65536-15000)%256;

if(++tc0==10) //150ms conversion status

{


                           tc0=0;

                           P0=_crol_(P0,1);

                        }

}

//T1 interrupt function

void Time1() interrupt 3

{

TH0=(65536-50000)/256; //Restore the initial value of timer 1

TL0=(65536-50000)%256;

if(++tc1==10) //500ms conversion status

{

tc1=0;

P2=_crol_(P2,1);

}

}

Microcontroller C language programming: TIMER0 and TIMER1 control strip LED

Keywords:MCU Reference address:Microcontroller C language programming: TIMER0 and TIMER1 control strip LED

Previous article:Summary of MCU delay methods
Next article:Design of contactless IC card industrial water meter and its water selling system

Recommended ReadingLatest update time:2024-11-15 14:40

Design of interruption-style lighting based on 51 single-chip microcomputer
This design aims to use interrupt 0 (INT0) to complete the design of 2 styles of LED display. Operation method: Start simulation, then run demo2 style, wait for a while, and then press the switch "Change" to run another style. simulation: Reference Code: #include reg52.h #define uint unsigned int #define ucha
[Microcontroller]
Design of interruption-style lighting based on 51 single-chip microcomputer
Design of intelligent surge current tester based on 8031 ​​microcontroller and conversion system
introduction With the widespread application of rectifier diodes in the electronics industry, especially the home appliance industry, users have increasingly stringent requirements for the technical parameters of rectifier diodes. In China, the manufacturer's test standard (national standard) for rectifier diode surge
[Microcontroller]
Design of intelligent surge current tester based on 8031 ​​microcontroller and conversion system
Research and design of ARM single chip microcomputer height and distance measuring vehicle
Introduction: The current advanced electronic information science and technology has provided new ideas and solutions for the height and distance measurement in daily life. This design will use the remote control car as a measuring tool, and use angle sensors, Hall sensors and other sensors to obtain the measured phys
[Microcontroller]
Research and design of ARM single chip microcomputer height and distance measuring vehicle
Design of digital controlled current source based on single chip microcomputer
Abstract: This paper presents a design of digital current source based on single-chip microcomputer control. This design uses PIC16F877A single-chip microcomputer as the core component, and uses PID algorithm to achieve the functions of selectable range, adjustable output, precise stepping, and extremely small ripple
[Microcontroller]
Design of digital controlled current source based on single chip microcomputer
Simple game Proteus simulation program based on LCD12864 and 51 single chip microcomputer
Using LCD12864 as the display screen, a simple game controlled by a button is realized. The main work focuses on the graphics of the game and the realization of related logic. The character scene design is converted into segment code by font extraction software and stored in the microcontroller in advance. The animati
[Microcontroller]
Simple game Proteus simulation program based on LCD12864 and 51 single chip microcomputer
How is the microcontroller program executed? Where is the instruction data written?
The operation of a microcontroller requires the execution of a program, and hardware is also essential. Everyone knows that the operation of a microcontroller requires the execution of a written program, but where are the instructions of the microcontroller written? Where do you read the instructions? Let's start fr
[Microcontroller]
Development method of AVR microcontroller when lack of emulator
For FLASH memory microcontrollers, you can develop programs quickly and easily without an emulator. Specifically, you can start from the following aspects: 1. Try to use high-level languages ​​to develop system programs. Have you ever had the experience of wasting a lot of time to find the wrong label when writing an
[Microcontroller]
What is the microcontroller addressing mode? What are the addressing modes?
The way of finding the address of an operand is called the addressing mode. 1. Register addressing Register addressing means storing operands in registers, which include working registers R0~R7, accumulator A, general register B, address register DPTR, etc. For example, the instruction MOV R1, A transfers the data
[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号