سلام
می خوام این تاچ روی یک glcd 128*64 قرار بدم و می خوام که سطر وستون انرا حساب کنم هر کار که می کنم نمی تونم دقیق انرا حساب کنم و حداکثر تامقدار45*105 بدست میاد.لطفا کمک کنید.
************************************************** ***
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega16.h>
#include <alcd.h>
#include <stdio.h>
#include <delay.h>
#define ADC_VREF_TYPE 0xc0
int i;
char lcd[20];
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
int X (void)
{
int b=0;
PORTA=0x02;
DDRA=0x0A;
for(i=0;i<20;i++)
{
b+=read_adc(2);
}
b=(b/20);
b=(b/8); //1024/128=8
delay_ms(50);
return b;
}
int Y (void)
{
int a=0;
PORTA=0x01;
DDRA=0x05;
for(i=0;i<20;i++)
{
a+=read_adc(1);
}
a=(a/20);
a=(a/16); //1024/64=16
delay_ms(50);
return a;
}
void main(void)
{
PORTA=0x00;
DDRA=0x00;
PORTD=0x00;
DDRD=0xff;
// ADC initialization
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: Int., cap. on AREF
// ADC Auto Trigger Source: Free Running
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0xA6;
SFIOR&=0x1F;
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTC Bit 0
// RD - PORTC Bit 1
// EN - PORTC Bit 2
// D4 - PORTC Bit 4
// D5 - PORTC Bit 5
// D6 - PORTC Bit 6
// D7 - PORTC Bit 7
// Characters/line: 16
lcd_init(16);
glcd_clear();
while (1)
{
lcd_gotoxy(0,0);
sprintf(lcd,"x=%d \ny=%d ",X(),Y());
lcd_puts(lcd);
}
}
می خوام این تاچ روی یک glcd 128*64 قرار بدم و می خوام که سطر وستون انرا حساب کنم هر کار که می کنم نمی تونم دقیق انرا حساب کنم و حداکثر تامقدار45*105 بدست میاد.لطفا کمک کنید.
************************************************** ***
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega16.h>
#include <alcd.h>
#include <stdio.h>
#include <delay.h>
#define ADC_VREF_TYPE 0xc0
int i;
char lcd[20];
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
int X (void)
{
int b=0;
PORTA=0x02;
DDRA=0x0A;
for(i=0;i<20;i++)
{
b+=read_adc(2);
}
b=(b/20);
b=(b/8); //1024/128=8
delay_ms(50);
return b;
}
int Y (void)
{
int a=0;
PORTA=0x01;
DDRA=0x05;
for(i=0;i<20;i++)
{
a+=read_adc(1);
}
a=(a/20);
a=(a/16); //1024/64=16
delay_ms(50);
return a;
}
void main(void)
{
PORTA=0x00;
DDRA=0x00;
PORTD=0x00;
DDRD=0xff;
// ADC initialization
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: Int., cap. on AREF
// ADC Auto Trigger Source: Free Running
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0xA6;
SFIOR&=0x1F;
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTC Bit 0
// RD - PORTC Bit 1
// EN - PORTC Bit 2
// D4 - PORTC Bit 4
// D5 - PORTC Bit 5
// D6 - PORTC Bit 6
// D7 - PORTC Bit 7
// Characters/line: 16
lcd_init(16);
glcd_clear();
while (1)
{
lcd_gotoxy(0,0);
sprintf(lcd,"x=%d \ny=%d ",X(),Y());
lcd_puts(lcd);
}
}
دیدگاه