BASIC4MCU | 질문게시판 | 답변 : 코드비전 소스입니다.
페이지 정보
작성자 master 작성일2019-11-06 23:21 조회3,286회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=10560
본문
#include <mega128.h>#include <stdio.h>#include <alcd.h>#include <delay.h>#define L_IN1 PORTB.0 // L_motor Dir Control#define L_IN2 PORTB.1#define R_IN1 PORTB.2 //R_Motor Dir Control#define R_IN2 PORTB.3#define L_EN PORTB.5 //L_motor control,OCR1A output pin#define R_EN PORTB.6 // R_motor Control,OCR1B output pinvolatile unsigned char mode[3][16]={ "Ready ","Memorizing"};volatile unsigned char temp_L[16];volatile unsigned char temp_R[16];volatile unsigned int L_cnt,R_cnt;volatile unsigned int L_cnt_s[100],L_Dir_s[100];volatile unsigned int R_cnt_s[100],R_Dir_s[100];volatile unsigned int L_run_cnt,R_run_cnt,L_top,R_top;volatile bit L_Run,R_Run,L_comp,R_comp,test1,tes2,test3;volatile int L_step,R_step,top,err_L,err_R;volatile bit L_D,R_D,Memo_flag,md_sel,;volatile bit L_chk_flag,R_chk_flag,L_t_chk,R_t_chk;interrupt[EXT_INT0]void Memo(void){if(L_Run!=1||R_Run!=1)md_sel=~md_sel; //Memorizing mode on/offL_chk_flag=1;R_chk_flag=1;if(L_t_chk==1){//L MotorL_Dir_s[L_step]=L_D; //방향저장L_cnt_s[L_step]=L_cnt;}//R Motorif(R_t_chk==1){R_Dir_s[R_step]=~R_D; // 방향저장R_cnt_s[R_step]=R_cnt; // 펄스 수 저장}//초기화if(L_t_chk==1||R_t_chk==1){L_t_chk=0;R_t_chk=0;md_sel=0;L_cnt=0;R_cnt=0;L_run_cnt=0;R_run_cnt=0;L_chk_flag=0;R_chk_flag=0;//저장완료Memo_flag=1;}}//interrupt[EXT_INT1]void Run_mode(void){if(Memo_flag==1){L_Run=1;R_Run=1;L_run_cnt=0;R_run_cnt=0;}}//Left Motorinterrupt[EXT_INT4]void Left_motor_capture(void){if(md_sel==1)// save mode{L_cnt++;if(L_chk_flag==1)//DIR check{L_t_chk=1;if(PINE.5==0){L_D=0; //im_Dir Reverse}else{L_D=1; // im_dir Drive}L_chk_flag=0;}if(L_D^PINE.5==1){if(L_cnt>2){L_Dir_s[L_step]=L_D;L_cnt_s[L_step]=L_cnt;L_step++;L_chk_flag=1;L_cnt=0;}}}if(Memo_flag==1){L_run_cnt++;}}// Right Motorinterrupt[EXT_INT6]void Right_Motor_capture(void){if(md_sel==1){R_cnt++; //회전 펄스 수++if(R_chk_flag==1){ // Direction checkR_t_chk=1;if(PINE.7==0){R_D=0; // Im_Dir Reverse}else{R_D=1; // Im_dir Drive}R_chk_flag=0; // chk Flag off,더이상 방향 체크 없이 카운트만 체크}if(R_D^PINE.7==1)// 방향 전화 xor 연산을 통해 감지{if(R_cnt>2)// 카운트가 2이상이어야지만 step 증가{R_Dir_s[R_step]=~R_D; //방향 저장R_cnt_s[R_step]=R_cnt; //펄스 수 저장R_step++; // Step++R_chk_flag=1; //방향 chk flag OnR_cnt=0; //R_cnt 초기화}}}if(Memo_flag==1)// 저장된값 출력시 if 문을 발생{R_run_cnt++;}}//void main(void){DDRB=0xff;EICRA=(1<<ISC31)|(0<<ISC30)|(1<<ISC21)|(0<<ISC20)|(1<<ISC11)|(0<<ISC10)|(1<<ISC01)|(0<<ISC00);EICRB=(0<<ISC71)|(0<<ISC70)|(1<<ISC61)|(0<<ISC60)|(0<<ISC51)|(0<<ISC50)|(1<<ISC41)|(0<<ISC40);EIMSK=(0<<INT7)|(1<<INT6)|(0<<INT5)|(1<<INT4)|(0<<INT3)|(0<<INT2)|(1<<INT1)|(1<<INT0);TCCR1A=(0<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)|(0<<COM1C1)|(0<<COM1C0)|(0<<WGM11)|(1<<WGM10);TCCR1B=(0<<ICNC1)|(0<<ICES1)|(0<<WGM13)|(1<<WGM12)|(0<<CS12)|(1<<CS11)|(1<<CS10);OCR1A=170;OCR1B=170;lcd_init(16);#asm("sei")while(1){/// LCD 상태 표시lcd_gotoxy(0,0);sprintf(temp_L,"mode:%s",mode[md_sel]);lcd_puts(temp_L);lcd_gotoxy(0,1);sprintf(temp_R,"L:%3d R:%3d",L_step,R_step);lcd_puts(temp_R);// 저장 정보가 있을 때if(Memo_flag==1&&(L_Run==1||R_Run==1)){// L Motorif(L_Run==1){if(L_cnt_s[L_top]!=0){if(L_Dir_s[L_top]==0){TCCR1A|=(1<<COM1A1)|(1<<COM1A0);L_IN1=1;L_IN2=0; // reverse}else{TCCR1A|=(1<<COM1A1)|(0<<COM1A0);L_IN1=0;L_IN2=1; //drive}err_L=L_cnt_s[L_top]-L_run_cnt;if(err_L==0){TCCR1A|=(0<<COM1A1)|(0<<COM1A0)|(0<<COM1C0)|(0<<WGM11)|(1<<WGM10);L_EN=0;L_IN1=1;L_IN2=1;delay_us(30);L_run_cnt=0;L_top++;}}if(L_step<L_top){TCCR1A|=(0<<COM1A1)|(0<<COM1A0)|(0<<COM1C1)|(0<<COM1C0)|(0<<WGM11)|(1<<WGM10);L_IN1=1;L_IN2=1;L_EN=0;L_run_cnt=0;L_top=0;L_Run=0;L_comp=1;}if(L_comp==1)L_EN=0;}/************************R MOTOR************************/if(R_Run==1){if(R_cnt_s[R_top]!=0){/********************R 방향 파악********************/if(R_Dir_s[R_top]==0)/*******Reverse*******/{TCCR1A|=(1<<COM1B1)|(0<<COM1B0);R_IN1=0;R_IN2=1;}else /*******Drive*******/{TCCR1A|=(1<<COM1B1)|(1<<COM1B0);R_IN1=1;R_IN2=0;}/************************************************/err_R=R_cnt_s[R_top]-R_run_cnt;if(err_R==0){TCCR1A|=(0<<COM1B1)|(0<<COM1B0)|(0<<COM1C1)|(0<<COM1C0)|(0<<WGM11)|(1<<WGM10);R_EN=0;R_IN1=1;R_IN2=1;delay_us(30);R_run_cnt=0;R_top++;test1=1;}}if(R_step<R_top){TCCR1A|=(0<<COM1B1)|(0<<COM1B0)|(0<<COM1C1)|(0<<COM1C0)|(0<<WGM11)|(1<<WGM10);test1=1;R_IN1=1;R_IN2=1;R_EN=0;R_run_cnt=0;R_step=0;err_R=0;R_Run=0;R_comp=1;}if(R_comp==1)R_EN=0;}if(L_comp==1&&R_comp==1){Memo_flag=0;OCR1A=0;OCR1B=0;TCCR1A=(0<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)|(0<<COM1C1)|(0<<COM1C0)|(0<<WGM11)|(0<<WGM10);TCCR1B=(0<<ICNC1)|(0<<ICES1)|(0<<WGM13)|(0<<WGM12)|(0<<CS12)|(0<<CS11)|(0<<CS10);L_EN=0;R_EN=0;}}}}
다시 컴파일 하면 워닝이 3개 발생합니다.
3개의 변수는 선언함 하고 사용되지 않았다는 경고인데 프로그램 동작과는 무관합니다.
댓글 0
조회수 3,286등록된 댓글이 없습니다.