圣龙扬特-AVR电子

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 734|回复: 0
打印 上一主题 下一主题

ICCAVR的6路PWM输出实验

[复制链接]

26

主题

1

好友

3446

积分

超级版主

Rank: 8Rank: 8

UID
7
帖子
140
精华
0
注册时间
2013-2-26
在线时间
20 小时

突出贡献

跳转到指定楼层
楼主
发表于 2013-2-28 20:05:52 |只看该作者 |倒序浏览
//ICC-AVR application builder : 2008-7-12 20:25:58
// Target : M16
// Crystal: 7.3728Mhz

#include <iom16v.h>
#include <macros.h>

unsigned char m;                                //定义全局变量

void port_init(void)
        {
        PORTA = 0xFF;
        DDRA  = 0x00;
        PORTB = 0x00;
        DDRB  = 0xFF;
        }

//TIMER1 initialize - prescale:64
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 2Hz
// actual value:  2.000Hz (0.0%)
void timer1_init(void)
        {
        TCCR1B = 0x00;
        TCNT1H = 0x1F;
        TCNT1L = 0x01;
        TCCR1A = 0x00;
        TCCR1B = 0x03;
        }

#pragma interrupt_handler timer1_compa_isr:7
void timer1_compa_isr(void)
        {
        PORTB = 0x00;                                        //清端口
        }

#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
        {
        TCNT1H = 0x1F;
        TCNT1L = 0x01;
        m++;
        if(m>=6)m=0;
        PORTB |= 1<<m;                                        //各端口置1
        }

//call this routine to initialize all peripherals
void init_devices(void)
        {
        CLI();
        port_init();
        timer1_init();

        MCUCR = 0x00;
        GICR  = 0x00;
        TIMSK = 0x14;                                        //允许溢出中断和匹配中断
        SEI();
        }

void main(void)
        {
        init_devices();
        OCR1A = 20000;                                        //比较匹配值,此值决定脉冲宽度
       
        while(1);
        }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

Archiver|手机版|圣龙扬特-AVR电子 ( 鲁ICP备05022832号 )

GMT+8, 2024-5-4 08:25 , Processed in 0.191794 second(s), 19 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部