#include <mega128.h>

#include "delay.h"

#include "lcd.h"


void LCD_Decimal(unsigned char num, short AD_dat){

  unsigned char Decimal[5];

  Decimal[4] = '0' + AD_dat / 10000;      //10000자리 아스키 값으로 저장

  AD_dat = AD_dat % 10000;             //나머지값

  Decimal[3] = '0' + AD_dat / 1000;      //1000자리 아스키 값으로 저장

  AD_dat = AD_dat % 1000;             //나머지값

  Decimal[2] = '0' + AD_dat / 100;      //100자리 아스키 값으로 저장

  AD_dat = AD_dat % 100;             //나머지값

  Decimal[1] = '0' + AD_dat / 10;      //10자리 아스키 값으로 저장

  AD_dat = AD_dat % 10;             //나머지값

  Decimal[0] = '0' + AD_dat / 1;      //1자리 아스키 값으로 저장

  if(num == 0){

    LCD_pos(0,10);        LCD_Data(Decimal[3]);

    //LCD 10번째 칸       0번째 열에 1000자리 표시

    LCD_pos(0,11);        LCD_Data(Decimal[2]);

    //LCD 11번째 칸                               

    LCD_pos(0,12);        LCD_Data(Decimal[1]);

    LCD_pos(0,13);        LCD_Data(Decimal[0]);

  }                                            

  else if(num == 1){                          

    LCD_pos(1,10);        LCD_Data(Decimal[4]);

    LCD_pos(1,11);        LCD_Data('.');

    LCD_pos(1,12);        LCD_Data(Decimal[3]);          

    LCD_pos(1,13);        LCD_Data(Decimal[2]);

    LCD_pos(1,14);        LCD_Data(Decimal[1]);

    LCD_pos(1,15);        LCD_Data(Decimal[0]);

    LCD_pos(1,16);        LCD_Data('V');

  }

}


void AD_init(){

  ADMUX |= (1<<REFS1)|(1<<REFS0);      //MUX0~4 = 00000

  ADCSRA |= (1<<ADEN)|(1<<ADSC)|(1<<ADFR);          //free running 모드로 동작위해

}

void main(){

  short Voltage = 0;

  AD_init();

  PortInit();             //lcd.h에 있음

  LCD_Init();             //lcd.h에 있음

  //A/D 데이터 전압으로 변환

  LCD_pos(0,0);

  LCD_STR("Voltage : ");

  LCD_pos(1,0);

  LCD_STR("R.Value : "); 

  while(1){

    Voltage = (short)((0.0025 * ADCW) * 10000);

    LCD_Decimal(0,ADCW);  //AD 데이터

    LCD_Decimal(1,Voltage);  //전압값

    delay_ms(100);

  }

}

'학교 > M.P.' 카테고리의 다른 글

문자출력(출력 - 그래픽LCD)  (0) 2015.12.16
방향출력(입력 - 스위치, 출력 - LCD2줄)  (0) 2015.12.16
시간출력(출력 - LCD2줄)  (0) 2015.12.16
LCD출력(출력 - LCD2줄)  (0) 2015.12.16
블로그 이미지

뭐해볼까

,

#include <mega128.h>

#include <delay.h>

#include <LCD.h>


Byte Temp;

Word cnt;

Byte sec, min, hour;


void Init_timer0(){

  TCCR0 |= (1<<WGM01);    //CTC mode

  OCR0 = 100;             //계산/?? -> 200으로 하면 느리게 감

  TIMSK = (1<<OCIE0);     //출력비교 인터럽트 허가

}


interrupt[TIM0_COMP] void tim0_out_comp(){

  cnt++;     //50us * 200 = 1sec

  if(cnt == 20000){

    cnt = 0;

    sec++;

    if(sec>=60){

      min++;

      sec = 0;

    } 

    if(min>=60){

      hour++;

      min = 0;

    }         

    if(hour>=24)

      hour = 0;

  }

}


void main(){

  Byte str[] = "Current Time";

  Byte str1[] = "AM 12:00:00";

  Byte AM[] = "AM";

  Byte PM[] = "PM";

  Temp = 0;

  cnt = 0;

  sec = 0; min = 0, hour = 12;

  //timer 초기화

  Init_timer0();

  sei();

  TCCR0 |= 1<<CS01;       //LCD 초기화

  PortInit();             //lcd 출력포트 실행

  LCD_Init();

  LCD_pos(0,0);           //커서 이동

  LCD_STR(str);

  LCD_pos(1,0);  

  LCD_STR(str1);

  while(1){

    if(hour > 12){

      LCD_pos(1,0);

      LCD_STR(PM);

      LCD_pos(1,3);

      LCD_CHAR((hour-12)/10 + '0');    //0을 더하는 이유는 ASCII값으로 변환을 위해서

      LCD_CHAR((hour-12)%10 + '0');

    }else{

      LCD_pos(1,0);

      LCD_STR(AM);

      LCD_pos(1,3);

      LCD_CHAR((hour/10)+'0');

      LCD_CHAR((hour%10)+'0'); 

    }

    LCD_pos(1,6);

    LCD_CHAR((min/10)+'0');

    LCD_CHAR((min%10)+'0');

    LCD_pos(1,9);         

    LCD_CHAR((sec/10)+'0');

    LCD_CHAR((sec%10)+'0');                

    

  }  

}

블로그 이미지

뭐해볼까

,

#include <mega128.h>

#include <delay.h>

#include <LCD.h>


void main(){

  Byte str[] = "My first text";

  Byte str1[] = "Hello LCD!";

  int i;

  PortInit();

  LCD_Init();

  LCD_pos(0,0);

  LCD_STR(str);

  LCD_pos(1,0);

  LCD_STR(str1);

  while(1){

    for(i = 0;i<16;i++){

      LCD_Shift(RIGHT);

      delay_ms(250);

    }

    for(i = 0;i<16;i++){

      LCD_Shift(LEFT);

      delay_ms(250);

    }               

//    Cursor_Home();

  }

}

블로그 이미지

뭐해볼까

,