Simple program for timer counting LED display

Publisher:数据迷航者Latest update time:2012-11-10 Source: 21IC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*
Note: This program mainly shows how to use the timer to count
. It is a relatively simple program that reflects modular sub-functions
*/

#include //header file
#define uchar unsigned char //macro definition
#define uint unsigned int
uchar count; //define global variables
void display_led() //led display sub-function
{
if(count==20) //changes every 1S (crystal oscillator: 12MHZ)
{
count=0; //count cleared for next count
P2=~P2; //P2 value inverted
P2=P2<<1; //P2 value shifted left
P2=~P2;
if(P2==0xff) //if the last LED is on,
P2=0xfe; //then the first LED is on
}
}
void init() //initialization sub-function
{
EA=1; //turn on total interrupt
ET0=1; //turn on timer interrupt
TR0=1; //start timer
TMOD=0x01; //T0 working mode 1, 16-bit counting
TH0=(65536-50000)/256; //Set the initial value of the timer
TL0=(65536-50000)%256;
P2=0xfe; //Assign initial value to P2 port
while(1)
{
display_led(); //Call LED display sub-function
}
}
void main() //Main function
{
init(); //Call initialization sub-function
}
void delay() interrupt 1 //Timed interrupt sub-function
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++; //Count variable plus 1
}

Reference address:Simple program for timer counting LED display

Previous article:An improved voltage regulating circuit controlled by STC12C2052AD single chip microcomputer
Next article:Simple program for timer counting LED display

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号