#include"iot13v.h"
#include"macros.h"
#define TRUE 1
#define FLASE 0
#define SET_BIT(x,y) x |=(1<<y)
#define CLR_BIT(x,y) x &= (~(1<<y))
#define GET_BIT(x,y) (x&(1<<y))
#define CPL_BIT(x,y) x^= (1<<y)
#define PWM_SET PORTB |= (1 << PB0) //位置高
#define PWM_CLR PORTB &= ~(1 << PB0)
//位置低
#define GREEN_SET PORTB |= (1 << PB3)
//位置高
#define GREEN_CLR PORTB &= ~(1 << PB3) //位置低
#define BLUE_SET PORTB |= (1 << PB5) //位置高
#define BLUE_CLR PORTB &= ~(1 << PB5) //位置低
#pragma interrupt_handler time0ovf_data:4
typedef unsigned char uchar ; //定义变量
uchar counter = 0 ;
uchar gray = 0;
oid time0ovf_data(void)
{
switch(countr)
{
case 0:
gray ++ ;
if(gray ==0xff)
{
countr = 1 ;
// gray = 0xff;
}
break;
case 1: //gray = 0;
gray -- ;
if(gray == 0x00)
{
countr = 0 ;
//gray = 0;
}
break;
case 2:
break;
}
TCCR0B = 0x04;
SEI();
}
//第一步,初始化
/*void Delay_ms(int ms)
{
unsigned int i, j;
for (i=0,i<ms,i--)
} */
void Delay_ms(unsigned int i)
{
for( ; i > 0 ; i --)
;
}
void main(void)
{
unsigned int i = 0;
CLI();
DDRB = 0x01; //设置输入输出方向,PB0为输入
PORTB = 0x00;
PINB = 0x08;
TCCR0A = 0;
TCCR0B = 0x04;
SET_BIT(TIMSK0,TOIE0);
TCNT0 = 0;
//gray = 0;
//countr = 0;
TCCR0B = 0x04;
SEI() ;
while(1)
{
++ counter ;
if( gray > counter)
{
PWM_CLR;
Delay_ms(5); //延时5MS
}
else {
PWM_SET;
Delay_ms(5); //延时5MS
}
}
}
为什么补能调光
uchar countr =0; |