You are on page 1of 14

/*****************************************************

This program was produced by the

CodeWizardAVR V2.05.0 Evaluation

Automatic Program Generator

© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.

http://www.hpinfotech.com

Project :

Version :

Date : 15/04/2011

Author : Freeware, for evaluation and non-commercial use only

Company :

Comments:

Chip type : ATmega8

Program type : Application

AVR Core Clock frequency: 4,000000 MHz

Memory model : Small

External RAM size :0

Data Stack size : 256

*****************************************************/

#include <mega8.h>

#include <delay.h>

// Declare your global variables here


int dienday1,i;

void chuongtrinh1(void) // Dien day thanh led-bar tu duoi len

dienday1=0x80;

for (i=0;i<8;i++)

{ PORTB=dienday1;

dienday1=dienday1|dienday1>>1;

delay_ms(500);

};

i=0;

int dienday,k;

void chuongtrinh2() // Dien day thanh led-bar tu tren xuong

dienday=0x01;

for (k=0;k<8;k++)

{ PORTB=dienday;

dienday=dienday|dienday<<1;

delay_ms(500);

};

k=0;

}
int j;

void chuongtrinh3() //Nhay led-bar kieu dao

{ for (j=0;j<5;j++)

{ PORTB=0xAA;

delay_ms(100);

PORTB=~PORTB;

delay_ms(100);

};

j=0;

int sosanh,bienxoay,nho,lap,dich;

void chuongtrinh4() // Chay don tu tren xuong

sosanh=8; dich=0x80;

nho=0x00;

bienxoay=0x01;

lap=0;

do

do

PORTB = nho | bienxoay;


bienxoay=bienxoay<<1;

delay_ms(200);

lap++;

while (lap<sosanh);

sosanh--;

nho=nho | dich;

dich=dich>>1;

bienxoay=0x01;

lap=0;

while (nho<0xFF);

int sosanh1,bienxoay1,nho1,lap1,dich1;

void chuongtrinh5() // Chay don tu duoi len

sosanh1=8; dich1=0x01;

nho1=0x00;

bienxoay1=0x80;

lap1=0;

do
{

do

PORTB = nho1 | bienxoay1;

bienxoay1=bienxoay1>>1;

delay_ms(200);

lap1++;

while (lap1<sosanh1);

sosanh1--;

nho1=nho1 | dich1;

dich1=dich1<<1;

bienxoay1=0x80;

lap1=0;

while (nho1<0xFF);

int biendich1,biendich2;

void chuongtrinh6() \\ Chay tu giua ra 2 ben ko don

biendich1=0x10;
biendich2=0x08;

do

PORTB=biendich1|biendich2;

delay_ms(500);

biendich1=biendich1<<1;

biendich2=biendich2>>1;

while (PORTB!=0x81);

int bien1,bien2,biendon,f,sosanh2,chay1,chay2;

void chuongtrinh7() \\Chay tu giua ra 2 ben co don

bien1=0x10; f=0 ; sosanh2=4; chay1=0x80; chay2=0x01;

bien2=0x08; biendon=0x00;

do

do

PORTB=bien1|bien2|biendon;
delay_ms(800);

bien1=bien1<<1;

bien2=bien2>>1;

f++;

while (f<sosanh2);

biendon=biendon|chay1|chay2;

bien1=0x10; bien2=0x08; f=0;

sosanh2--;

chay1=chay1>>1; chay2=chay2<<1;

while (PORTB!=0xFF);

int g;

void chuongtrinh8() // led-bar nhap nhay

{ g=0;

do

{ PORTB=0xFF;

delay_ms(1000);

PORTB=~PORTB;

delay_ms(1000);

g++;

while (g<5);

g=0;
}

void chuongtrinh9()

{ delay_ms(2000);

PORTB=0x00;

void chuongtrinh10()

delay_ms(2000);

PORTB=0xFF;

void ctngat(int x)

switch(x) // Dua ra chuong trinh theo so lan ngat

case 0: { chuongtrinh1(); break; } // Chuong trinh ngat lan 1

case 1: { chuongtrinh2(); break; } // Chuong trinh ngat lan 2

case 2: { chuongtrinh3(); break; } // Chuong trinh ngat lan 3

case 3: { chuongtrinh4(); break; } // Chuong trinh ngat lan 4

case 4: { chuongtrinh5(); break; } // Chuong trinh ngat lan 5

case 5: { chuongtrinh6(); break; } // Chuong trinh ngat lan 6

case 6: { chuongtrinh7(); break; } // Chuong trinh ngat lan 7


case 7: { chuongtrinh8(); break; } // Chuong trinh ngat lan 8

case 8: { chuongtrinh9(); break; } // Chuong trinh ngat lan 9

case 9: { chuongtrinh10(); break;} // Chuong trinh ngat lan 10

int x=0;

// External Interrupt 0 service routine

interrupt [EXT_INT0] void ext_int0_isr(void)

ctngat(x);

x++;

// External Interrupt 1 service routine

interrupt [EXT_INT1] void ext_int1_isr(void)

PORTB=0x11;

}
void main(void)

// Declare your local variables here

// Input/Output Ports initialization

// Port B initialization

// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out

// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0

PORTB=0x00;

DDRB=0xFF;

// Port C initialization

// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTC=0x00;

DDRC=0x00;

// Port D initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTD=0xFF;

DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock

// Clock value: Timer 0 Stopped

TCCR0=0x00;

TCNT0=0x00;

// Timer/Counter 1 initialization

// Clock source: System Clock

// Clock value: Timer1 Stopped

// Mode: Normal top=0xFFFF

// OC1A output: Discon.

// OC1B output: Discon.

// Noise Canceler: Off

// Input Capture on Falling Edge

// Timer1 Overflow Interrupt: Off

// Input Capture Interrupt: Off

// Compare A Match Interrupt: Off

// Compare B Match Interrupt: Off

TCCR1A=0x00;

TCCR1B=0x00;

TCNT1H=0x00;

TCNT1L=0x00;

ICR1H=0x00;

ICR1L=0x00;

OCR1AH=0x00;

OCR1AL=0x00;

OCR1BH=0x00;

OCR1BL=0x00;
// Timer/Counter 2 initialization

// Clock source: System Clock

// Clock value: Timer2 Stopped

// Mode: Normal top=0xFF

// OC2 output: Disconnected

ASSR=0x00;

TCCR2=0x00;

TCNT2=0x00;

OCR2=0x00;

// External Interrupt(s) initialization

// INT0: falling

// INT1: rising

GICR|=0xC0;

MCUCR=0x0E;

GIFR=0xC0;

// Timer(s)/Counter(s) Interrupt(s) initialization

TIMSK=0x00;

// USART initialization

// USART disabled

UCSRB=0x00;

// Analog Comparator initialization

// Analog Comparator: Off


// Analog Comparator Input Capture by Timer/Counter 1: Off

ACSR=0x80;

SFIOR=0x00;

// ADC initialization

// ADC disabled

ADCSRA=0x00;

// SPI initialization

// SPI disabled

SPCR=0x00;

// TWI initialization

// TWI disabled

TWCR=0x00;

#asm("sei") // Set bit I len 1

while (1)

chuongtrinh3();

chuongtrinh8();

chuongtrinh4();

chuongtrinh5();

}
}

You might also like