AVR microcontroller (ATMEGA16) timer program

Publisher:温馨生活Latest update time:2018-06-21 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include  

#include  

#define uchar unsigned char  

#define uint unsigned int  

#pragma interrupt_handler timer1:9  

flying i,temp;  

void delay(uint x)  

{  

 uint y,z;  

 for(y=x;y>0;y--)  

                 for(z=1111;z>0;z--);  

}  

void main(void)  

{  

 i=0;  

 temp=0x01;  

 TCCR1B=0x04; //T/C1 clock source, 256 division  

 TCNT1H=0x85; //Assign initial value, external crystal oscillator 8M, timing 1s  

 TCNT1L=0xed;  

 TIMSK=0x04; //Open T/C1 interrupt  

 SREG=0x80;   

 DDRB=0xff;  

 while(1);  

}  

void timer1(void)  

{  

 TCNT1H=0x85;    

 TCNT1L=0xed;  

 if(i<8)  

 {  

  PORTB=temp;  

  temp<<=1;  

  i++;  

 }  

 else  

 {  

  i=0;  

  temp=0x01;  

 }  

}  


Reference address:AVR microcontroller (ATMEGA16) timer program

Previous article:ATmega16A uses the process PC port to solve
Next article:AVR microcontroller (ATmega16L) DS18B20 temperature sensor driver

Recommended ReadingLatest update time:2024-11-16 09:44

PIC16F877A microcontroller (interrupt and timer Timer1)
1 Basic principles In the figure above, if an external crystal oscillator is connected to the left side of RC0, then T1OSCEN must be set to 1. The frequency of this external crystal oscillator is generally low. The lower the crystal oscillator frequency, the lower the power consumption. Why is an external cry
[Microcontroller]
PIC16F877A microcontroller (interrupt and timer Timer1)
ATmega16 Development Board Tutorial (1) - LED Lighting
2. LED lights up When used as a general digital IO, the IO of the AVR microcontroller has read, write and modify functions. Each port has 3 registers: DDRx, PORTx, and PINx. DDRx: 1-output, 0-input. When configured as input, PORTx=1, pull-up enabled, PORTx=0, high configuration; when configured as output, PORTx=1, o
[Microcontroller]
ATmega16 Development Board Tutorial (1) - LED Lighting
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号