/*

 * main.c

 *

 * Created: 2015-12-02 오후 4:25:33

 * Author : assist304

 */ 


#include <avr/io.h>

#include "_main.h"

#include "_adc.h"

#include "_glcd.h"


unsigned int Data_ADC0 = 0;


char Dis_Scr_IO_ON[]={"O"};

char Dis_Scr_IO_OFF[]={"X"};

char Dis_Scr1[]={"#$%&'()*+,-./0123456"};

char Dis_Scr2[]={"789:;<=>?@ABCDEFGHIJ"};

char Dis_Scr3[]={"KLMNOPQRSTUVWXYZ[]{}"};


void Port_init(void) // 포트 초기화 구문입니다.

{

PORTA = 0x00; DDRA = 0xFF; // PORTA 출력 LOW ,핀의 출력 설정

PORTB = 0xFF; DDRB = 0b11111111; // PORTB 출력 LOW ,핀의 출력 설정

PORTC = 0x00; DDRC = 0xF0; // PORTC 상위 4bit 입력, 하위 4bit 출력

PORTD = 0x80; DDRD = 0b10000000; // 핀의 입출력 설정

PORTE = 0x00; DDRE = 0xFF; // PORTE 출력 LOW ,핀의 출력 설정

PORTF = 0x00; DDRF = 0x00; // PORTE 출력 LOW ,핀의 출력 설정

}


void init_devices(void) // 초기화 할수를 여기에 넣습니다.

{

cli(); //disable all interrupts


Port_init(); // Port 초기화

Adc_init();

lcd_init();         // initialize GLCD

sei(); //re-enable interrupts

}


int main(void)

{

init_devices();

lcd_clear();

lcd_string(0,0,"====================");

while(1)

{

Data_ADC0 = Read_Adc_Data(0) / 10; // 아날로그 0번 포트 읽기

_delay_ms(200); // 딜레이 200ms

lcd_clear(); // 그래픽 LCD 클리어

ScreenBuffer_clear(); // 스크린 버퍼 클리어

lcd_string(0,0,"ADC0 Potentiometer"); // ADC0 Potentiometer 출력

GLCD_Rectangle(20,0,30,Data_ADC0); // 라인 게이지 출력

lcd_xy(1,0); GLCD_4DigitDecimal(Data_ADC0); // ADC0의 값을 출력

}

}

블로그 이미지

뭐해볼까

,

#include <mega128.h>

#include <delay.h>

#include <lcd.h>


void Switch_Verify(void){       

  Byte Left[] = "LEFT   ";       

  Byte Right[] = "RIGHT  ";        

  Byte Up[] = "UP     ";        

  Byte Down[] = "DOWN   ";       

  Byte Emt[] = "       ";       

  Byte sw;  

  sw = (0x0f & PIND);  

  switch(sw){               

    case 0x0e : {LCD_STR(Left); break;}            

    case 0x0d : {LCD_STR(Right); break;}           

    case 0x0b : {LCD_STR(Up); break;}           

    case 0x07 : {LCD_STR(Down); break;}           

    default : LCD_STR(Emt); break;          

  } 


void main(){

  Byte str1[] = "Push Arrow key";

  Byte str2[] = "State : Plz key";       

  DDRD = 0xF0;  // DIP Switch 입력 설정  

  PortInit();  // LCD 출력 포트 설정        

  LCD_Init();  // LCD 초기화       

  LCD_pos(0,0);  // LCD 포지션 0행 1열 지정       

  LCD_STR(str1);  // 문자열 str을 LCD 출력       

  LCD_pos(1,0);  // LCD 포지션 0행 1열 지정       

  LCD_STR(str2);  // 문자열 str을 LCD 출력  

  while(1){                

    LCD_pos(1,8);               

    Switch_Verify();        

  } 

}

'학교 > 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"


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();

  }

}

블로그 이미지

뭐해볼까

,