오늘 질문만 많이 올려서 죄송해요..
구동하는데 2가지가 안되므로 메인문을 2개를 사용하고싶은데... 하나의 프로젝트에 2개지 c파일을 사용하여 동작하는 형태입니다...
어떤 방식으로 하는건지 알려주세요 ㅜㅜ
- 처음 메인분 -
#include <avr/io.h> //16MHz
#define F_CPU 16000000UL // 16 MHz
#include <util/delay.h>
#include"ATmega128_v20m.h"
#define DEBOUNCING_DELAY 20
void RC_Motor(int angle){ // angle : -90도 ~ +90도
int i;
if(angle<-90)angle=-90;
if(angle> 90)angle= 90;
i=(angle)*18 + 3000;
OCR3A=i; //PB5
OCR3B=i; //PB6
}
int angle=0;
int main(void){
DDRB=0x00;
PORTB=0x00;
PORTE = 0x00;
//RC서보모터
DDRE=0x18; // PB5,6 out
TCCR3A=0xAA; // FAST PWM
TCCR3B=0x1A; // 8분주=0.5usec
OCR3A=3000; // 1500usec=0도
OCR3B=3000; // 1500usec=0도
ICR3=47999; // 0.5usec*48000=24000usec=41.67Hz
while(1){
/* RC_Motor(-90); _delay_ms(6000);
RC_Motor( 0); _delay_ms(6000);
RC_Motor( 90); _delay_ms(6000);
RC_Motor( 0); _delay_ms(6000); */
if((PINB&0x01)==0){
if(angle>-90){
angle--;
RC_Motor(angle); ;
}
}
if((PINB&0x02)==0){
if(angle< 0){
angle ++;
RC_Motor(angle); ;
}
}
if((PINB&0x04)==0){
if(angle > 0){
angle --;
RC_Motor(angle); ;
}
}
if((PINB&0x08)==0){
if(angle<90){
angle++;
RC_Motor(angle); ;
}
}
_delay_ms(10);
}
}
-- 2번째 메인문 --
#include<avr/io.h>
#include<util/delay.h>
#include"ATmega128_v20m.h"
#define DEBOUNCING_DELAY 20
#define F_CPU 16000000UL // 16 MHz
void RC_Motor(int angle){ // angle : -90도 ~ +90도
int i;
if(angle<-90)angle=-90;
if(angle> 90)angle= 90;
i=(angle)*18 + 3000;
OCR3A=i; //PB5
OCR3B=i; //PB6
}
int angle=0;
void msec_delay(int n);
char pattern1[3] = {1,2,3};
char pattern2[2] = {2,1};
char pattern3[3] = {3,2,1};
char pattern4[2] = {1,2};
char pattern5[2] = {3,2};
char pattern6[3] = {1,2,3};
char pattern7[2] = {2,3};
char pattern8[2] = {0x11, 0x10};
int x,z;
int floor =1;
int y=8;
int main()
{
PORTB = 0x00;
DDRB=0xf0;
PORTE = 0x00;
//RC서보모터
DDRE=0x18; // PE 3,4 out 서보모터 연결 핀
TCCR3A=0xAA; // FAST PWM
TCCR3B=0x1A; // 8분주=0.5usec
OCR3A=3000; // 1500usec=0도
OCR3B=3000; // 1500usec=0도
ICR3=47999; // 0.5usec*48000=24000usec=41.67Hz
PORTD = 0xff;
DDRD = 0xf0;
MCU_initialize();
Delay_ms(50);
LCD_initialize();
LCD_command(0x83);
LCD_2d(floor);
LCD_string(0x85, "Floor");
while(1)
{
if((PINB&0x01)==0){
if(angle>-90){
angle--;
RC_Motor(angle); ;
}
}
if((PINB&0x02)==0){
if(angle< 0){
angle ++;
RC_Motor(angle); ;
}
}
if((PINB&0x04)==0){
if(angle > 0){
angle --;
RC_Motor(angle); ;
}
}
if((PINB&0x08)==0){
if(angle<80){
angle++;
RC_Motor(angle); ;
}
}
_delay_ms(10);
if((PIND&0x01)==0)
{
if(floor==1)
{
PORTB=0x10;
}
else if(floor==2) //2층에서 1층으로 갈 때
{
x=0;
LCD_string(0xc3, "1");
while(PIND&0x08);
LCD_string(0xc3, "CLOSE DOOR");
Delay_ms(1000);
LCD_initialize();
while(1)
{
LCD_string(0x88, "<");
LCD_command(0xc7);
LCD_2d(pattern2[x]);
Delay_ms(1000);
x=x+1;
LCD_string(0x85, "<");
LCD_command(0xc7);
LCD_2d(pattern2[x]);
if(x==2)break;
} //
LCD_initialize();
LCD_string(0xc3, "OPEN DOOR");
Delay_ms(1000);
LCD_initialize();
floor = 1;
LCD_command(0x83);
LCD_2d(floor);
LCD_string(0x85, "Floor");
}
else if (floor==3) //3층에서 1층으로 갈 때
{
x=0;
LCD_string(0xc3, "1");
while(PIND&0x08);
LCD_string(0xc3, "CLOSE DOOR");
Delay_ms(1000);
LCD_initialize();
while(1){
Delay_ms(500);
LCD_string(0x88, "<");
LCD_command(0xc7);
LCD_2d(pattern3[x]);
Delay_ms(1000);
x=x+1;
LCD_string(0x86, "<");
LCD_command(0xc7);
LCD_2d(pattern3[x]);
Delay_ms(1000);
x=x+1;
LCD_string(0x84, "<");
LCD_command(0xc7);
LCD_2d(pattern3[x]);
Delay_ms(1000);
if(x==2)break; //
}
LCD_initialize();
LCD_string(0xc3, "OPEN DOOR");
Delay_ms(1000);
LCD_initialize();
floor = 1;
LCD_command(0x83);
LCD_2d(floor);
LCD_string(0x85, "Floor");
}
}
else if((PIND&0x02)==0)
{
if(floor==2)
{
PORTB=0x20;
}
else if(floor==1) //1층에서 2층으로 갈 때
{
x=0;
LCD_string(0xc5, "2");
while(PIND&0x08);
LCD_string(0xc3, "CLOSE DOOR");
Delay_ms(1000);
LCD_initialize();
while(1)
{
LCD_string(0x88, ">");
LCD_command(0xc7);
LCD_2d(pattern4[x]);
Delay_ms(1000);
x=x+1;
LCD_string(0x8b, ">");
LCD_command(0xc7);
LCD_2d(pattern4[x]);
if(x==2)break;
}
LCD_initialize(); //
LCD_string(0xc3, "OPEN DOOR");
Delay_ms(1000);
LCD_initialize();
floor = 2;
LCD_command(0x83);
LCD_2d(floor);
LCD_string(0x85, "Floor");
}
else if (floor==3) //3층에서 2층으로 갈 때
{
LCD_command(0x83);
LCD_2d(floor);
LCD_string(0x85, "Floor");
x=0;
LCD_string(0xc5, "2");
while(PIND&0x08);
LCD_string(0xc3, "CLOSE DOOR");
Delay_ms(1000);
LCD_initialize();
while(1)
{
LCD_string(0x88, "<");
LCD_command(0xc7);
LCD_2d(pattern5[x]);
Delay_ms(1000);
x=x+1;
LCD_string(0x85, "<");
LCD_command(0xc7);
LCD_2d(pattern5[x]);
if(x==2)break;
} //
LCD_initialize();
LCD_string(0xc3, "OPEN DOOR");
Delay_ms(1000);
LCD_initialize();
floor = 2;
LCD_command(0x83);
LCD_2d(floor);
LCD_string(0x85, "Floor");
}
}
else if((PIND&0x04)==0)
{
if(floor==3)
{
PORTB=0x40;
}
else if(floor==1) //1층에서 3층으로 갈 때
{
LCD_command(0x83);
LCD_2d(floor);
LCD_string(0x85, "Floor");
x=0;
LCD_string(0xc8, "3");
while(PIND&0x08);
LCD_string(0xc3, "CLOSE DOOR");
Delay_ms(1000);
LCD_initialize();
while(1){
Delay_ms(500);
LCD_string(0x88, ">");
LCD_command(0xc7);
LCD_2d(pattern1[x]);
Delay_ms(1000);
x=x+1;
LCD_string(0x8a, ">");
LCD_command(0xc7);
LCD_2d(pattern1[x]);
Delay_ms(1000);
x=x+1;
LCD_string(0x8c, ">");
LCD_command(0xc7);
LCD_2d(pattern1[x]);
Delay_ms(1000);
if(x==2)break; //
}
LCD_initialize();
LCD_string(0xc3, "OPEN DOOR");
Delay_ms(1000);
LCD_initialize();
floor = 3;
LCD_command(0x83);
LCD_2d(floor);
LCD_string(0x85, "Floor");
}
else if (floor==2) //2층에서 3층으로 갈 때
{
LCD_command(0x83);
LCD_2d(floor);
LCD_string(0x85, "Floor");
x=0;
LCD_string(0xc8, "3");
while(PIND&0x08);
LCD_string(0xc3, "CLOSE DOOR");
Delay_ms(1000);
LCD_initialize();
while(1)
{
LCD_string(0x88, ">");
LCD_command(0xc7);
LCD_2d(pattern7[x]);
Delay_ms(1000);
x=x+1;
LCD_string(0x8b, ">");
LCD_command(0xc7);
LCD_2d(pattern7[x]);
if(x==2)break;
} //
LCD_initialize();
LCD_string(0xc3, "OPEN DOOR");
Delay_ms(1000);
LCD_initialize();
floor = 3;
LCD_command(0x83);
LCD_2d(floor);
LCD_string(0x85, "Floor");
}
}
}
}
이렇게 2가지 동작을 하나의 프로젝트에서 구현하고 싶은데 섞어 넣으면 컴파일 오류는 없지만 동작을 하나만 해요..ㅜ.ㅠ