ví dụ 1 đoạn mã có pwm.các anh em thao khao ...(^+^)
Trích:
#include "C:\Documents and Settings\anh gioi\Desktop\dieu xung\12f683\ex06.h"
void main()
{
int8 i;
setup_timer_2 ( T2_DIV_BY_4, 0xc0, 2);
setup_ccp1(ccp_pwm);
while(true){
if ( (input(PIN_A0) == 0) & (input(PIN_A1) == 0) )
{
setup_ccp1(CCP_OFF);
}
if ( (input(PIN_A0) == 0) & (input(PIN_A1) == 1) )
{
setup_ccp1(CCP_PWM);
set_pwm1_duty(500);
}
if ( (input(PIN_A0) == 1) & (input(PIN_A1) == 0) ){
setup_ccp1(CCP_PWM);
set_pwm1_duty(1020);
}
}
}
|
đây là dùng pic 12F683.rất đơn giản