336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

ATmega128사용 + 16MHz

Main Routine에서는 ADC에 따른 Servo회전

Sub Routine에서는 Reset해서 0 degree로 회전

자세한 내용은 여기☜클릭 후 이메일로

//코드작성자 Ukrina의 Cvyak

//----------------------------------------------------------

연결법

ATmega128의 VCC, GND를 기본적으로 연결해준다.

FT232모듈의 VCCIO와 3V3을 Jumper로 묶은후 5V를 뽑아서 BreadBoard의 Vcc라인에 연결

GND를 뽑아서 BreadBoard의 GND라인에 연결

TX,RX를 뽑아서 각각 PD2,PD3에 연결한다. (PD2,PD3는 각가 Rx,Tx이다.)

ATmega128의 PE0,PE1은 각각 Rx,Tx이므로 HC-06 블루투스 모듈의 Tx,Rx에 교차연결하면 된다.

Aref를 BreaBoard의 Vcc라인에 연결한다. (늘솜 제품 기준)

PF3는 ADC의 3번 채널이므로 POT의 중간핀 or 센서의 Signal핀에 연결해주면 된다.

PC0는 Servo의 Signal핀에 연결해서 ATmega128의 출력펄스가 Servo에 전달되도록한다.

//-----------------------------------------------------------


// It's just two usefull macros - clear and set one bit in the byte (PORT)

#define clr(a,b) (a &=~(1<<b))

#define set(a,b) (a |= (1<<b))


#define over (val>500)

#define below (val<500)

unsigned int val;

unsigned int i;


char key = 'B';               // Default delay = 5 sec = 5000 msec


void RXUART_ISR() org IVT_ADDR_USART0__RX

{

  if (UART1_Data_Ready()){  // If data is received,

    key = UART1_Read(); // Read the received data,

  }

}


void main() {

char valor[8];


                                  // Default set port to input

  DDRA = DDRB = DDRC = DDRD = DDRE = DDRG = 0x00;

  PORTA= PORTB= PORTC= PORTD= PORTE= PORTG= 0x00;


  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<< Set your led PORT

  set(DDRB,4);                    // Set your led PORTB4 to output

  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>> Set your led PORT


  //set(DDRE,0);                  // Allow UART write




    /*

    ADCSRA |= (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); //128 prescale for 8MHz

    ADCSRA |= (1<<ADEN); //Enable the ADC

    ADCSRA |= (1<<ADSC); //Start the ADC conversion

    */

    ACO_bit = 0x07;      //Disable comparators

    ADC_Init();


    UART2_Init(9600);//☆For HyperTerminal( =Checking AnalogValue)

    //----------------------------

    DDRB = 0x01;   //Set RB0 to Input pin

    //----------------------------

    DDRC = 0x01;  //Makes RC0 output pin

                  //0000 0001

    PORTC = 0x00; //default value



    UART1_Init(9600);// ☆For Bluetooth communication

    SREG_I_bit = 1;                 // Interrupt enable

    RXCIE0_bit = 1;              // Enable RX interrupt



 while(1){          // Endless loop

    if(key=='A')

      {   /*rotate to zero*/

          //Rotate Motor to 0 degree

          PORTC = 0x01;        //PC0 pin is used. (1:output, 0:input)

          Delay_us(500);   //pulse ......???????? Delay_us(1000)

          PORTC = 0x00;

          Delay_ms(100);//------

      }

    else if(key=='B')

      { /*your main loop*/

         ////코드 :::: https://raw.githubusercontent.com/sisalina/AVR-programming/master/analog_read.c

         val=ADC_Read(3);     //obtain value Analog of channel 3

         IntToStr(val, valor);   //IntToStr(int input, char *output);

         for(i=0; i<7; i++)

         UART2_Write(valor[i]);

         UART2_Write_Text(" ");

         UART2_Write(key);

         UART2_Write_Text(" ");

         Delay_ms(100);



          if(below)  //Sensing Analog Value

          {

          //Rotate Motor to 0 degree

          PORTC = 0x01;        //PC0???? ???????. (1:output, 0:input)

          Delay_us(500);   //pulse ......???????? Delay_us(1000)

          PORTC = 0x00;

          //Delay_ms(2000);       //??????? ????? U?? ???????? ????????? ???.

          }

      /*

          //Rotate Motor to 90 degree

          PORTC = 0x01;

          Delay_us(1500);   //pulse

          PORTC = 0x00;

          Delay_ms(2000);

      */

          if(over)

          {

          //Rotate Motor to 180 degree

          PORTC = 0x01;     //PC0???? ???????. (1:output, 0:input)

          Delay_us(2200);   //pulse ......???????? Delay_us(2000)

          PORTC = 0x00;

          //delay_ms(2000);        //??????? ????? U?? ???????? ????????? ???.

          }

      }

    }

}

Posted by ElectricShock
:
BLOG main image
잡동사니들(지극히 개인취향인...) (다른글에도 댓글 부탁해요♥) You May Leave English Messages on GuestBook. by ElectricShock

공지사항

카테고리

분류 전체보기 (782)
Programming(=프로그래밍) (3)
MiDi (2)
Animation (4)
Blender (3D Graphic Program.. (10)
Blendtuts.com (Series) (1)
Blender 기초 팁들 (2)
Processing (디지털미디어과) (2)
Music (1)
Books in the world (0)
Communication(CAN, UART, et.. (12)
MCU Examples (PIC 기반) (7)
Transistor (1)
Mikro C Pro (11)
Mikro Pascal (1)
Proton IDE (0)
Robot (0)
Swift 3D (1)
Dummies Series (1)
All about Hacking (0)
제2 외국어 (1)
PIC 해외서적들 (3)
AVR (25)
PIC (MikroC) (MPLAB) (4)
Assembly (2)
ARM (3)
Arduino (26)
PSpice (1)
Proteus ISIS (14)
CodeVision (2)
FPGA (15)
MPLAB (24)
PCB (the Procedure) (15)
3D Printer (5)
PICKIT3 (6)
Matlab (11)
RaspBerry PI (15)
BeagleBone (1)
Android Studio (17)
졸업작품 (172)
Korea History (0)
Issue(사회) (73)
Multimeter 리뷰 (1)
Oscilloscope (1)
A (34)
B (19)
J (6)
C (32)
P (12)
T (37)
H (12)
I (12)
M (44)
R (5)
E (5)
F (2)
D (9)
O (2)
L (7)
S (9)
W (2)
V (6)
G (14)
Visual C++ or Visual Studio (2)
Android App Development (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백