본문 바로가기

임베디드/Atmega12836

atmega128 dht11 + usart 시리얼통신 아래에 첨부파일 있음. 폴더 안에 다 들어가 있다 main.c /* * dht11_0205_final.c * * Created: 2021-02-05 오후 2:37:53 * Author : User */ #define F_CPU 16000000UL #include #include #include #include #include "dht11.h" #include "uart.h" int main(){ uint8_t data = 0; char buf[40] = {0,}; USART_Init(); while (1){ dht11_getdata(0, &data); sprintf(buf, "Temp:%d", data); strTransmit(buf); memset(buf, 0x00, 40); _delay_ms(1000.. 2021. 2. 5.
millis() 와 micros() atmega128 에서 사용하기 https://www.avrfreaks.net/forum/millis-and-micros-8bits Millis() and Micros() for 8Bits Hey Guys I would like to know if there's already an existing library for Atmel C Millis() and Micros() like the Arduino has? www.avrfreaks.net https://arduino.stackexchange.com/questions/58757/equivalent-of-millis-in-atmel-studio Equivalent of millis() in Atmel studio This code It works in atmel studio.But th.. 2021. 2. 5.
(안됨)atmega128 dht11 + usart 시리얼통신 합치기 데이터시트 타이밍 차트 대로 동작하지 않아서 동작하지 않는듯 함 usart 저장된 곳에 dht11.c 와 h를 복사해 준다 add > existing item 해서 복사한 파일들을 불러와 준다 추가 된 것을 확인 atmega128 library 많은 사이트 아트메가128 라이브러리 https://git.ondrovo.com/ MightyPork's Gitea Gitea (Git with a cup of tea) is a painless self-hosted Git service written in Go git.ondrovo.com 2021. 2. 5.
atmega128 시리얼통신 아래 코드 main.c / uart.c / uart.h 로 분리 main.c /* * USART.c * * Created: 2018-11-09 오전 12:50:55 * Author : RRL */ #define F_CPU 16000000UL #include #include #include "uart.h" int main(void) { unsigned char data; USART_Init(); while (1) { data=USART_Receive(); if(data=='1') { float temp = 30.2; float humi = 40; char buf[40] = {0,}; sprintf(buf, "Temp:%f, humi:%f", temp, humi); strTransmit(buf); } // .. 2021. 2. 4.
atmega128 dht11 코드 + 코드 작성 위한 아두이노 라이브러리 찾기 main.c /* * dht11.c * * Created: 2021-02-04 오전 10:30:42 * Author : User */ #define F_CPU 16000000UL #include #include #include "dht11.h" int main(void) { initDHT11(DDRB, PORTB, PINB, PB7); while (1) { int err; float temp, humi; if((err = read(&humi, &temp))==0) { Serial.print("temperature:"); Serial.print(temp); Serial.print(" humidity:"); Serial.print(humi); Serial.println(); } else { Serial.pr.. 2021. 2. 4.
AVR 내부 flash memory 구조, atmega128 bootsz 퓨즈상태와 부트로더 섹션 크기 조정, AVR 부트로더 동작 2021. 1. 29.
analog single wire dht 2021. 1. 29.
atmega128 (timer/counter0 normal) + (timer/counter2 fast pwm) LED깜빡이기 #define F_CPU 16000000UL #include #include #define LED1 PB6 // 타이머카운터0 #define LED2 PB7 // 타이머카운터2 volatile unsigned long timer0; //오버플로마다 1씩 증가될 변수 volatile unsigned long timer2; ISR(TIMER0_OVF_vect) { timer0++; // 오버플로마다 1씩 증가 if(timer0 % 100 == 0){ PORTB ^= 1 2021. 1. 29.
8비트 + 16비트 섞어 써보기 #define F_CPU 16000000UL #include #include #define LED1 PB7 // 8bit 타이머 카운터 사용할 led #define LED2 PB6 // 16bit 타이머 카운터 사용할 led volatile unsigned long timer0; //오버플로마다 1씩 증가될 변수 volatile unsigned long timer1; ISR(TIMER0_OVF_vect) { timer0++; // 오버플로마다 1씩 증가 if(timer0 % 100 == 0){ PORTB ^= 1 2021. 1. 29.
인터럽트(Interrupt) 개요 정의 : MCU에서 자동으로 하드웨어 상태를 확인 - >신호의 변화에 대응하는 것으로 입력을 받아들이는 방법 인터럽트가 발생하면 프로세서는 현재 수행중인 프로그램을 멈추고, 상태 레지스터와 PC(Program Counter)등을 스택에 잠시 저장한 후 인터럽트 서비스 루틴(ISR)로 점프함.. ISR 실행한 후엔 이전의 프로그램으로 복귀해 정상적인 절차를 실행 Polling방식 / Interrupt 방식 Polling : 사용자가 명령어를 사용해 입력한 값을 계속 읽어서 변화 감지. 모든 경우의 입력(신호의 변화)에 대응해 처리 가능. 주기적으로 검사 Interrupt : MCU 자체가 하드웨어적으로 변화를 확인해 변화시에만 일정한 동작 수행. 하드웨어적으로 지원되는 몇개의 입력(신호의 변화)에만 대응해.. 2021. 1. 24.
ATmega128 인터럽트방식 p247 (pdf246) 키입력 - 폴링방식 p205 (pdf203), 인터럽트방식 p247 (pdf246) sei cli : global interrupt enable volatile 쓰는 이유 : volatile 은 변수 값을 참고할 때 캐시메모리에 있는게 아닌(캐시메모리의 값을 참조하는것 =간소화) 실제 메모리주소로 바로 가서 참조한다. 그래서 다른값을 참조하는 일을 없게 한다. 온전히 변수값 그대로를 참조한다 https://ko.wikipedia.org/wiki/Volatile_%EB%B3%80%EC%88%98 volatile 변수 - 위키백과, 우리 모두의 백과사전 위키백과, 우리 모두의 백과사전. C/C++ 프로그래밍 언어에서 이 키워드는 최적화 등 컴파일러의 재량을 제한하는 역할을 한다. 개발자가 설정한 개념을 구현.. 2021. 1. 22.
ATmega128 공통음극 캐소드 MT03911AR 7세그먼트 책에있는 코드인데 안된다 . 책대로 연결했는데 왜 안되는지 모르겠음 .. /* * FNDexample.c * * Created: 2020-12-07 오전 9:31:46 * Author : User */ #include unsigned char digit[] = {0x77, 0x41, 0x3B, 0x5B, 0x4D, 0x5E, 0x7C, 0x43, 0x7F, 0x4F}; void display_7segled(unsigned char led[], unsigned int number){ PORTB = led[number]; } int main(void) { DDRB = 0xFF; display_7segled(digit, 4); return 0; } 그래서 아래처럼 한칸씩 켜보고 직접 짜보기로함 #include.. 2021. 1. 21.
PORTB = 1 << PB7; 와 PORTB |= 1 << PB7; 차이 2021. 1. 21.
JMOD-128-1 AtmelStudio 7.0 에서 연결하기 새 프로젝트 만들고 아트메가 128 선택 후 컴퓨터와 연결 tools > add target 04 tools> device programming 05 코드 작성 후 빌드에 올라가면 memories에 들어가면 flash에 elf 파일이 있다. program 클릭 /* * jmod_led0121.c * * Created: 2021-01-21 오전 10:40:52 * Author : User */ #define F_CPU 16000000UL #include #include int main(void) { DDRB = 1 2021. 1. 21.
atmega128 timer/counter0 위상정정 PWM 이용한 DC모터 속도제어 책 pdf 367 #include #include #define F_CPU 16000000UL #define PRESCALE 256L #define PULSE_PER_OVERFLOW 510L #define MS_OVERFLOW_CYCLE ((double)(PULSE_PER_OVERFLOW * PRESCALE)\ /(double)((double)F_CPU/1000.0)) #define OC0 PB4 #define UP PB7 #define DOWN PB6 #define NUM_REQ 2 #define REQ_UP 0 #define REQ_DOWN 1 #define DEBOUNCE_CYCLE 50 volatile unsigned long timer0; //오버플로마다 1씩 증가 될 변수 volatile un.. 2021. 1. 9.
착시현상 7SEGMENT /* * Ko_Timer_Counter_SL.c * * Created: 2021-01-07 오후 9:25:09 * Author : Ko */ #include #include #define F_CPU 16000000UL volatile unsigned long timer0; // 오버플로마다 1씩 증가될 변수 volatile unsigned int number; // 증가되어 7-세그먼트 LED에 디스플레이 될 숫자 unsigned char led[]={0x48, 0x7D, 0xC4, 0x64, 0x71, 0x62, 0x43, 0x7C, 0x40, 0x70}; // 타이머 / 카운터0 인터럽트 서비스 루틴 ISR(TIMER0_OVF_vect) { timer0++; // 오버플로 횟수가 4의 배수일 때 10.. 2021. 1. 7.
atmega128 timer/counter0 normal 모터 2021. 1. 7.
고속pwm으로 똑같이 동작하게 2021. 1. 6.
atmega128 timer/counter0 normal LED깜빡이기 /* * Ko_Timer_Counter.c * * Created: 2021-01-04 오후 5:29:39 * Author : User */ #define F_CPU 16000000UL #include #include #define LED PB7 volatile unsigned long timer0; //오버플로마다 1씩 증가될 변수 ISR(TIMER0_OVF_vect) { timer0++; // 오버플로마다 1씩 증가 if(timer0 % 100 == 0){ PORTB ^= 1 2021. 1. 6.
pwm duty cycle youtu.be/yo5asigXynk 2021. 1. 6.