⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 ATmaga128单片机PWM程序 通过设计寄存器的值可以实现准确的PWM信号输出
💻 C
字号:
#include <avr/io.h>
#include "type.h"
#include <avr/signal.h>
#include <avr/interrupt.h>

const uchar SEGMENT[16]={0x3f,0x30,0x5b,0x79,0x74,0x6d,0x6f, 0x38,
		            0x7f,0x7d,0x7e,0x67,0x0f,0x73,0x4f,0x4e};
					//将BCD码转换成共阴极数码管扫描码的数组
					

/*
函数名称: display_one_smg()
功    能: 指定的数码管显示指定的内容
参    数: number--显示的内容(0-15)
	  	  position--指定的数码管(1-6)
返回值  : 无
*/
void display_one_smg(uchar num,uchar pos)
{
	//SMG_INIT();
	PORTD &= 0x0F;
	PORTC = ~SEGMENT[num];
	PORTD = (PORTD|(1<<(pos+4)));
}



int main(void)
{
    uint i,rt;
	SMG_INIT();
	i=39;
    DDRB|=0X60;
	TCCR1A=0Xab;
	TCCR1B=0X1B;
	OCR1A=432;
	OCR1B=i;
	while(1)
	{
			rt = i;
			display_one_smg(rt/10,1);
			display_one_smg(rt%10,0);	
	}

	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -