BASIC4MCU | 질문게시판 | 답변 : atmega128 음운데이터 lcd에 입력 받고 DC모터제어하기
페이지 정보
작성자 master 작성일2019-06-16 16:52 조회4,058회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=9445
본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2019-06-16 오후 4:47:03// by Ok-Hyun Park//#include <avr/io.h>#include "Text_LCD_lib.h"#include "COMMON_LIB.h"//#define read_XRAM (address)#define write_XRAM (address,value)//unsigned cahr flag=0,left[64],right[64];//void printf_Audio(char*buf,u16 data){lcd_puts(buf);lcd_Data_Write(data/1000+'0');lcd_Data_Write((data/100)%10+'0');lcd_Data_Write((data/10)%10+'0');lcd_Data_Write((data)%10+'0');}//int main(){u16 i,j,k=0,energy_left=0,energy_right=0;MCUCR=0x80; XMCRA=0x40; XMCRB=0x07;DDRB I=0x07; PORTB I=0X01;lcd_init();SPCR=0x5c; SPCR=0x11;AIC23B_spi_write(0x1e,0x00);AIC23B_spi_write(0x00,0x17);AIC23B_spi_write(0x02,0x17);AIC23B_spi_write(0x04,0x09);AIC23B_spi_write(0x06,0xf9);AIC23B_spi_write(0x08,0x18);AIC23B_spi_write(0x0a,0x00);AIC23B_spi_write(0x0c,0x01);AIC23B_spi_write(0x0e,0x53);AIC23B_spi_write(0x10,0x0d);AIC23B_spi_write(0x12,0xc1);ms_delay(100);while(1){j=k=0;energy_left=energy_right=0;for(i=0; i<128; i++){if((i%2)==0){ //짝수left[j]=ABS(read_XRAM(0x80+i)); energy_right+=left[j++];}else{ //홀수right[k]=ABS(read_XRAM(0x80+i)); energy_right+=tight[k++];}}lcdGotoXY(1,0); printf_Audio("Left: ",energy_left);lcdGotoXY(1,1); printf_Audio("Right: ",energy_right);//if((energy_left>75)||(energy_right>75)){if(flag==0){ flag=1;//모터 CW 90도 코드}}else{if(flag){ flag=0;//모터 CCW 90도 코드}}//ms_delay(1000);}}
댓글 0
조회수 4,058등록된 댓글이 없습니다.