BASIC4MCU | 질문게시판 | 아래 ATMEGA LCD 출력 코드 및 에러 확인 질문 이미지 첨부합니다.
페이지 정보
작성자 chelsea 작성일2022-06-03 14:34 조회1,315회 댓글1건첨부파일
본문
Atmega8 센서값 LCD 출력 code 입니다.
microchip studio에서 아래 코드로 빌드업을 진행하면 맨 아래 ERROR IMAGE와 같이
경고메세지가 발생하는데요..검색해도 이해되지 않는 부분이 많아서 글을 올립니다.
에러가 발생하는 원인 및 코드 확인 부탁드립니다.
#include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define F_CPU 16000000UL #define LCD_RS PORTC4 #define LCD_EN PORTC5 #define LCD_PORT PORTC #define LCD_Clear 0x01 #define LCD_Cursor 0x03 #define LCD_Function_Set 0x28 #define LCD_On 0x0E #define LCD_Entry 0x06 volatile float calibrationfactor = 4.5; volatile float flowrate=0; volatile float cal=0; volatile int pulsecount=0; volatile int millisec=0; volatile char sec=0; void init_port() { DDRD = 0xFC; PORTD = 0x44; } void init_timer1() { TCCR1A = (0<<WGM10)|(0<<COM1A0); TCCR1B = (1<<WGM12)|(0<<CS12)|(1<<CS11)|(1<<CS10); OCR1A = 249;; TIMSK = (1<<OCIE1A); /*TCCR0A = (1 << WGM01); TIMSK0 |= (1 << OCIE0A); TCCR0B |= (1 << CS02) | (1 << CS00); OCR0A = 0x07;*/ } ISR (TIMER1_COMPA_vect) { if(++millisec>=1000) { millisec=0; // 1sec if(sec<6) { if(++sec>=6)PORTC=0x05; //6sec이후 // pump1(PC3) Off, pump2(PC2) on, valve(PC1) On } // flowrate=pulsecount/calibrationfactor; //L/min if(flowrate==0) { PORTD|= 2; //PD1 High Output (Water flow signal) } else PORTD&=~2; //PD1 Low Output pulsecount = 0; } } ISR (INT0_vect) { pulsecount++; } int main(void) { char water[20]={0}; init_port(); init_timer1(); MCUCR |= (0 << ISC00)|(1 << ISC01); GICR |= (1 << INT0); sei(); /* Replace with your application code */ while (1) { sprintf(water,"WATERFLOW:%3f",flowrate); Write_Command_LCD(0x08); String_LCD(water); _delay_ms(10); } } // LCD void LCD_Init(void) { _delay_ms(50); Write_Command_LCD(LCD_Function_Set); _delay_ms(2); Write_Command_LCD(LCD_On); _delay_ms(2); Write_Command_LCD(LCD_Clear); _delay_ms(2); Write_Command_LCD(LCD_Entry); _delay_ms(2); Write_Command_LCD(0x02); //Return Home _delay_ms(2); } void Write_Command_LCD(char Command) { LCD_PORT = (LCD_PORT & 0x0F) | (Command & 0xF0); //상위 4BIT 출력 //LCD_PORT=Command; <- 8bit를 사용할 경 LCD_PORT &= ~(1<<LCD_RS); // RS=0, command reg. LCD_PORT |= (1<<LCD_EN); //LCD_E=1; //하강 Edge에서 데이터를 전달하기 때문에 High 상태 유지 후 _delay_ms(1); LCD_PORT &= ~(1<<LCD_EN); //LCD_E=0; //low 상태로 전환하여 데이터를 전달. _delay_ms(1); LCD_PORT = (LCD_PORT & 0x0F) | (Command << 4); //하위 4BIT 출력 LCD_PORT |= (1<<LCD_EN); //LCD_E=1; //하강 Edge에서 데이터를 전달하기 때문에 High 상태 유지 후 _delay_ms(1); LCD_PORT &= ~(1<<LCD_EN); //LCD_E=0; //low 상태로 전환하여 데이터를 전달. _delay_ms(10); } void PutsChar_LCD(int data) { LCD_PORT = (LCD_PORT & 0x0F) | (data & 0xF0); //상위 4BIT 출력 LCD_PORT &= ~(1<<LCD_RS); // RS=0, command reg. LCD_PORT |= (1<<LCD_EN); //LCD_E=1; //하강 Edge에서 데이터를 전달하기 때문에 High 상태 유지 후 _delay_ms(1); LCD_PORT &= ~(1<<LCD_EN); //LCD_E=0; //low 상태로 전환하여 데이터를 전달. _delay_ms(1); LCD_PORT = (LCD_PORT & 0x0F) | (data << 4); //하위 4BIT 출력 LCD_PORT |= (1<<LCD_EN); //LCD_E=1; //하강 Edge에서 데이터를 전달하기 때문에 High 상태 유지 후 _delay_ms(1); LCD_PORT &= ~(1<<LCD_EN); //LCD_E=0; //low 상태로 전환하여 데이터를 전달. _delay_ms(10); } void String_LCD(char *ptr) { unsigned int i=0; for(i=0;ptr[i]!=0;i++) /* Send each char of string till the NULL */ { PutsChar_LCD (ptr[i]); } }
댓글 1
조회수 1,315master님의 댓글
master 작성일
변수든 함수든 뭐든 사용하기 전에 선언이 되어 있어야 합니다.
Write_Command_LCD(0x08);
String_LCD(water);
메인함수에서 사용하고 있는데요
함수 선언은 아래에 있는 것이 문제입니다.
//
함수 프로토 타입 선언이 뭔지를 공부하셔야 합니다.
https://www.google.com/search?q=c+%ED%95%A8%EC%88%98+%ED%94%84%EB%A1%9C%ED%86%A0%ED%83%80%EC%9E%85+%EC%84%A0%EC%96%B8&ei=ZaaZYo6lGqjw-Qaf16HICw&oq=c+%ED%95%A8%EC%88%98+%ED%94%84%EB%A1%9C%ED%86%A0%ED%83%80%EC%9E%85&gs_lcp=Cgdnd3Mtd2l6EAMYADIFCAAQgAQyBQgAEIAEOgQIABADOhEILhCABBCxAxCDARDHARDRAzoRCC4QgAQQsQMQgwEQxwEQowI6CwgAEIAEELEDEIMBOgcILhDUAhADOggIABCABBCxAzoICC4QgAQQsQM6CwguEIAEELEDEIMBOgsILhCABBCxAxDUAjoECC4QAzoFCC4QgAQ6BggAEB4QCjoECAAQDToICAAQHhAIEA06BQgAEKIEOgUIIRCgAUoECEEYAEoECEYYAFAAWPtoYMp1aAdwAHgAgAF0iAH1EJIBBDE4LjWYAQCgAQHAAQE&sclient=gws-wiz