[ATtiny10] ADC, PWM 테스트
ATtiny 시리즈는 대부분의 코드가 호환된다.
ATtiny10 ADC 소스코드
//Read ADC Value
unsigned char AdcRead(unsigned char Channel)
{
unsigned int value = 0;
ADMUX = Channel&7;
ADCSRA = ADCSRA|ADC_START_CONVERSION;
while(!(ADCSRA & ADC_COMPLETE));
value = ADCL;
return value;
}
ATtiny10 PWM 소스코드
void InitPWM0_A(void)
{
Sbi(PWM0A_DDR, PWM0A_BIT); //Output for PWM
//TCCR0A |= (PWM0B_CLEAR|PWM_MODEA_FAST);
TCCR0A |= (PWM0A_SET|PWM_MODEA_PHASE);
TCCR0B |= (PWM0_PRESCALE_DIV8);
//TCCR0A |= (PWM0_PRESCALE_DIV256);
TCNT0 = 200;
SetPwm0A(0);
}
ATtiny10 ADC, PWM 테스트 동영상
ATtiny10 ADC, PWM 테스트 소스코드
#include "system.h"
#include "pwm.h"
#include "adc.h"
//-----------------------------------------------------------------------------
int main(void)
{
unsigned char pwm = 0;
unsigned char flag = 0;
//시스템 초기화
SystemInit();
//PWM 초기화
InitPWM0_A();
AdcInit();
while(1)
{
SetPwm0A(~(AdcRead(2)));
Delay(10);
}
}
//-----------------------------------------------------------------------------
반응형