BASIC4MCU | 질문게시판 | 답변 : 코드비젼 소스코드 avr소스코드로 변환부탁드립니다
페이지 정보
작성자 master 작성일2018-06-01 08:05 조회7,918회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=1312
본문
//#include <avr/io.h>#include <avr/interrupt.h>#include <stdio.h>#define F_CPU 16000000UL // 16 MHz#include <util/delay.h>//#define DEBOUNCE 10 // ms//#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//volatile unsigned char FeedTime=3,AirTime=6,FeedingStart=1,FirstDutyTime=1,SecondDutyTime=1;volatile int Temperature=0;//void DisplayTemperature(void){ // temperature of waterfloat DutyCycle; int T10=0,T1=0;DutyCycle=FirstDutyTime/SecondDutyTime;Temperature=(DutyCycle*100000.0-32000.0)/470.0;T10=Temperature/10; T1=Temperature-(T10*10);lcd_gotoxy(0,1); lcd_putsf("Temperature: ");lcd_gotoxy(14,0); lcd_putchar((char)T10);lcd_gotoxy(15,0); lcd_putchar((char)T1);_delay_ms(100);}//ISR(TIMER2_OVF_vect){static char TimesOverFlow=0,FeedCnt=0,AirCnt=0;//if(++TimesOverFlow>=62){ TimesOverFlow=0;if(++FeedCnt>=FeedTime){ FeedCnt=0; FeedingStart=1; } //3sec//if(++AirCnt>=AirTime){ AirCnt=0; // 6secPORTB^=2; // 토글 Oxygen Generatorif(PORTB&2){ lcd_gotoxy(0,0); lcd_putsf("-Providing AIR-"); _delay_ms(100); }}}}//ISR(INT0_vect){ SecondDutyTime=TCNT2; TCNT0=0; } // 온도 센서 Rising edgeISR(INT1_vect){ FirstDutyTime=TCNT0; } // 온도 센서 falling edge//// '*'를 누르면 인터럽트 발생// '#'을 누르면 설정 종료//ISR(INT4_vect){int i,j,k,PlaceNum,TenTimes,TempNum,KeyInput[20];if(PINE==0x41){ // '*'_delay_ms(DEBOUNCE);if(PINE==0){k=0; TenTimes=1; TempNum=0;for(;;){if(k==1){ } /*Display Select mode on LCD*/if(PINE==Key_1){ KeyInput[k]=1; _delay_ms(DEBOUNCE); k++; }if(PINE==Key_2){ KeyInput[k]=2; _delay_ms(DEBOUNCE); k++; }if(PINE==Key_3){ KeyInput[k]=3; _delay_ms(DEBOUNCE); k++; }if(PINE==Key_4){ KeyInput[k]=4; _delay_ms(DEBOUNCE); k++; }if(PINE==Key_5){ KeyInput[k]=5; _delay_ms(DEBOUNCE); k++; }if(PINE==Key_6){ KeyInput[k]=6; _delay_ms(DEBOUNCE); k++; }if(PINE==Key_7){ KeyInput[k]=7; _delay_ms(DEBOUNCE); k++; }if(PINE==Key_8){ KeyInput[k]=8; _delay_ms(DEBOUNCE); k++; }if(PINE==Key_9){ KeyInput[k]=9; _delay_ms(DEBOUNCE); k++; }if(PINE==Key_0){ KeyInput[k]=0; _delay_ms(DEBOUNCE); k++; }if(PINE==Key_Star){ _delay_ms(DEBOUNCE); k=0; }if(PINE==Key_Sharp){KeyInput[k]=999; _delay_ms(DEBOUNCE);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)FeedTime=TempNum;if(KeyInput[0]==2)InputAirTime=TempNum;break;}else k=0; /*Add display "Input Error" message on LCD*/}}}}}//int main(void){int j,i,count;//DDRA=0xff; DDRC=0xff; // LCDDDRB=0xff; // Motor(PB0)+Oxygen generator(PB1)//TCNT0=0xfc; TCCR0=0x05;TCNT2=0xfc; TCCR2=0x05; TIMSK=0x40;//EICRA=0x07; EICRB=0x3f; EIMSK=0x13; // INT 4->Keypad,INT 1,2->Temperature sensor.// Rising edge#asm("sei")//lcd_init(16);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){DisplayTemperature();//if (Temperature<10){ PORTB|= 4; PORTB&=~8; } // 히터 ONelse if(Temperature>20){ PORTB&=~4; PORTB|= 8; } // 쿨러 ONelse { PORTB&=~4; PORTB&=~8; } // OFF//if(FeedingStart){ FeedingStart=0;lcd_gotoxy(0,0); lcd_putsf("--FEEDING--");for(j=0; j<=20; j++){ PORTB|=0x01; _delay_ms(2); PORTB&=0xfe; _delay_ms(4); } // 20 Pulse}}}
연산오류도 보이고
인터럽트 설정 오류도 보이고
코드 완성도가 떨어지는 소스군요
누가 만든 코드일까요?
LCD는 코드비젼의 라이브러리를 사용하고 있으므로
함수로 만들어야합니다.
핀이 여유가 있으면 8비트 방식으로 만들면 되고요
https://www.basic4mcu.com/bbs/board.php?bo_table=gesiyo13&wr_id=149
8비트 방식은 이 예제 참고해서 만들어보세요
https://www.basic4mcu.com/bbs/board.php?bo_table=gesiyo10&wr_id=256
4비트 방식이면 이 예제 참고하세요
댓글 0
조회수 7,918등록된 댓글이 없습니다.