질문게시판 > 코드비젼 소스코드 avr소스코드로 변환부탁드립니다

TODAY283 TOTAL2,691,660
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 질문게시판 | 코드비젼 소스코드 avr소스코드로 변환부탁드립니다

페이지 정보

작성자 전자초짜 작성일2018-06-01 03:01 조회8,028회 댓글0건

본문

	#include <stdio.h>   

#include <delay.h> 
#include <mega128.h>


// Alphanumeric LCD Module functions
#asm
  .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

// Declare your global variables here

#if 1 // -------------------------- KTKTKT   

#define uint8_t int // BUGS

#define FeedTime 62*InputFeedTime        // Atmega는 16Mhz이고 256클럭마다 타이머가 오버플로우하게 된다.
// 그리고 클럭 스케일을 clk/1024로 해놓았으므로 1초간 오버플로우 하는 횟수는
// 16,000,000/256/1024 = 61.03515625번 이므로 약 62번 오버 플로우하게 되면
// 1초를 맞출수 있게 된다.
#define AirTime 62*InputAirTime
#define DEBOUNCE_MAKE_DELAY        10  /* milliseconds */

/* Define Variable for Keypad */   
#define Key_1      0x09             
#define Key_2      0x0A
#define Key_3      0x0C
#define Key_4      0x11
#define Key_5      0x12
#define Key_6      0x14
#define Key_7      0x21
#define Key_8      0x22
#define Key_9      0x24
#define Key_0      0x42
#define Key_Star  0x41
#define Key_Sharp  0x44

/* Public Variable */
int Temperature=0;
unsigned int InputFeedTime = 0;
unsigned int InputAirTime = 0;
unsigned int TimesOverFlow = 0;
unsigned int FeedingStart = 0;
unsigned int FirstDutyTime = 0;
unsigned int SecondDutyTime = 0;

/* Functions */

/* 외부 인터럽트 허용 및 트리거 방식 설정 */
void InitExternalInterrupt (void)
{
  // Set the Register of Interrupt
  EICRA = 0x07;//_BV(ISC01) | _BV(ISC00) | _BV(ISC11);  // INT0 use Rising edge to make trigger.
                                      // INT1 use Falling edge to make trigger.
  EICRB = 0x3f;//_BV(ISC41) | _BV(ISC40) | _BV(ISC51) | _BV(ISC50) | _BV(ISC61) | _BV(ISC60);  // Set Logic level Signal trigger INT 7-4
  EIMSK = 0x73;    // We use five of INT Interupt, they are xooo xxoo.
                    // xooo -> INT 4,5,6 -> Keypad, xx00 -> INT 1,2 -> Temperature sensor.
}

/* LCD에 현재 온도를 표시 */
void DisplayTemperature (void)
{
  /* LCD code to display temperature of water */
  float DutyCycle;
  int T10=0;
  int T1=0;
  DutyCycle = FirstDutyTime / SecondDutyTime;
  Temperature = ( DutyCycle*100000 - 32000 ) / (470);
 
  lcd_gotoxy(0,1);
  lcd_putsf("Temperature:"); 
  delay_ms(100);
 
  T10 = Temperature/10;
  T1 = Temperature - (T10 * 10);
  lcd_gotoxy(14,0);
  lcd_putchar((char)T10);
  lcd_gotoxy(15,0);
  lcd_putchar((char)T1);
}

/* Interrupts */
#if 1
interrupt [TIM2_OVF] void ext_signaloverflow_isr(void)
#else
INTERRUPT(SIG_OVERFLOW2)
#endif
{
  uint8_t Temp_PortB;

  /* 정해진 주기가 되면 인터랍트 발생 그후에 Feeding mode를 Enable 합니다. */
  if ( 0 == (TimesOverFlow % FeedTime) )
  {
      FeedingStart = 1;
  }
 
  /* 정해진 주기가 되면 인터럽트 발생, 그후에 산소공급기를 켭니다. 다음 주기까지 지속. */
  if ( 0 == (TimesOverFlow % AirTime) )
  {
      /* Turn On the Oxygen Generator */
      Temp_PortB = PORTB && 0x02;
     
      if ( Temp_PortB )
      {
        PORTB = PORTB && 0xfd;
      }
      else
      {
                        lcd_gotoxy(0,0);
                        lcd_putsf("-Providing AIR -");     
                        delay_ms(100);

        PORTB = PORTB || 0x02;
      }
  }
 
  TimesOverFlow++;

}



/* Get the Signal from Temperature sensor ____ PORTD (input) */
#if 1
interrupt [EXT_INT0] void ext_int0_isr(void)
#else

/* 온도 센서가 DutyCycle을 만들면 두개의 포트가 Rising edge와 Falling edge를 검색후 인터럽트 발생,
    Duty Cycle를 계산합니다. */
INTERRUPT(SIG_INTERRUPT0)  // It occurs when Temperature sensor makes rising edge of pulse.
#endif
{
  unsigned int Temp_TCNT2;
 
  Temp_TCNT2 = TCNT2; // Save the count of Timer   
  SecondDutyTime = Temp_TCNT2; 
  TCNT0 = 0x0000; 
  //DisplayTemperature();
 
}

#if 1
interrupt [EXT_INT1] void ext_int1_isr(void)
#else // #if 1 BUGS
INTERRUPT(SIG_INTERRUPT1)  // It occurs when Temperature sensor makes falling edge of pulse.
#endif // #if 1
{
  unsigned int Temp_TCNT0;
 
  Temp_TCNT0 = TCNT0; // Save the count of Timer   
  FirstDutyTime = Temp_TCNT0; 
}



#if 1
interrupt [EXT_INT4] void ext_int4_isr(void)
#else // #if 1 BUGS


/* 키패드 중에 별표를 누르면, 인터럽트가 발생하여 메뉴설정 모드로 들어가게 됩니다.
  메뉴 설정중에는 모든 인터럽트가 금지되어 있으므로 안전하게 값들을 설정 가능해집니다.
  #버튼을 누르면 설정이 종료됩니다. */
SIGNAL(SIG_INTERRUPT4) // It occurs when Keys of first column of keypad are pushed.
#endif // #if 1
{
  int i,j,k;
  int KeyInput[20];
  int PlaceNum, TenTimes, TempNum;

  if ( PINE == 0x41 ) // it means that '*'key is pushed and the user want to adjust values.
  {
      for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
      {                                        // This If sentence was made to debounce.
        delay_ms(1);                              //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
      }                   
     
     
      if ( PINE == 0x00 )      // To push anther key, the user has to release first key.
      {                    // At that time, PINE would be 0x00.
        k=0;              // Initialize array number.( We have to add LCD Display fuction)
        TenTimes=1;
        TempNum = 0;
       
        for (;;)
        {
            if ( k == 1)
            {
              /* Display Select mode on LCD */
            }
            if ( PINE == Key_1 )
            {
              KeyInput[k] = 1;
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }     
              k++;
            }
            if ( PINE == Key_2 )
            {
              KeyInput[k] = 2;
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }
              k++;
            }
            if ( PINE == Key_3 )
            {
              KeyInput[k] = 3;
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }
              k++;
            }
            if ( PINE == Key_4 )
            {
              KeyInput[k] = 4;
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }
              k++;
            }
            if ( PINE == Key_5 )
            {
              KeyInput[k] = 5;
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }
              k++;
            }
            if ( PINE == Key_6 )
            {
              KeyInput[k] = 6;
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }
              k++;
            }
            if ( PINE == Key_7 )
            {
              KeyInput[k] = 7;
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }
              k++;
            }
            if ( PINE == Key_8 )
            {
              KeyInput[k] = 8;
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }
              k++;
            }
            if ( PINE == Key_9 )
            {
              KeyInput[k] = 9;
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }
              k++;
            }
            if ( PINE == Key_0 )
            {
              KeyInput[k] = 0;
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }
              k++;
            }
            if ( PINE == Key_Star )
            {
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }
              /* Add display CCC message on LCD */
              k=0;
            }
            if ( PINE == Key_Sharp )
            {
              KeyInput[k] = 999;
              for (i=0; i < DEBOUNCE_MAKE_DELAY ; i++ )
{ // This If sentence was made to debounce.
delay_ms(1); //If the switch bounce while only 10ms, It is Ok.
                                            //Because It doesn't receive any signal while 10ms
              }
              if ( (KeyInput[0] == 1) || (KeyInput[0] ==2) )
              {
                  for ( i=1 ; i<k ; i++)
                  {
                    PlaceNum = k-i-1;
                   
                    for ( j=0, TenTimes=1; j < PlaceNum ; j++)
                    {
                        TenTimes = TenTimes * 10;
                    }
                   
                    TempNum = TempNum + KeyInput[i] * TenTimes;                   
                  }
                 
                  if ( KeyInput[0] == 1 )
                  {
                    InputFeedTime = TempNum;
                  }
                 
                  if ( KeyInput[0] == 2 )
                  {
                    InputAirTime = TempNum;
                  }
                 
                  break;
              }
              else
              {
                  /* Add display "Input Error" message on LCD */
                  k=0;
              }
            }
        }
 
      }
  }
 
}



#endif // #if 1

void main(void)
{
  uint8_t input = 0x00;
  uint8_t output = 0xff;
  int j,i,count; // BUGS : MOVE MOVE
     
  /* Default Value */
  InputFeedTime = 3;
  InputAirTime = 6;
  TimesOverFlow = 0;
  FeedingStart = 1;
  FirstDutyTime = 1;
  SecondDutyTime = 1;
 
  /* Initialize Ports */
  DDRA = output;  // LCD
  PORTA = 0x00;
  DDRB = output;  // Motor (PORTB 0bit) + Oxygen generator ( PORTB 1bit )
  PORTB = 0x00;
  DDRC = output;  // LCD
  PORTC = 0x00;
  DDRD = input;  // Tempeature sensor (PORTD 0bit and 1bit) - INT0 and INT1
  DDRE = input;    // Keypad
 
  /* initialize External Signal interrupt */
  InitExternalInterrupt();

  /* Initialize Timer0, Timer2 funtions */
  TCCR0 = 0x05;  // Adjust Timer Scale -> clk/32
  TCNT0 = 0xfc;    // Timer Starts to counter from 254, it prevents making Assembly language problem.
  TCCR2 = 0x05;  // Adjust Timer Sclae -> clk/1024 
  TCNT2 = 0xfc;
  TIMSK = 0x40; // Enable Timer/Couner0 Overflow Interrupt Enable
 
  // Global enable interrupts
  #asm("sei")     

  // LCD module initialization
  lcd_init(16);
 
  // After LCD initialize, Display Some words...
  lcd_gotoxy(0,0);
  lcd_putsf("**OH DONG HOON**");     
  delay_ms(100);
  lcd_gotoxy(0,1);
  lcd_putsf("AUTO FISH BASIN*");   
  delay_ms(100);
 
  while (1)
        { 
        /* 온도를 LCD에 표시 */
        DisplayTemperature();
     

        /* 일정 온도 범위를 넘어서면 온도 제어를 합니다. */
        if(Temperature < 10)
                PORTB |= 0x04;            // 히터를 켭니다.
        else if(Temperature > 20)
                PORTB |= 0x08;            //  쿨러를 켭니다.
        else if((Temperature >= 10) && (Temperature <= 20))
              PORTB &= 0xF3;            // 히터랑 쿨러 모두다 끕니다.
                     
        /* Feeding Mode 실행 */       
        if ( FeedingStart )
        {
                        lcd_gotoxy(0,0);
                        lcd_putsf("--  FEEDING  --");     

            /* Making 20 Pulse for motor */
            for (j=0; j<=20; j++)
            {
              PORTB |= 0x01;    /* output 1 to port1.0 */
              delay_ms(2);          /* 1mSec delay*/
              PORTB &= 0xfe;    /* output 0 to port1.0*/
              delay_ms(4);      /* 4mSec delay*/
            }


            FeedingStart =0;  // ---- 0 -----

        }
      };
}

코드비젼 소스코드를 avr 소스코드로 바꾸려는데 컴파일시 오류가 너무 많네요.
어떻게 바꿔야하는지도 감이안잡히는데 도움부탁드립니다.
  • BASIC4MCU 작성글 SNS에 공유하기
  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기

댓글 0

조회수 8,028

등록된 댓글이 없습니다.

질문게시판HOME > 질문게시판 목록

MCU, AVR, 아두이노 등 전자공학에 관련된 질문을 무료회원가입 후 작성해주시면 전문가가 답변해드립니다.
ATMEGA128PWMLED초음파
아두이노AVR블루투스LCD
UART모터적외선ATMEGA
전체 스위치 센서
질문게시판 목록
제목 작성자 작성일 조회
공지 MCU, AVR, 아두이노 등 전자공학에 관련된 질문은 질문게시판에서만 작성 가능합니다. 스태프 19-01-15 19418
공지 사이트 이용 안내댓글[28] master 17-10-29 34131
질문 stm32f767을 이용해서 자이로가속도 센서의 값 받아오기 새글 rlchwjswk 23-06-03 9
질문 아두이노 모터제어 관련해서 질문드립니다!댓글[1] 이미지새글첨부파일 아두이노어렵잖아 23-06-03 21
질문 atmega128 디지털조도센서 코드오류댓글[1] 이미지새글 까미 23-06-02 25
질문 atmega128 디지털 조도 센서댓글[1] 새글 까미 23-06-02 25
질문 적외선리모콘으로 부저를제어 하는방법 질문입니다.댓글[4] 새글 Tell 23-06-02 18
질문 lora 무선 모듈에 관한 질문입니다.댓글[1] 로이스10 23-06-01 18
질문 적외선 송수신기 DC모터2개 제어 질문입니다.댓글[5] Tell 23-06-01 31
질문 스텝모터 제어 코드 질문댓글[4] pmh11 23-05-31 32
질문 초음파 센서를 이용한 인원 카운팅댓글[1] 초음파야 23-05-31 26
질문 모터 Hall 스위치 연결 문의댓글[1] 오후 23-05-31 21
질문 아두이노 lcd 문자 스크롤디스플레이 wnion 23-05-31 22
답변 답변글 답변 : 아두이노 lcd 문자 스크롤디스플레이댓글[1] master 23-05-31 28
질문 아두이노 타이머 인터럽트 미ㅏㄴㅇ 23-05-30 37
답변 답변글 답변 : 아두이노 타이머 인터럽트댓글[6] master 23-05-30 44
질문 THC-Soil Sensor with TTL 모듈 아두이노 센서값 받아오기댓글[1] ppiickle 23-05-30 30
질문 stm32 psd센서구동 질문댓글[2] 수포자 23-05-29 28
질문 앱인벤터 아두이노 보드 LCD 글씨 나타내기 질문댓글[7] 이미지 당찬병아리 23-05-29 41
질문 atmega128 led와 fan댓글[3] 이라 23-05-28 44
질문 stm32f767 스텝모터 속도 질문있습니다 123132 23-05-27 34
답변 답변글 답변 : stm32f767 스텝모터 속도 질문있습니다 master 23-05-28 30
질문 아트메가 128 코딩 오류 질문입니다.댓글[1] 태태킴 23-05-27 31
질문 스텝모터 제어하는 소스파일인데 질문있습니다. Bs드리프터 23-05-27 38
답변 답변글 답변 : 스텝모터 제어하는 소스파일인데 질문있습니다. master 23-05-27 35
질문 모터 컨트롤러와 웜기어 모터 연결 문의 드립니다댓글[1] 오후에 23-05-27 28
답변 답변글 답변 : 모터 컨트롤러와 웜기어 모터 연결 문의 드립니다댓글[1] 첨부파일 오후에 23-05-27 33
질문 아두이노 스텝모터 초음파 결합댓글[2] 결합기원 23-05-26 55
답변 답변글 답변 : 아두이노 스텝모터 초음파 결합 master 23-05-27 28
질문 piezo부저 연결 방법댓글[2] 이미지첨부파일 djwb 23-05-26 34
게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기