BASIC4MCU | 질문게시판 | 4x4 키패드와 lcd를 이용한 계산기
페이지 정보
작성자 songbin 작성일2018-12-18 07:16 조회5,494회 댓글0건본문
안녕하세요~!
atmega 48로 간단한 계산기를 만들고 싶은데요
제가 정말 이걸 시작한지 얼마안되서, 많이 모르고있습니다
우선은 codevision 으로 코드를 이것저것 짜집기해서 짜봤습니다.
프로테우스로 시뮬을 돌릴때, 버튼을 누르면 lcd에 숫자가 출력되게 하고싶은데,
어떤 코드를 필요로 하는지 잘모르겠습니다..
아래는 코드입니다! 그리고 프로테우스도 한번 봐주시면 감사하겠습니다.
#include <mega48pa.h>
#include <delay.h>
void LCDs_COMs(unsigned char x)
{
PORTB = 0x04 ;
delay_us(50) ;
PORTD = 0x00 ;
delay_us(50) ;
PORTB = 0x00 ;
PORTC = 0xFF ;
DDRC=0x0F;
}
void LCDs_DATs(unsigned char x)
{
PORTB = 0x05 ;
delay_us(50) ;
PORTD = 0x00 ;
delay_us(50) ;
PORTB = 0x01 ;
}
void LCDs_STRs(unsigned char *str) // 문자열 출력
{
while(*str != 0)
{
LCDs_DATs(*str) ; str++ ;
}
}
void LCDs_PXYs(unsigned char y, unsigned char x)
{
LCDs_COMs(0x80 | ( x + (y*0x40) ) ) ;
}
char KeyScan(void){
char KeyBuf=0xFF;
PORTC=0xFF;
DDRC=0x0F;
PORTC.0=0; delay_us(5);
if(!PINC.4)KeyBuf='0';
if(!PINC.5)KeyBuf='1';
if(!PINC.6)KeyBuf='2';
if(!PINC.7)KeyBuf='3';
PORTC.0=1;
PORTC.1=0; delay_us(5);
if(!PINC.4)KeyBuf='4';
if(!PINC.5)KeyBuf='5';
if(!PINC.6)KeyBuf='6';
if(!PINC.7)KeyBuf='7';
PORTC.1=1;
PORTC.2=0; delay_us(5);
if(!PINC.4)KeyBuf='8';
if(!PINC.5)KeyBuf='9';
if(!PINC.6)KeyBuf='A';
if(!PINC.7)KeyBuf='B';
PORTC.2=1;
PORTC.3=0; delay_us(5);
if(!PINC.4)KeyBuf='C';
if(!PINC.5)KeyBuf='D';
if(!PINC.6)KeyBuf='E';
if(!PINC.7)KeyBuf='F';
PORTC.3=1;
return KeyBuf;
}
void main(void)
{
unsigned int no ;
DDRB = 0x07 ;
PORTB = 0x00 ;
DDRD = 0xFF ;
PORTD = 0x00 ;
delay_ms(100) ;
LCDs_COMs(0x38) ;
delay_ms(10) ;
LCDs_COMs(0x38) ;
delay_ms(10) ;
LCDs_COMs(0x38) ;
delay_ms(10) ;
LCDs_COMs(0x0C) ;
delay_ms(10) ;
LCDs_COMs(0x01) ;
delay_ms(10) ;
LCDs_COMs(0x06) ;
delay_ms(10) ;
while (1)
{
}
}
댓글 0
조회수 5,494등록된 댓글이 없습니다.