با سلام به دوستان
من در ارتباط زیر به این مشکل برخوردم که همش عدد 987 برایم از at24c08b برگشت داده می شود!
کسی میتونه مشکل اون رو بهم بگه؟؟؟
کدوم پایه at284 رو باید زمین کنم؟(الان پایه a1 رو زمین کردم) ؟؟
کسی نقشه عملی از مدارش داره؟؟؟
/************************************************** ***
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 : 2014/03/16
Author : A
Company : A
Comments:
Chip type : ATmega32
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
************************************************** ***/
#include <mega32.h>
// I2C Bus functions
#include <i2c.h>
// Alphanumeric LCD functions
#include <alcd.h>
#include <stdlib.h>
#include <stdio.h>
#include <twi.h>
#include <delay.h>
int a,i,j;
int h3,h1,h2,l1,l2,l3;
int a1,a2;
char str[100];
//int parameter[]={1,2,3,4,6,7,15,9,16,3};
/* write a byte to the EEPROM */
void eeprom_write(int address,int d) {
h1=address/100;
l1=(address)-(h1*100);
h2=d/100;
l2=d-(h2*100);
i2c_start();
i2c_write(0xa0);
i2c_write(h1);
i2c_write(l1);
i2c_write(h2);
i2c_write(l2);
i2c_stop();
}
/* read a byte from the EEPROM */
int eeprom_read(int address) {
int data;
h3=address/100;
l3=address-(h3*100);
i2c_start();
i2c_write(0xa0);
i2c_write(h3);
i2c_write(l3);
i2c_start();
i2c_write(0xa1);
a1=i2c_read(0);
delay_ms(50);
i2c_start();
i2c_write(0xa1);
a2=i2c_read(0);
i2c_stop();
data=(a1*100)+a2;
return data;
}
// 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=0x00;
// 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=0x0F;
// 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=0xf0;
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 disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// I2C Bus initialization
// I2C Port: PORTC
// I2C SDA bit: 1
// I2C SCL bit: 0
// Bit Rate: 100 kHz
// Note: I2C settings are specified in the
// Project|Configure|C Compiler|Libraries|I2C menu.
i2c_init();
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTA Bit 0
// RD - PORTA Bit 1
// EN - PORTA Bit 2
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 16
lcd_init(16);
eeprom_write(1,123);
delay_ms(5);
eeprom_write(2,456);
delay_ms(5);
eeprom_write(3,987);
delay_ms(5);
/* */
while (1)
{
a=eeprom_read(1);
delay_ms(50);
lcd_clear();
lcd_gotoxy(0,0);
sprintf(str,"%u",a);
lcd_puts(str);
delay_ms(1000);
lcd_clear();
a=eeprom_read(2);
delay_ms(50);
lcd_clear();
lcd_gotoxy(0,0);
sprintf(str,"%u",a);
lcd_puts(str);
delay_ms(1000);
lcd_clear();
a=eeprom_read(3);
delay_ms(50);
lcd_clear();
lcd_gotoxy(0,0);
sprintf(str,"%u",a);
lcd_puts(str);
delay_ms(1000);
lcd_clear();
}
}
من در ارتباط زیر به این مشکل برخوردم که همش عدد 987 برایم از at24c08b برگشت داده می شود!
کسی میتونه مشکل اون رو بهم بگه؟؟؟
کدوم پایه at284 رو باید زمین کنم؟(الان پایه a1 رو زمین کردم) ؟؟
کسی نقشه عملی از مدارش داره؟؟؟
/************************************************** ***
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 : 2014/03/16
Author : A
Company : A
Comments:
Chip type : ATmega32
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
************************************************** ***/
#include <mega32.h>
// I2C Bus functions
#include <i2c.h>
// Alphanumeric LCD functions
#include <alcd.h>
#include <stdlib.h>
#include <stdio.h>
#include <twi.h>
#include <delay.h>
int a,i,j;
int h3,h1,h2,l1,l2,l3;
int a1,a2;
char str[100];
//int parameter[]={1,2,3,4,6,7,15,9,16,3};
/* write a byte to the EEPROM */
void eeprom_write(int address,int d) {
h1=address/100;
l1=(address)-(h1*100);
h2=d/100;
l2=d-(h2*100);
i2c_start();
i2c_write(0xa0);
i2c_write(h1);
i2c_write(l1);
i2c_write(h2);
i2c_write(l2);
i2c_stop();
}
/* read a byte from the EEPROM */
int eeprom_read(int address) {
int data;
h3=address/100;
l3=address-(h3*100);
i2c_start();
i2c_write(0xa0);
i2c_write(h3);
i2c_write(l3);
i2c_start();
i2c_write(0xa1);
a1=i2c_read(0);
delay_ms(50);
i2c_start();
i2c_write(0xa1);
a2=i2c_read(0);
i2c_stop();
data=(a1*100)+a2;
return data;
}
// 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=0x00;
// 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=0x0F;
// 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=0xf0;
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 disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// I2C Bus initialization
// I2C Port: PORTC
// I2C SDA bit: 1
// I2C SCL bit: 0
// Bit Rate: 100 kHz
// Note: I2C settings are specified in the
// Project|Configure|C Compiler|Libraries|I2C menu.
i2c_init();
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTA Bit 0
// RD - PORTA Bit 1
// EN - PORTA Bit 2
// D4 - PORTA Bit 4
// D5 - PORTA Bit 5
// D6 - PORTA Bit 6
// D7 - PORTA Bit 7
// Characters/line: 16
lcd_init(16);
eeprom_write(1,123);
delay_ms(5);
eeprom_write(2,456);
delay_ms(5);
eeprom_write(3,987);
delay_ms(5);
/* */
while (1)
{
a=eeprom_read(1);
delay_ms(50);
lcd_clear();
lcd_gotoxy(0,0);
sprintf(str,"%u",a);
lcd_puts(str);
delay_ms(1000);
lcd_clear();
a=eeprom_read(2);
delay_ms(50);
lcd_clear();
lcd_gotoxy(0,0);
sprintf(str,"%u",a);
lcd_puts(str);
delay_ms(1000);
lcd_clear();
a=eeprom_read(3);
delay_ms(50);
lcd_clear();
lcd_gotoxy(0,0);
sprintf(str,"%u",a);
lcd_puts(str);
delay_ms(1000);
lcd_clear();
}
}
دیدگاه