Bác nào muốn tìm hiệu thì đọc VD nhé :
/****************
LAP TRINH LED SANG DAN ROI TAT DAN O CHAN PORTB.3
*****************/
#include <mega8.h>
#include <delay.h>
void main(void)
{
unsigned char k;
PORTB=0x00;
DDRB=0x08;
//-------------- khai bao PWM voi timer 2--
ASSR=0x00;
TCCR2=0x66;
TCNT2=0x00;
OCR2=0x00;
//-------------
while (1)
{
for (k=255;k>0;k--) // led tat dan
{
OCR2=k;
delay_ms(50);
};
delay_ms(1000);
for (k=0;k<255;k++) // led sang dan
{
OCR2=k;
lcd_putchar(y+0x30);
delay_ms(50);
};
delay_ms(1000);
};
}
// Xin các cao thủ chỉ giáo
/****************
LAP TRINH LED SANG DAN ROI TAT DAN O CHAN PORTB.3
*****************/
#include <mega8.h>
#include <delay.h>
void main(void)
{
unsigned char k;
PORTB=0x00;
DDRB=0x08;
//-------------- khai bao PWM voi timer 2--
ASSR=0x00;
TCCR2=0x66;
TCNT2=0x00;
OCR2=0x00;
//-------------
while (1)
{
for (k=255;k>0;k--) // led tat dan
{
OCR2=k;
delay_ms(50);
};
delay_ms(1000);
for (k=0;k<255;k++) // led sang dan
{
OCR2=k;
lcd_putchar(y+0x30);
delay_ms(50);
};
delay_ms(1000);
};
}
// Xin các cao thủ chỉ giáo
Comment