1.Đèn LED nhấp nháy 1s.
- Chương trình mẫu:
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include "delay.h" //khai bao thu vien ham tao tre
#define LED PORTC.0 //dinh nghi LED la PORTC.0
void main(void)
{
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=1
PORTC=0x01; //LED duoc noi vao PORTC.0 vi vay chon trang thai led sau khi mach duoc cap nguon la LED tat
DDRC=0x01; //chon trang thai cho phep xuat ra dieu khien led
{
LED = ~LED;//dao trang thai led ( 1-> 0 va 0-> 1)
delay_ms(500); //tre 500ms
};
}
2.LED sáng 4 LED tắt luân phiên.
- Chương trình mẫu:
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include "mega16.h"
#include "delay.h" //khai bao thu vien ham tao tre
#define LED PORTC //dinh nghia LED la PORTC
#include "delay.h" //khai bao thu vien ham tao tre
#define LED PORTC //dinh nghia LED la PORTC
void main(void)
{
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=1
PORTC=0xFF; //LED duoc noi vao PORTC vi vay chon trang thai led sau khi mach duoc cap nguon la LED tat
DDRC=0xFF; //chon trang thai cho phep xuat ra dieu khien led
{
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=1
PORTC=0xFF; //LED duoc noi vao PORTC vi vay chon trang thai led sau khi mach duoc cap nguon la LED tat
DDRC=0xFF; //chon trang thai cho phep xuat ra dieu khien led
while (1)
{
LED = 0x0F;//dao trang thai led ( 1-> 0 va 0-> 1)
delay_ms(500); //tre 500ms
LED = 0xF0;
delay_ms(500);
};
}
{
LED = 0x0F;//dao trang thai led ( 1-> 0 va 0-> 1)
delay_ms(500); //tre 500ms
LED = 0xF0;
delay_ms(500);
};
}
3.LED sáng từ trái sang phải.
- Chương trình mẫu:
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include "mega16.h"
#include "delay.h" //khai bao thu vien ham tao tre
#define LED PORTC //dinh nghia LED la PORTC
#include "delay.h" //khai bao thu vien ham tao tre
#define LED PORTC //dinh nghia LED la PORTC
void main(void)
{
char i; //khai bao mot bien su dung de dem so lan dich bit
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=1
PORTC=0xFF; //LED duoc noi vao PORTC vi vay chon trang thai led sau khi mach duoc cap nguon la LED tat
DDRC=0xFF; //chon trang thai cho phep xuat ra dieu khien led
{
char i; //khai bao mot bien su dung de dem so lan dich bit
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=1
PORTC=0xFF; //LED duoc noi vao PORTC vi vay chon trang thai led sau khi mach duoc cap nguon la LED tat
DDRC=0xFF; //chon trang thai cho phep xuat ra dieu khien led
while (1)
{
for(i=0;i
{
for(i=0;i
{
LED = ~(1 << i);
LED = ~(1 << i);
delay_ms(500); //tre 500ms
}
};
}
}
};
}
4.LED sáng từ phải sang trái.
- Chương trình mẫu:
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include "mega16.h"
#include "delay.h" //khai bao thu vien ham tao tre
#define LED PORTC //dinh nghia LED la PORTC
#include "delay.h" //khai bao thu vien ham tao tre
#define LED PORTC //dinh nghia LED la PORTC
void main(void)
{
char i; //khai bao mot bien su dung de dem so lan dich bit
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=1
PORTC=0xFF; //LED duoc noi vao PORTC vi vay chon trang thai led sau khi mach duoc cap nguon la LED tat
DDRC=0xFF; //chon trang thai cho phep xuat ra dieu khien led
{
char i; //khai bao mot bien su dung de dem so lan dich bit
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=1
PORTC=0xFF; //LED duoc noi vao PORTC vi vay chon trang thai led sau khi mach duoc cap nguon la LED tat
DDRC=0xFF; //chon trang thai cho phep xuat ra dieu khien led
while (1)
{
for(i=0;i {
LED = ~(0x80>>i); //dich so 128 di i don vi ( bit cao nhat la 1)sau do dao trang thai bit
delay_ms(500); //tre 500ms
}
};
}
{
for(i=0;i {
LED = ~(0x80>>i); //dich so 128 di i don vi ( bit cao nhat la 1)sau do dao trang thai bit
delay_ms(500); //tre 500ms
}
};
}