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

📄 sivo.c

📁 avr常用功能程序中包含了pwm、adc、中断、定时、i2c等各程序可供开发者直接使用
💻 C
字号:
#include <avr/io.h>
#include <avr/signal.h>
#define uchar unsigned char
#define uint unsigned int
//the number of the "~" ;how_long<=1023

uint a,b;
unsigned int howlong=0;
void delay(unsigned int t)
{
    for(;t>0;t--);
}
void init()
{
    DDRB=0XFF;                //PORTB is setting on out
	DDRD=0X20;         		 //设置OC1A为输出
	PORTB=0X7F;           	 //PORTB is "1"
	TCCR1A=0x83;       		 //OC1A is "0",10 BITS PWM   C3,1;;;83,0
	TCCR1B=0X42;       		 //噪声消除,上升捕获   bu neng yong ping bi
	TCNT1=0;               	 //initial volue
    SREG=0X80;              //总中断开
	TIMSK=0X20;          	 //open the capture interrupt
	OCR1A=500;		 //zhan kong bi=x/1023
    howlong=2000;
}
SIGNAL(SIG_INPUT_CAPTURE1)
	{    
		TIMSK=00;                 //close capture interrupt
 	   	 PORTB=0X00;               //低4位亮
         delay(1);
         PORTB=0X7F;           //低4位灭
     	TIMSK=0X20;          //open capture interrupt
    	
	}
//================================================

//==============================================	
int main (void)
{
	
	init();
	b=100;
//    while(1);
	while(1)
	{ 	b+=5; 
	   	OCR1A=b;  		//定义占空比  
		if(b==1020)         //a 10 bit PMW
	   		{  
		   	 		while(b>=100)
		   				{
		         		b-=5;
		         		delay(5000);
			    		OCR1A=b;  		//定义占空比
		    			}         
   		  	}
		delay(5000);
   	
	}   
	
}
     

⌨️ 快捷键说明

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