atmega8 example: T1 timer CTC mode square wave output

Publisher:温柔微笑Latest update time:2022-02-09 Source: eefocusKeywords:atmega8 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere


/*******************************************************************

* Function library description: ATMEGA8 T1 timer CTC mode square wave output

* Version: v1.00        

* Edited by: Pang Hui, Wuhu Lianda Freescale Studio                     

* Modified on: August 8, 2011    

*        

* Description: OC1A changes the logic level every time a comparison match occurs, that is, a square wave output with a frequency of 50% 2ms

* At this time, OC1A should be set to output

*                                                          

* Version update: See readme.txt for details

*

* 20110805 V1.02                                            

*                                                                                          

********************************************************************

*Note: When used as a square wave output, whether OCR1A or ICR1 is used as the TOP value, the output pin is OC1A

* 6M external crystal

********************************************************************/

 

#include

 

int main(void)

{

    //OC1A is set to output. When used as a square wave output, it must be set to output

    DDRB |= (1 << PB1);

    //6M crystal oscillator 8-frequency division 1ms level inversion once, that is, square wave frequency 2ms

    //OCR1A = 750;

    ICR1 = 750;

    //OC1A match inversion

    TCCR1A |= (1 << COM1A0);

    //CTC OCR1A mode, 8-division 6M / 8 = 750khz and start CTC mode

    //TCCR1B |= (1 << WGM12) | (1 << CS11);

    TCCR1B |= (1 << WGM13) | (1 << WGM12) | (1 << CS11);

 

    while(1);

 

    return 0;

}


Keywords:atmega8 Reference address:atmega8 example: T1 timer CTC mode square wave output

Previous article:Let atmega8 define IO pins like Freescale xs128
Next article:AVR MCU-nRF24L01 sending and receiving program

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号