Thứ Ba, 2 tháng 10, 2012

4 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
*****************************************************/


#include "mega16.h"
#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


while (1)
{
LED = 0x0F;//dao trang thai led ( 1-> 0 va 0-> 1)
delay_ms(500); //tre 500ms
LED = 0xF0;
delay_ms(500);
};
}

Tải về:  http://www.mediafire.com/?l02t3mn6b6qxld3
Nguồn sangthai.com.vn
Quang Cao