Nguyên văn bởi mrcuongcon
Xem bài viết
Dùng phần mềm CodevisionAVR để dịch.
Tôi gửi kèm theo cả file mô phỏng của Proteus để các bạn thử.
/************************************************** ***
This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project : Led
Version :
Date : 8/26/2008
Author : Nguyen Minh Hieu
Company : ANCO
Comments:
Chip type : ATmega16
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** ***/
//cac led noi vao PORTA, cuc duong cua led noi vao tro 330R va noi len VCC
//doan code nay lam led sang lan luot tu phai qua trai va tu trai qua phai
#include <mega16.h>
#include <delay.h>
void main(void)
{
unsigned char i,data;
PORTA=0xFF; //port A co tro keo ben trong
DDRA=0xFF; //Huong cua du lieu = xuat du lieu ra
while (1)
{
data = 0x01;
//delay_ms(500); //tat tat ca cac led
for(i= 0;i<=8;i++) // lap lai 9 lan cho 8 led
{
PORTA = ~data; // xuat du lieu ra dieu khien den
delay_ms(500); // led sang 500ms
data <<=1; // dich sang trai 1 bit
}
data = 0x80; // tat cac led
for(i = 0;i<=8;i++) // lap lai 9 lan cho 8 led
{
PORTA = ~data; // dao du lieu tu trang thai sang thanh tat va xuat ra dieu khien den
delay_ms(500);
data >>= 1; // dich bit sang phai 1 bit
}
};
}
Comment