I2C problem with CodeVisionAVR

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone,

I have a puzzling question to ask all you experts.

Questions:

1. I compiled the code below for I2C everything's okay no error but there's the assembly error. I don't know what's wrong with my code. I'm using CodeVision AVR evaluation.

Can anyone help me? I would appreciate it very much. Thank you all.

Regards,

Joseph Tjoharno

/*********************************************
This program was produced by the
CodeWizardAVR V1.23.5 Evaluation
Automatic Program Generator
© Copyright 1998-2002 HP InfoTech s.r.l.
http://www.hpinfotech.ro
e-mail:office@hpinfotech.ro , hpinfotech@xnet.ro

Project : FanControl#1
Version : 1.0
Date : 12/4/2002
Author : Joseph Tjoharno
Company :
Comments:
Fan Control using MIC74 and AT90S8515 and I2C

Chip type : AT90S8515
Clock frequency : 4.000000 MHz
Memory model : Small
Internal SRAM size : 512
External SRAM size : 0
Data Stack size : 128
*********************************************/
#include
// I2C Bus & LCD functions
#asm
.equ __lcd_port=0x15 //port C is used for LCD
#endasm

#asm
.equ __i2c_port=0x12 //port D is used for I2C
.equ __sda_bit=3
.equ __scl_bit=4
#endasm

#include
#include
#include
#include

sfrb PORTA=0x1b;
sfrb DDRA=0x1a;
sfrb PINA=0x19;

//sfrb PORTD=0x12;
//sfrb DDRD=0x11;
//sfrb PIND=0x10;

unsigned char mic74_read(unsigned char address){
unsigned char data;
i2c_start();
i2c_write(0x00);
i2c_write(address);
i2c_start();
i2c_write(0x00 | 1);
data=i2c_read(0);
i2c_stop();
return data;
}

void mic74_write(unsigned char address, unsigned char data){

i2c_start();
i2c_write(0x00);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(10);
}

void lcd_display(unsigned char old, unsigned char new)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("fan speed is");
lcd_gotoxy(0,1);
lcd_write_byte(old,new);
}

void main(void)
{
while (1)
{
unsigned char old, new;

i2c_init();
lcd_init(16);
lcd_clear();

old=mic74_read(0x06);
mic74_write(0x06,0x07);
new=mic74_read(0x06);
lcd_display(old,new);
}
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting. I've done many skeletons with the CodeVision Wizard, and was always impressed that it never came up with an error.

How many assembly errors were there? Open the .lst file, and look for "error". If you can't figure it out from there, post a few lines around the error(s), including the relavent C source line above the corresponding machine code lines.

Lede

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CVAVR doesn't like some characters (like raw LF or CR if I recall). Check the .ERR file for exactly what line number is causing the error and make sure you don't have any unusual characters in them. Alternately look at the output of the .ERR file and then at the .LST file.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All you write between #asm ... #endasm is directly included in the .asm file.
The Atmel assembler doesn't like the '//' C comments that you have inserted in the assembly portion of the program generated by the Wizard.
Use ';' instead of '//' :

#asm
.equ __lcd_port=0x15 ;port C is used for LCD
#endasm

#asm
.equ __i2c_port=0x12 ;port D is used for I2C
.equ __sda_bit=3
.equ __scl_bit=4
#endasm

Regards,

Pavel
www.hpinfotech.ro

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you all, and especially Pavel. Thanks for you help. Now the code work. That was so stupid of me.

Thank you again