티스토리 뷰
Servo contorol
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <mega128.h> #include <delay.h> #include <stdio.h> #include "lcd.h" /* SERVO */ // TCCR3A = 10101010 // COM3A[1,0], COM3B[1,0], COM3C[1,0] // TCCR3B = 00011010 // WGM[1,1,1,0], CS[0,1,0] // WGM[1,1,1,0] : Fast PWM, TOP = ICR3 // OCR3A = 3000; // COMP = 1.5[msec] // ICR3 = 40000; // TOP = 20[msec] /* SERVO */ void Init_TImer3A(void) { TCCR3A = 0xAA; TCCR3B = 0x1A; OCR3AH = 3000>>8; OCR3AL = 3000&0xff; DDRE = 0x08; ICR3H = 39999>>8; TCR3L = 39999&0xff; } void Servo_motor(int angle) { OCR3AH = (angle*18+3000)>>8; OCR3AL = (angle*18+3000)&0xff; } void main(void) { Init_TImer3A(); while(1) { Servo_motor(45); delay_ms(2000); Servo_motor(0); delay_ms(2000); Servo_motor(-45); delay_ms(2000); Servo_motor(0); delay_ms(2000); } } | cs |
Infrared contorol
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #include <mega128.h> #include <delay.h> #include <io.h> #include "lcd.h" /* ADC */ /* ADCSRA = 0b11101111 Bit 7 : ADEN, ADC Enable Bit 6 : ADSC, ADC Start Conversion(AD 변환시작) Bit 5 : ADFR, ADC Free Running Select(ADC 프리러닝) -> 1일 때, 프리러닝 Bit 4 : ADIF, ADC Interrupt Flag Bit 3 : ADIE, ADC Interrupt Enable Bit 2~0 : ADPS, ADC Prescaler Bits // (/128) ADMUX = (1<<REFS1)|(1<<REFS0) REFS1~0 : REF 전압 선택 -> [1,1]내부전압 2.56V ADC 정렬방향 선택 -> 우측정렬 0 UX 4~0 : ADC핀 선택(이득도 선택가능) -> 가변저항은 ADC0 ADCW = ADCH + ADCL // ADC 변환 값을 저장 */ /* ADC */ interrupt [ADC_INT] void adc_isr(void) { LCD_pos(0,0); } void AD_Init(void) { ADMUX |= (1<<REFS1)|(1<<REFS0); ADCSRA |= 0xEF; } void LCD_Decimal(short AD_dat) { unsigned char Decimal[5]; Decimal[4] = '0'+ AD_dat/10000; AD_dat = AD_dat%10000; Decimal[3] = '0' + AD_dat/1000; AD_dat = AD_dat%1000; Decimal[2] = '0' + AD_dat/100; AD_dat = AD_dat%100; Decimal[1] = '0' + AD_dat/10; AD_dat = AD_dat%10; Decimal[0] = '0' + AD_dat/1; LCD_pos(0,0); LCD_STR("Result:"); LCD_pos(0,8); LCD_Data(Decimal[4]); LCD_pos(0,9); LCD_Data(Decimal[3]); LCD_pos(0,10); LCD_Data(Decimal[2]); LCD_pos(0,11); LCD_Data(Decimal[1]); LCD_pos(0,12); LCD_Data(Decimal[0]); LCD_pos(1,0); LCD_STR("Distance:"); LCD_pos(0,10); if(508<AD_dat){LCD_STR("under");} else if(460<AD_dat && AD_dat<=508){LCD_STR("20cm");} else if(390<AD_dat && AD_dat<=460){LCD_STR("25cm");} else if(352<AD_dat && AD_dat<=390){LCD_STR("30cm");} else if(294<AD_dat && AD_dat<=352){LCD_STR("35cm");} else if(266<AD_dat && AD_dat<=294){LCD_STR("40cm");} else if(237<AD_dat && AD_dat<=266){LCD_STR("45cm");} else if(215<AD_dat && AD_dat<=237){LCD_STR("50cm");} else if(198<AD_dat && AD_dat<=215){LCD_STR("55cm");} else if(180<AD_dat && AD_dat<=198){LCD_STR("60cm");} else if(174<AD_dat && AD_dat<=180){LCD_STR("65cm");} else if(158<AD_dat && AD_dat<=174){LCD_STR("70cm");} else if(151<AD_dat && AD_dat<=158){LCD_STR("75cm");} else if(137<AD_dat && AD_dat<=151){LCD_STR("80cm");} else if(124<AD_dat && AD_dat<=137){LCD_STR("90cm");} else if(112<AD_dat && AD_dat<=124){LCD_STR("100cm");} else if(105<AD_dat && AD_dat<=112){LCD_STR("105cm");} else if(102<AD_dat && AD_dat<=105){LCD_STR("110cm");} else if(96<AD_dat && AD_dat<=102){LCD_STR("120cm");} else if(89<AD_dat && AD_dat<=96){LCD_STR("130cm");} else if(83<AD_dat && AD_dat<=89){LCD_STR("140cm");} else if(78<AD_dat && AD_dat<=83){LCD_STR("150cm");} else if(AD_dat<=78){LCD_STR("over");} } void main(void) { AD_Init(); Port_Init(); LCD_Init(); SREG = 0x08; while(1) { LCD_Decimal(ADCW); } } | cs |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- alpine.js
- nosql
- gcp
- DevOps
- PostgreSQL
- Angular
- MySQL
- Remix
- oracle
- Gatsby.js
- 이진탐색 #중복
- vue.js
- Next.js
- SQLite
- REACT
- Azure
- node.js
- aws
- Quasar
- Cloud
- svelte
- RDBMS
- nuxt.js
- vue
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함