땜쟁이 포럼

A/D 변환 LCD에 쓰기

테라뱅크 0 9,481

//Project:              HkAD.c 

//A/D Use Port:        PORTA PIN0=Read 
//LCD Use Port(DATA):  PORTC Write 
//LCD Use Port(Control):PORTA Write(pin5,6,7) 
//CPU Type:            Atmel AVR8535,8515,103 
//Clock Frequency:      4.9152Mhz 
//Comfiler:            AvrEdit3.1(AVRGCC) 
//Date:                2001/08/05 
//Author:              hwang hae kwon 

//포트A-PIN0 = A/D사용 
//AREF = +5V 
//AGND = GND 
//AVCC= +5V 
//가변저항 왼쪽= +5V 
//가변저항 오른쪽 GND 
//가변저항 중간= 포트A-PIN0번에 결선 합니다. 
// LCD결선은 다 아시죠 생략 합니다. 
//볼륨을 조정 하시면 전압 변동에 따라 0~1024까지 
//숫자로 표시 됩니다. 
//헤더화일은 LCD2*16.H를 이용 하세요. 
#include <io.h> 
#include <interrupt.h> 
#include <signal.h> 
void  delay( int del); 
//--------------------------- 
#define PortA_In_Out DDRA //A 입출력 설정 
#define PortC_In_Out DDRC //C 입출력 설정 
#define LCD_PORT_OUT_Bit PORTA 
#define LCD_PORT_OUT    PORTC 
#define LCD_PORT_INPUT  PINC 
#define LCD_RS          5    // PORT C LCD 4 
#define LCD_RW          6    // PORT C LCD 5 
#define LCD_E          7    // PORT C LCD 6 
#define PORT_IN        0x00  //포트 입력 
#define PORT_OUT      0xff  //포트 출력 
#define LOW_PORT_OUT  0x0f  //하위 포트  출력 
#define HI_PORT_OUT    0xf0  //상위 포트  출력 
//-------------------------------- 
unsigned char HexToAsiic_Map[16] = {"0123456789ABCDEF"}; 
//------- 10진수변환 자리수------------------- 
unsigned char decimal_first_position,decimal_second_position; 
unsigned char decimal_third_position,decimal_fourth_position; 
unsigned char ADCL_low,ADCL_hi; 
//----------------------------- 
void delay(int del) 

while ( del--); 

//------------------------- 
#include <lcd2_16.h> 
//----------------------- 
void  port_init(void) 

outp(0xfe,PortA_In_Out);// A/D 
outp(0x00,ADMUX);  //A/D관련 A-0 PORTA 읽음 
outp(0xe0,ADCSR);  //A/D관련 초기화 
outp(0x01, TIMSK); //Timer0 interrupt허가 
outp(0,  TCNT0);  // reset TCNT0 
outp(5,  TCCR0);  // count with cpu clock/1024 

//--------변환 10진수 자리수4자리로 변환LCD--------- 
void decimal_Chang (long decimal_temp) 

long i; 
unsigned char m,l,h; 
i=decimal_temp; 
l=i/1000; //0000자리 
i%=1000; //나머지 i에저장 
h=i/100; // 000 
i%=100; 
m=i/10;  //  00 
i%=10;  //  0 
decimal_first_position=HexToAsiic_Map[i];//space=0x80 
if(decimal_temp<10) 
  decimal_second_position=0x80; 
else 
  decimal_second_position=HexToAsiic_Map[m]; 
if(decimal_temp<100) 

  decimal_third_position=0x80; 

else 

  decimal_third_position=HexToAsiic_Map[h]; 

if(decimal_temp<1000) 

  decimal_fourth_position=0x80; 

else 

  decimal_fourth_position=HexToAsiic_Map[l]; 

//if(decimal_temp<10000) decimal_fifth_position=0x80; 
// else decimal_fifth_position=HexToAsiic_Map[l]; 

//--------------------- 
SIGNAL(SIG_OVERFLOW0) /* signal handler for tcnt0 overflow interrupt */ 

int i; 
i=inp(ADCH); 
i=(i<<8); 
ADCL_low = inp(ADCL); 
i=(i | ADCL_low); 
decimal_Chang(i); 
lcd_char_out(8,1,decimal_fourth_position); 
lcd_char_out(9,1,decimal_third_position); 
lcd_char_out(10,1,decimal_second_position); 
lcd_char_out(11,1,decimal_first_position); 
outp(0, TCNT0);  //eset counter to get this interrupt again 

//--------------------------- 
int main( void ) 

port_init(); 
lcd_init(); 
lcd_clr(); 
lcd_string_out(0,0,"  A/D Test"); 
sei();// timer interrupt start 
while(1) 


} 

  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기
  • 카카오스토리로 보내기
  • 네이버밴드로 보내기

Comments

번호 분류 제목 글쓴이 날짜 조회 추천
4 팁자료 Hkfnd.c (serial전송 main프로그램) 댓글2 테라뱅크 01.04 9500 0
3 팁자료 key4*4 누른값 LCD에 쓰기 댓글1 테라뱅크 01.04 9311 0
열람중 팁자료 A/D 변환 LCD에 쓰기 테라뱅크 01.04 9482 1
1 팁자료 LCD2*16 글자 써보기 댓글1 테라뱅크 01.04 9317 0
카테고리
최근통계
  • 현재 접속자 4 명
  • 오늘 방문자 943 명
  • 어제 방문자 1,124 명
  • 최대 방문자 2,440 명
  • 전체 방문자 1,084,779 명
  • 전체 회원수 478 명
  • 전체 게시물 745 개
페이스북에 공유 트위터에 공유 구글플러스에 공유 카카오스토리에 공유 네이버밴드에 공유