单片机SPWM
- 格式:pdf
- 大小:177.56 KB
- 文档页数:3
SPWM
avr16SPWM
SPWM
avr168m
1050HZ
SPWMhex
/******************************************************************************
****************
spwm10
spwm
*******************************************************************************
****************/ SPWM
#include
#include
//--------------------------------------------------------------------------------------------
volatile const unsigned int Z[21]={3377,1246,5568,3617,3375,
5634,1634,7099,516 ,7869,
131 ,7869,516 ,7099,1634,
5634,3374,3617,5568,1246, 3377 };//
void time1()
{
TCCR1A=0x00; // (COMA1,0 COMB1,0 FOC1A,FOC1B WGM1,0 )
TCCR1B=0x09; // (ICNC,ICES,-- WGM3,2 CS2,CS1,CS0 )
OCR1A=0; //
TIMSK|=(1<<4); // (OCIE2 TOIE2 TIC1E1 OCIE1A OCIE1B TOIE1
OCIE0 TOIE0 )
SREG|=0x80; //
}
//t1
#pragma interrupt_handler t1zd:7
void t1zd()
{
static unsigned int n=0;
n=n+1;
if(n>=43) n=1;
if(n==1) OCR1A=Z[0],PORTD&=~(1<<5),PORTD&=~(1<<4);
if((n<=21) && (n>1) ) OCR1A=Z[n-1],PORTD^=(1<<4);
if(n==22) OCR1A=Z[n-22],PORTD&=~(1<<5),PORTD&=~(1<<4);
if(n>22) OCR1A=Z[n-22],PORTD^=(1<<5);
}
void main()
{
DDRD|=(1<<4)|(1<<5);
time1();
OCR1A=100;
while(1);
}