BASIC4MCU | 질문게시판 | 답변 : 마스터님이 올려주신 코드에 LCD코드를 삽입해봤습니다.
페이지 정보
작성자 master 작성일2019-12-28 08:56 조회3,019회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=11440
본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2019-12-28 오전 8:57:15// by Ok-Hyun Park//#include <mega128.h>#include <delay.h>#include <stdio.h>//#define LINE1 0x80 //2nd?Line Move#define LINE2 0xC0 //2nd?Line Move#define HOME 0x02 //Cursor Home#define RSHIFT 0x1C //Display Right Shift#define LSHIFT 0x18 //Display Left Shift#define DISPON 0x0c //Display On#define DISPOFF 0x08 //Display Off//char str[30];int a,Volt10,rot=375;//void LCD_E(void) { PORTC|=0x04; delay_us(1); PORTC&=0xFB; delay_us(1); }void CMD(char c) { PORTC=c&0xF0; LCD_E(); PORTC=c<<0x4; LCD_E(); delay_ms(5); }void DATA(char d){ PORTC=(d&0xF0)|1; LCD_E(); PORTC=(d<<0x4)|1; LCD_E(); delay_us(50); }void LCD_CLR() { CMD(1); }void LCD_STR(char *s){ while(*s)DATA(*s++); }void LCD_STRf(char flash *s){ while(*s)DATA(*s++); }void LCD_init(void){DDRC=0xFF;delay_ms(15);CMD(0x20); CMD(0x20); CMD(0x20); // D5=1CMD(0x28); // function setCMD(0x06); // entry mode setLCD_CLR(); // all clearCMD(0x0c); // display on}//interrupt[TIM3_COMPA]void timer3_compa_isr(void){static char c=0;a=ADCW;Volt10=(int)((float)a*50.0/1023.0+0.5);sprintf(str,"Value:%d.%d[V]",Volt10/10,Volt10%10);CMD(LINE2); LCD_STR(str);CMD(LINE1);if(Volt10<=40){TCCR1A=0x00; OCR1A=2777; PORTA=0; LCD_STR(" ");}else{TCCR1A=0x40;c^=1;if(c){ PORTA=0x00; OCR1A=2082; LCD_STRf("fire!!!"); }else { PORTA=0xff; OCR1A=2777; LCD_STRf(" "); }}//if (Volt10<=15){ rot+=1; if(rot>475)rot=475; OCR1A=rot; }else if(Volt10<=30){ rot+=2; if(rot>475)rot=475; OCR1A=rot; }else if(Volt10<=40){ rot+=4; if(rot>475)rot=475; OCR1A=rot; }}//void main(void){DDRB=0xff;LCD_init();TCCR1B=0x0a; ICR1=0x09c3; OCR1A=375;TCCR3B=0x0c; OCR3AH=31249>>8; OCR3AL=31249&0xff; ETIMSK=0x10; //?500msADCSRA=0xe7;SREG=0x80;while(1);}
댓글 0
조회수 3,019등록된 댓글이 없습니다.