دوستان سلام
من برای راه اندازی تاچ برنامه زیر رو نوشتم. تو این برنامه قراره که هر وقت دایره قرمز لمس شد ال ای دی که روی portA.4 روشن بشه. در ضمن x , y لمس شده رو هم نمایش بده.این رو که تست میکنم x,y رو درست نشون میده ولی نمیفهمم که چرا وقتی حتی تو رنج گفته شده هم هستن ال ای دی روشن نمیشه.
کدشو این زیر گذاشتم.
لطفا راهنمایی کنید.
من برای راه اندازی تاچ برنامه زیر رو نوشتم. تو این برنامه قراره که هر وقت دایره قرمز لمس شد ال ای دی که روی portA.4 روشن بشه. در ضمن x , y لمس شده رو هم نمایش بده.این رو که تست میکنم x,y رو درست نشون میده ولی نمیفهمم که چرا وقتی حتی تو رنج گفته شده هم هستن ال ای دی روشن نمیشه.
کدشو این زیر گذاشتم.
لطفا راهنمایی کنید.
کد:
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 6/25/2014
Author : PerTic@n
Company : If You Like This Software,Buy It
Comments:
Chip type : ATmega32A
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
*****************************************************/
#define LCD_RST_DDR DDRB
#define LCD_RST_PORT PORTB
#define LCD_RST_PIN 0
#define LCD_RS_DDR DDRB
#define LCD_RS_PORT PORTB
#define LCD_RS_PIN 1
#define LCD_CS_DDR DDRB
#define LCD_CS_PORT PORTB
#define LCD_CS_PIN 2
#define LCD_RD_DDR DDRB
#define LCD_RD_PORT PORTB
#define LCD_RD_PIN 3
#define LCD_WR_DDR DDRB
#define LCD_WR_PORT PORTB
#define LCD_WR_PIN 4
#define LCD_DATAPORT_MSB_DDR DDRD
#define LCD_DATAPORT_MSB_PORT PORTD
#define LCD_DATAPORT_MSB_PIN PIND
#define LCD_DATAPORT_LSB_DDR DDRC
#define LCD_DATAPORT_LSB_PORT PORTC
#define LCD_DATAPORT_LSB_PIN PINC
#define LCD_CONTROLPORT_DDR DDRB
#define LCD_CONTROLPORT_PORT PORTB
#define LCD_CONTROLPORT_PIN PINB
#define PORTRAIT
#include <mega32a.h>
#include <tftlcd_functions.h>
#include <delay.h>
#include <stdlib.h>
#include <stdio.h>
#define saddress 5
// I2C Bus functions
#include <i2c.h>
#define ADC_VREF_TYPE 0x40
int a,b,c=0,d=0,x1;
char lcd_buffer[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)
{
DDRA.0=1;
PORTA.0=1;
DDRA.2=1;
PORTA.2=0;
DDRA.3=0;
PORTA.3=0;
DDRA.1=0;
a=read_adc(1);
delay_ms(30);
return a;
}
int y (void)
{
DDRA.0=0;
PORTA.0=0;
DDRA.1=1;
PORTA.1=1;
DDRA.3=1;
PORTA.3=0;
DDRA.2=0;
b=read_adc(2);
delay_ms(30);
return b;
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x10;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AVCC pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x83;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// I2C Bus initialization
// I2C Port: PORTB
// I2C SDA bit: 6
// I2C SCL bit: 7
// Bit Rate: 100 kHz
// Note: I2C settings are specified in the
// Project|Configure|C Compiler|Libraries|I2C menu.
//i2c_init();
lcd_init();
lcd_background_color(BLACK);
lcd_gotoxy(1,4);
lcd_putsf("Shiva Akbari Melika Emami",RED,0,0);
delay_ms(2000);
lcd_background_color(BLUE);
lcd_draw_circle(120,160,100,1,RED);
lcd_gotoxy(12,9);
lcd_putsf("START",WHITE,RED,0);
while(1){
c=x();
d=y();
lcd_gotoxy(13,18);
sprintf(lcd_buffer,"X=%d ",c);
lcd_puts(lcd_buffer,YELLOW,0,0);
lcd_gotoxy(17,18);
sprintf(lcd_buffer," Y=%d ",d);
lcd_puts(lcd_buffer,YELLOW,0,0);
if((c>=30)&& (c<=80) && (d>=300) && (d<=600))
{
PORTA.4=1;
//x1=1;
}
else{
PORTA.4=0;
// x1=0;
}
/* i2c_start();
i2c_write(saddress);
i2c_write(x1);
i2c_stop();*/
delay_ms(1000);
}
}





(درس و مشق فعالیتمو تو انجمن کم کرده)
دیدگاه