#include <mega128.h>
#asm
.equ __lcd_port=0x18 ;PORTB
#endasm
#include <lcd.h>
#include <delay.h>
#include <stdio.h>
#define sen_on() PORTA = 0xff
#define sen_off() PORTA = 0x00
#define SENSOR_MODE_ON 1
#define SENSOR_MODE_OFF 2
typedef unsigned char byte;
typedef unsigned int word;
typedef unsigned long dword;
word sensor_input[8];
byte sensor_mode;
int sensor_cnt = 0;
#define ADC_VREF_TYPE 0x00
// ADC interrupt service routine
interrupt [ADC_INT] void adc_isr(void)
{
sensor_input[sensor_cnt] = ADCW;
sensor_cnt++;
switch(sensor_cnt)
{
case 0: ADMUX = 0x00; break;
case 1: ADMUX = 0x01; break;
case 2: ADMUX = 0x02; break;
case 3: ADMUX = 0x03; break;
case 4: ADMUX = 0x04; break;
case 5: ADMUX = 0x05; break;
case 6: ADMUX = 0x06; break;
case 7: ADMUX = 0x07; break;
default: sensor_cnt=0; break;
}
// ADMUX = 0x02; // adc cheannel select
//if(sensor_cnt>=8) sensor_cnt=0;
}
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
if(sensor_mode == SENSOR_MODE_ON) //초기값은 sensor_mode 애 SENSOR_MODE_ON값이 들어가있음.
{ // 60us
sen_on(); //발광 on
delay_us(3); //2~3적당.
ADCSRA|=0x40;
sensor_mode = SENSOR_MODE_OFF; //스위칭 변수.
TCNT3H = 0xff; //start timer
TCNT3L = 0xf1;
}
else if(sensor_mode == SENSOR_MODE_OFF)
{
// 180us
sen_off(); //발광 off
sensor_mode = SENSOR_MODE_ON; // 스위칭 변수.
TCNT3H = 0xff;
TCNT3L = 0xdd; //start timer
}
}
void adc_init(void)
{
ADCSRA = 0x00; //disable adc
ADMUX = ADC_VREF_TYPE; // VRef
ACSR = 0x80;
ADCSRA = 0x8E; // ADC Prescaler 128
}
void main(void)
{
char lcd_buf[16];
DDRA = 0b11111111;
DDRF = 0x00;
lcd_init(16);
TIMSK = 0x04;
TCCR1A = 0x00;
TCCR1B = 0x03; //start timer2, prescale 64
TCNT1H = 0x00;
TCNT1L = 0x00;
//ETIMSK = 0x40; //timer2 compare interupt
sensor_mode = SENSOR_MODE_ON;
adc_init();
#asm("sei");
while (1)
{
lcd_clear();
lcd_gotoxy(0,0);
sprintf(lcd_buf, "%d",sensor_input[3]);
lcd_puts(lcd_buf);
lcd_gotoxy(4,0);
sprintf(lcd_buf, "%d",sensor_input[1]);
lcd_puts(lcd_buf);
lcd_gotoxy(8,0);
sprintf(lcd_buf, "%d",sensor_input[2]);
lcd_puts(lcd_buf);
lcd_gotoxy(0,1);
sprintf(lcd_buf, "%d",sensor_input[7]);
lcd_puts(lcd_buf);
lcd_gotoxy(4,1);
sprintf(lcd_buf, "%d",sensor_input[6]);
lcd_puts(lcd_buf);
lcd_gotoxy(8,1);
sprintf(lcd_buf, "%d",sensor_input[5]);
lcd_puts(lcd_buf);
delay_ms(500); // 0.5초 지연
};
}
이렇게소스코드를짜보았는데 수광부쪽테스트를해봐도 반응이없네요... 소스쪽문제일까요 ㅠㅠ?