±Û¾´ÀÌ : ¹®È«½Ä (moon2733@naver.com)      2008-04-21 21:10:26 | hit : 261
  Á¦¸ñ : ŸÀ̸Ó2
ÀÌ ÇÁ·Î±×·¥Àº Á¦°¡ §°Çµ¥¿©~`¿ÜºÎŬ·°ÀÌ µé¾î¿Í¼­ óÀ½¿¡ 10°³ÀÇ Ä«¿îÆ® ¸¶´Ù

sega[10]ÀÇ ÇÑ ¹ÙÀÌÆ® ¾¿ target[]ÀÇ ¹öÆÛ¿¡ À̵¿ ÈÄ 100¹ø Ä«¿îÆ® µÇ¸é Æ÷Æ®¿¡ sega[0]À» Ãâ·ÂÇÏ°í ±×´ÙÀ½ ºÎÅÍ´Â Ä«¿îÆ® 10°³¸¶´Ù sega[1]2...3...4ÀÌ·¸°Ô Ãâ·ÂÇÏ´Â ÇÁ·Î±×·¥ ÀÔ´Ï´Ù. ÀÌ·¸°Ô ÇÒ·Á°íÇϴµ¥ ÇÁ·Î±×·¥ÀÌ ³Ê¹« ±æ¾îÁ®¼­ À̺κÐÀ» ¾î¶»°Ô ÇÒÁö..±×¸®°í Æ÷Æ®ÀÇ Ãâ·Â ŸÀӽð£À» 10ms·Î À¯Áö ÈÄ offÇÏ°í ½ÍÀºµ¥ µô·¹ÀÌ ÇÔ¼ö·Î »ç¿ëÇÏ´Ù º¸´Ï±î Á¤È®È÷ ¸ÂÃ߱Ⱑ ¾î·Æ½À´Ï´Ù. À̺κÐÀ» ŸÀ̸ӷΠon½Ã°£À» ÁÖ´Â ¹æ¹ýÀº? ¸öµµ ¾ÈÁÁÀ¸½Åµ¥ ¾î·Á¿î°Ç¸¸ ¹°¾îºÁ¼­ Á˼ÛÇÕ´Ï´Ù.

±×·³ ¸ö °Ç°­ÇÏ½Ã°í ¸ÞÀÏ ÁÖ¼¼¿©^^

#include

//#include

#include

#include





#define sbit(x,y) (x |= (1<
#define cbit(x,y) (x &= ~(1<
#define tbit(x,y) (x & (1<




#define SHIFT_X16_Y10SET 1 // ½¬ÇÁÆ®¸ðµå 16°³¾¿ ½¬ÇÁÆ® À̵¿

#define SHIFT_0on_1offSET 2 // ½¬ÇÁÆ® Ȧ¦ 10ÁÙ Ãâ·Â ÆÛÁö

#define MVTECH 3 // MVTECH ·Î°í







unsigned char Recive_Data;//0~255



int M_timer=0;

int count=0;

int countt=0;

int i=0, j=0;



unsigned int cnt=0;

unsigned char temp_cnt=0;



int sega[10] = {0x00, 0x01, 0x02, 0x04,0x08,0x10,0x20,0x40,0x80,0xff};



unsigned char target[15][10];





/////////// clk===4MHZ/////////////////////////////////////////////////////////////////



void Delay_us(unsigned int time_us)                        /* time delay for us */

{ register unsigned int i;



    for(i = 0; i < time_us; i++){                         // 4 cycle +



    }

}







void Delay_ms(unsigned int time_ms) /* time delay for ms */

{ register unsigned int i;



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

        { Delay_us(250);

            Delay_us(250);

            Delay_us(250);

            Delay_us(250);

        }

}







SIGNAL (SIG_OVERFLOW0)

{     //0.065     ---> 0.01s



    //     count++;

// if(count > 0xff) count =0;

//     TCNT0 = count; //0xd9;

// M_timer++;



// if(M_timer == 100){

//

// PORTB ^= 0xff;

// M_timer = 0;

//

// }

    

    //    TCNT0=80;                

// if(M_timer >= 15){sbit(PORTA,4); TIMSK =    0;}





// TIMSK=0;// enable TCNT0 overflow

// PORTB=0;





}





SIGNAL (SIG_OVERFLOW1) //¿ÜºÎ Ŭ·°ÀÌ µé¾î¿Ã¶§..

{    





     TCNT1 = 0xffff;

count++;

LCD_goto(7,0);

temp_cnt = count / 100;

LCD_putch(temp_cnt + '0');

temp_cnt = count % 100;

temp_cnt = temp_cnt / 10;                                        

LCD_putch(temp_cnt + '0');

temp_cnt = count % 100;

temp_cnt = temp_cnt % 10;

LCD_putch(temp_cnt + '0');    







if(count == 10){



count = 0;

PORTB=target[9][0]; //0x00

Delay_ms(100);



target[0][0] = sega[0];



countt++;

//i = 0;

LCD_goto(7,1);

temp_cnt = countt / 100;

LCD_putch(temp_cnt + '0');

temp_cnt = countt % 100;

temp_cnt = temp_cnt / 10;                                        

LCD_putch(temp_cnt + '0');

temp_cnt = countt % 100;

temp_cnt = temp_cnt % 10;

LCD_putch(temp_cnt + '0');



if(countt == 2){//count20..

//



PORTB=target[8][1]; //0x01

Delay_ms(100);



target[1][0] = target[0][0];

target[0][1] = sega[1];





}

else if(countt == 3){//count30..





PORTB=target[7][2]; //0x02

Delay_ms(100);



target[2][0] = target[1][0];

target[1][1] = target[0][1];

target[0][2] = sega[2];







}



else if(countt == 4){//count40..



PORTB=target[6][3];//0x04

Delay_ms(100);



target[3][0] = target[2][0];

target[2][1] = target[1][1];

target[1][2] = target[0][2];

target[0][3] = sega[3];





}





else if(countt == 5){//count40..



PORTB=target[5][4]; //0x08

Delay_ms(100);



target[4][0] = target[3][0];

target[3][1] = target[2][1];

target[2][2] = target[1][2];

target[1][3] = target[0][3];

target[0][4] = sega[4];









}



else if(countt == 6){//count40..



PORTB=target[4][5];//0x10

Delay_ms(100);



target[5][0] = target[4][0];

target[4][1] = target[3][1];

target[3][2] = target[2][2];

target[2][3] = target[1][3];

target[1][4] = target[0][4];

target[0][5] = sega[5];







}





else if(countt == 7){//count40..



PORTB=target[3][6];//0x20

Delay_ms(100);



target[6][0] = target[5][0];

target[5][1] = target[4][1];

target[4][2] = target[3][2];

target[3][3] = target[2][3];

target[2][4] = target[1][4];

target[1][5] = target[0][5];

target[0][6] = sega[6];





}





else if(countt == 8){//count40..



PORTB=target[2][7]; //0x40

Delay_ms(100);



target[7][0] = target[6][0];

target[6][1] = target[5][1];

target[5][2] = target[4][2];

target[4][3] = target[3][3];

target[3][4] = target[2][4];

target[2][5] = target[1][5];

target[1][6] = target[0][6];

target[0][7] = sega[7];





}



else if(countt == 9){//count40..



PORTB=target[1][8]; //0x80

Delay_ms(100);



target[8][0] = target[7][0];

target[7][1] = target[6][1];

target[6][2] = target[5][2];

target[5][3] = target[4][3];

target[4][4] = target[3][4];

target[3][5] = target[2][5];

target[2][6] = target[1][6];

target[1][7] = target[0][7];

target[0][8] = sega[8];





}



else if(countt == 10){//count40..





target[9][0] = target[8][0];

target[8][1] = target[7][1];

target[7][2] = target[6][2];

target[6][3] = target[5][3];

target[5][4] = target[4][4];

target[4][5] = target[3][5];

target[3][6] = target[2][6];

target[2][7] = target[1][7];

target[1][8] = target[0][8];

target[0][9] = sega[9];



PORTB=target[9][0]; //0x00

Delay_ms(100);





}





else if(countt == 11){//count40..



// countt = 0;

target[9][1] = target[8][1];

target[8][2] = target[7][2];

target[7][3] = target[6][3];

target[6][4] = target[5][4];

target[5][5] = target[4][5];

target[4][6] = target[3][6];

target[3][7] = target[2][7];

target[2][8] = target[1][8];

target[1][9] = target[0][9];



target[0][0] = sega[0];



PORTB=target[9][1]; //0x00

Delay_ms(100);





}



else if(countt == 12){//count40..



target[8][2] = target[7][2];

target[7][3] = target[6][3];

target[6][4] = target[5][4];

target[5][5] = target[4][5];

target[4][6] = target[3][6];

target[3][7] = target[2][7];

target[2][8] = target[1][8];

target[1][9] = target[0][9];



target[1][0] = target[0][0];

target[0][1] = sega[1];



PORTB=target[8][2]; //0x01

Delay_ms(100);





}





else if(countt == 13){//count40..



target[7][3] = target[6][3];

target[6][4] = target[5][4];

target[5][5] = target[4][5];

target[4][6] = target[3][6];

target[3][7] = target[2][7];

target[2][8] = target[1][8];

target[1][9] = target[0][9];



target[2][0] = target[1][0];

target[1][1] = target[0][1];

target[0][2] = sega[2];



PORTB=target[7][3];//0x02

Delay_ms(100);





}



else if(countt == 14){//count40..



target[6][4] = target[5][4];

target[5][5] = target[4][5];

target[4][6] = target[3][6];

target[3][7] = target[2][7];

target[2][8] = target[1][8];

target[1][9] = target[0][9];



target[3][0] = target[2][0];

target[2][1] = target[1][1];

target[1][2] = target[0][2];

target[0][3] = sega[3];



PORTB=target[6][4]; //0x04

Delay_ms(100);





}



else if(countt == 15){//count40..



target[5][5] = target[4][5];

target[4][6] = target[3][6];

target[3][7] = target[2][7];

target[2][8] = target[1][8];

target[1][9] = target[0][9];



target[4][0] = target[3][0];

target[3][1] = target[2][1];

target[2][2] = target[1][2];

target[1][3] = target[0][3];

target[0][4] = sega[4];



PORTB=target[5][5];//0x08

Delay_ms(100);





}



else if(countt == 16){//count40..



target[4][6] = target[3][6];

target[3][7] = target[2][7];

target[2][8] = target[1][8];

target[1][9] = target[0][9];



target[5][0] = target[4][0];

target[4][1] = target[3][1];

target[3][2] = target[2][2];

target[2][3] = target[1][3];

target[1][4] = target[0][4];

target[0][5] = sega[5];



PORTB=target[4][6];//0x10

Delay_ms(100);





}





else if(countt == 17){//count40..



target[3][7] = target[2][7];

target[2][8] = target[1][8];

target[1][9] = target[0][9];



target[6][0] = target[5][0];

target[5][1] = target[4][1];

target[4][2] = target[3][2];

target[3][3] = target[2][3];

target[2][4] = target[1][4];

target[1][5] = target[0][5];

target[0][6] = sega[6];



PORTB=target[3][7]; //0x20

Delay_ms(100);





}



else if(countt == 18){//count40..



target[2][8] = target[1][8];

target[1][9] = target[0][9];



target[7][0] = target[6][0];

target[6][1] = target[5][1];

target[5][2] = target[4][2];

target[4][3] = target[3][3];

target[3][4] = target[2][4];

target[2][5] = target[1][5];

target[1][6] = target[0][6];

target[0][7] = sega[7];



PORTB=target[2][8]; //0x40

Delay_ms(100);





}





else if(countt == 19){//count40..



//countt = 0;



target[1][9] = target[0][9];



target[8][0] = target[7][0];

target[7][1] = target[6][1];

target[6][2] = target[5][2];

target[5][3] = target[4][3];

target[4][4] = target[3][4];

target[3][5] = target[2][5];

target[2][6] = target[1][6];

target[1][7] = target[0][7];

target[0][8] = sega[8];



PORTB=target[1][9]; //0x80

Delay_ms(100);





}





else if(countt == 20){//count40..



countt = 0;



target[9][0] = target[8][0];

target[8][1] = target[7][1];

target[7][2] = target[6][2];

target[6][3] = target[5][3];

target[5][4] = target[4][4];

target[4][5] = target[3][5];

target[3][6] = target[2][6];

target[2][7] = target[1][7];

target[1][8] = target[0][8];

target[0][9] = sega[9];



PORTB=target[0][9]; //0xFF

Delay_ms(100);





}









}





}



SIGNAL (TIMER0_COMP_vect)

{     // 0.01s



     //TCNT0 = 0x00;

    // comp_count++;

     //if(comp_count == 99){



    //                 PORTB = out_ten;

    

    

         //comp_count = 0;

}













//}

//unsigned char Recive_Data;//0~255





void LCD_ready()

{

cbit(PORTA,0);

}



void IR_read()

{

DDRA=0x00;

        PORTA=0x00;

cbit(PORTA,0);

sbit(PORTA,1);

sbit(PORTA,2);

Delay_us(1);

}









void LCD_string1(unsigned char byte, char *string) /* display a string on LCD */

{

    IR_write(byte); // start position of string

    while(*string != '\0') // display string

        { DR_write(*string);

             string++;

        }

}



void LCD_initialize1(void) /* initialize text LCD module */

{

    IR_write(0x28); // function set(8 bit, 2 line, 5x7 dot)

    IR_write(0x0C); // display control(display ON, cursor OFF)

    IR_write(0x06); // entry mode set(increment, not shift)

    IR_write(0x01); // clear display

    Delay_ms(2);

}







void IR_write(unsigned char byte)//LCD_command

{    

unsigned char temp;

Delay_us(50);



temp = (byte & 0xf0);

PORTA = (temp &= 0xfe); // rs =0

PORTA = (temp &= 0xfd);         // write (rw=0)

Delay_us(3);

PORTA = (temp |= 0x04);            // Enable    =    1

Delay_us(3);

PORTA = (temp &= 0xfb); // Enable    =    0



temp = ((byte << 4) & 0xf0);

PORTA = (temp &= 0xfe);            

PORTA = (temp &= 0xfd);

Delay_us(3);

PORTA = (temp |= 0x04);

Delay_us(3);

PORTA = (temp &= 0xfb);

Delay_us(50);

}                                    



void DR_write(unsigned char byte)

{

     unsigned char temp;

Delay_us(50);



temp = (byte & 0xf0);

PORTA = (temp |= 0x01);        // rs =1

PORTA = (temp &= 0xfd);         // write (rw=0)

Delay_us(3);

PORTA = (temp |= 0x04);         // Enable    =    1

Delay_us(3);

PORTA = (temp &= 0xfb);         // Enable    =    0



temp = ((byte << 4) & 0xf0);

PORTA = (temp |= 0x01);

PORTA = (temp &= 0xfd);

Delay_us(3);

PORTA = (temp |= 0x04);

Delay_us(3);

PORTA = (temp &= 0xfb);

Delay_us(50);

}



void LCD_goto(char x, char y)

{

if (y>=1) x+=0xc0;

else if(y==0) x+=0x80;



        Delay_ms(1);

        IR_write(x);

}

void LCD_putch(char c)

{

        DR_write(c);

        Delay_us(400);

}







void lcd_line2cl()

{



char i;

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



{

LCD_goto(i,1);

LCD_putch(' ');

}







}





void lcd_line1cl()

{



char i;

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



{

LCD_goto(i,0);

LCD_putch(' ');

}







}









void main(void)

{

        

        unsigned int ii = 0;



DDRE=0x02;

        DDRB = 0xFF;

//UCSR0C = 0x06;



DDRA = 0xff;

PORTA= 0x00;



DDRD    = 0x00;//dc ¸ðÅÍ...

PORTD = 0x00;//LCD EN Ãâ·Â..





TCCR0 =    0x04;    // CK/256 µµ¿ò¸»(¾Æ·¡) ÂüÁ¶ ÇÁ¸®½ºÄÉÀÏ·¯ 256

TCNT0 =    0;    //0xd9 ;// 256-39; //Ä«¿îÅÍ Å¬¸®¾î



// TCCR1B=0x03;        // CK/8 µµ¿ò¸»(¾Æ·¡) ÂüÁ¶ ÇÁ¸®½ºÄÉÀÏ·¯ 8

// TCNT1=0;



        TCCR1B =0x06; // 0000 0111    06

        TCNT1 = 0xfffe;





        TIMSK =    0x07; // 0000 0111

        OCR0    =    39;









        sei();





LCD_initialize1();

Delay_ms(1);

LCD_string1(0x80,"Pulse1:000    ");

     LCD_string1(0xC0,"Pulse2:000 " );



        PORTB = 0x00;





while(1){

                        







     }







}



name
password
 
  »óÈ£: (ÁÖ) ·Îº¸ºí·°IT / ÀüÈ­¹øÈ£ : (02)597-8224 , Fax : (02)2679-8557 Copyright (C) 2004, (ÁÖ) ·Îº¸ºí·° ½Ã½ºÅÛÁî All Rights Reserved / E-Mail : WebMaster