BASIC4MCU | 질문게시판 | 답변 : atmega 128 lcd와 온도센서 합친코드
페이지 정보
작성자 master 작성일2018-12-10 20:41 조회6,422회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=6693
본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2018-12-10 오후 8:47:09// by Ok-Hyun Park//#define F_CPU 16000000#include <avr/io.h>#include <util/delay.h>#include <avr/interrupt.h>#include <stdio.h>//#define FUNCSET 0x28 //Function Set#define ENTMODE 0x06 //Entry Mode Set#define ALLCLR 0x01 //Clear Display#define DISPON 0x0c //Display On#define LINE1 0x80 //Set DDRAM Address(0x00)#define LINE2 0xC0 //Set DDRAM Address(0x40)#define LINE3 0x94 //Set DDRAM Address(0x14)#define LINE4 0xD4 //Set DDRAM Address(0x54)//#define PORT_DATA PORTD#define DDR_DATA DDRD//#define Byte unsigned char//volatile Byte flag=0,sec=0,min=0,hour=0;//void LCD_CMD(unsigned char byte){PORT_DATA=(byte&0xF0)|4; _delay_us(1); PORT_DATA&=0xFB;PORT_DATA=(byte<<0x4)|4; _delay_us(1); PORT_DATA&=0xFB; _delay_ms(3);}//void LCD_CHAR(unsigned char byte){PORT_DATA=(byte&0xF0)|5; _delay_us(1); PORT_DATA&=0xFB;PORT_DATA=(byte<<0x4)|5; _delay_us(1); PORT_DATA&=0xFB; _delay_us(50);}//void LCD_STR(Byte *s){ while(*s)LCD_CHAR(*s++); }//void LCD_INIT(void){DDR_DATA=0xFF; _delay_ms(15); LCD_CMD(0x20); LCD_CMD(0x20); LCD_CMD(0x20);LCD_CMD(FUNCSET); LCD_CMD(DISPON); LCD_CMD(ALLCLR); LCD_CMD(ENTMODE);}//void TX1_char(char c){ while(!(UCSR1A&0x20)); UDR1=c; }void TX1_STR(char *s){ while(*s)TX1_char(*s++); }//ISR(TIMER1_COMPA_vect){if(++sec>59){ sec=0;if(++min>59){ min=0; if(++hour>23)hour=0; }}flag=1;}//int main(void){int i; char str[30];LCD_INIT();LCD_CMD(LINE1); LCD_STR("Current Time");LCD_CMD(LINE2); LCD_STR(str2);LCD_CMD(LINE3); LCD_STR("Temperature");LCD_CMD(LINE4); LCD_STR(str4);TCCR1B=0x0D; OCR1A=15624; TIMSK=0x10;UCSR0B=0x18; UBRR0L=103; // 9600ADMUX=0x43; ADCSRA=0xE7;SREG=0x80;while(1){if(flag){ flag=0;sprintf(str,"%02d:%02d:%02d",hour,min,sec);LCD_CMD(LINE2); LCD_STR(str);TX1_STR(str); TX1_STR("\r\n");//i=ADC;i=(int)((float)i*500.0/1023.0);sprintf(str,"%d C",i);LCD_CMD(LINE4); LCD_STR(str);TX1_STR(str); TX1_STR("\r\n");}}}
댓글 0
조회수 6,422등록된 댓글이 없습니다.