//ICC-AVR application builder : 2007-5-6 21:30:57
I love avr, I love virtual instruments.
Keywords:ATMage16
Reference address:PWM application of 16-bit timer of ATMage16
// Target : M16
// Crystal: 8.0000Mhz
//TIMER1 initialize - prescale:64
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 1Hz
// actual value: 1.000Hz (0.0%)
#include
#include
#define PWM1A PORTD5 //OC1A PD5
#define PWM1B PORTD4 //OC1B PD4
unsigned char OCAH;
unsigned char OCAL;
unsigned char OCBH;
unsigned char OCBL;
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0x00; //setup
TCNT1L = 0x01;
OCR1AH = OCAH;
OCR1AL = OCAL;
OCR1BH = OCBH;
OCR1BL = OCBL;
ICR1H = 0xff; // pwm 的计数顶值
ICR1L = 0xFF;
TCCR1A = 0xA3; // 匹配清零 top置位
TCCR1B = 0x0B; // start Timer
}
void init_devices(unsigned char valueah,unsigned char valueal,unsigned char valuebh,unsigned char valuebl)
{
OCAH=valueah;
OCAL=valueal;
OCBH=valuebh;
OCBL=valuebl;
CLI();
//disable all interrupts
timer1_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x04; //timer interrupt sources
SEI(); //re-enable interrupts
}
void main(void)
{
PORTD&=(0<
DDRD|=(1<
init_devices(0x0f,0x45,0x0f,0xf0); //修改实参即可改变占空比,最大值为0X0FFF;
while(1);
}
// Crystal: 8.0000Mhz
//TIMER1 initialize - prescale:64
// WGM: 10) PWM phz correct, TOP= ICRn
// desired value: 1Hz
// actual value: 1.000Hz (0.0%)
#include
#include
#define PWM1A
#define PWM1B
unsigned char OCAH;
unsigned char OCAL;
unsigned char OCBH;
unsigned char OCBL;
void timer1_init(void)
{
TCCR1B = 0x00;
TCNT1H = 0x00;
TCNT1L = 0x01;
OCR1AH = OCAH;
OCR1AL = OCAL;
OCR1BH = OCBH;
OCR1BL = OCBL;
ICR1H = 0xff;
ICR1L = 0xFF;
TCCR1A = 0xA3;
TCCR1B = 0x0B;
}
void init_devices(unsigned char valueah,unsigned char valueal,unsigned char valuebh,unsigned char valuebl)
{
OCAH=valueah;
OCAL=valueal;
OCBH=valuebh;
OCBL=valuebl;
CLI();
timer1_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x04;
SEI();
}
void main(void)
{
PORTD&=(0<
while(1);
}
[Copy to clipboard]
I love avr, I love virtual instruments.
Previous article:AVR MCU Research (8): GCC-AVR Interrupts
Next article:Use of AVR serial port getchar(), getchar(), printf() and other functions
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
Guess you like
- Summary of performance indicators of integrated operational amplifiers
- 【Top Micro Intelligent Display Module】Three: Interface editing tool SGTools
- C2000 LaunchPad - SIC Interrupt Reception
- [Automatic clock-in and walking timing system based on face recognition] BLE automatic time calibration and scanning wearable watch/scan
- EEWORLD University ---- Cisco CCNA+CCNP Learning Tutorial
- What are the differences between level conversion chips and digital ADU isolation chips? Aren't they both designed to match their own voltage...
- IIC communication of msp430g2553
- How to get the free page block of STM32' MCU internal flash
- Using MicroPython to run app-like functions on a single chip
- What software do you usually use when doing circuit simulation?