Atmega32 with codivisionavr + proteus

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

Hello everyone.

Please, I need of the help with code generated with codevision to atmega32 + lcd, it's working in proteus simulator, but not in physical circuit, was made to simple lcd of 4 bits, any can tell me why this happens, thanks...

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

THINK: What things could possibly be different between the Simulation, and your physical circuit?

 

The most obvious is to check that your physical circuit actually matches what you simulated - isn't it?

 

  • Wiring correct?
  • Correct components?
  • Correct component values?
  • Power supply correct - and turned on!
  • Have you actually programmed the correct code into the chip?
  • etc
  • etc ...

 

Image result for ibm think

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks awneil, the circuit and the schematic in the proteus are the same...

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

Take a picture of your hardware and post it, do you have bypass caps on all vcc/gnd pin pairs? 

Do you have power on all VCC and AVCC pins?

What is your clock source, internal R/C or external Xtal? 

What are your fuse settings? 

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

Often Proteus allows implementations that will not work in the "real" world:

  • Does the uC have proper bypass caps?
  • Are the fuses in the uC properly set?
  • Is the circuit properly grounded?

 

Showing a schematic of your physical system would help us help you.

 

David

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

The board

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

The code..

 


Chip type               : ATmega8535
Program type            : Application
AVR Core Clock frequency: 8,000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 128
*****************************************************/

#include <mega8535.h>

// Alphanumeric LCD Module functions
#include <alcd.h>
#include <delay.h>
// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTA=0x00;
DDRA=0xFF;

// 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 disabled
ADCSRA=0x00;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;

// Alphanumeric LCD initialization
// Connections 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: 8
lcd_init(8);

while (1)
      {
      lcd_puts("Carlos");

      }
}

 

Last Edited: Thu. May 25, 2017 - 01:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In proteus working with 8mhz clock frequêncy.

 

Adding that with both the atmega32 and the atmega8535 this occurs, I'm finding this to be due to lcd, but it's new and I've already switched to another one the same ..

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

Check your pin numbering - eg,  look where pin 40 is:

http://www.atmel.com/images/doc2... - page 2

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. May 25, 2017 - 12:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There seems to be a regulator wired up at the bottom R?/H side of the bread board but I can't see any MANDATORY bypass caps on that just as I can't see any on the chip itself.

 

But then I see that the pot's V+ is coming directly from VA.

 

Please do you drawing EXACTLY as wired up. ALL GND and VCC pins must be wired up and decoupled with bypass caps including AGND and AVCC, this is not optional.

 

EDIT I fixed yous code format, please use the code button when posing code <>, also as it has been pointed out the chip wiring is nothing like the schematic.

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Thu. May 25, 2017 - 01:41 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CarlosConde wrote:
the circuit and the schematic in the proteus are the same...

No - it is now quite clear that they are not!!

 

js wrote:
Please do you drawing EXACTLY as wired up.

It would help if you also posted a photo in which we can see the connections to the LCD - in #6, they are hidden in shadow.

 

Also, if you could get a clear close-up of the connections at the microcontroller

 

please use the code button when posing code <>

Detailed instructions here: https://www.avrfreaks.net/comment...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. May 25, 2017 - 07:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

CarlosConde wrote:
the circuit and the schematic in the proteus are the same...

No - it is now quite clear that they are not!!

 

That^^^^^

 

 

@OP...to start with, and it's not the only error, your schematic shows the LCD connected to Port A but on the breadboard it's on Port C.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

Attachment(s): 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

Brian Fairchild wrote:
your schematic shows the LCD connected to Port A but on the breadboard it's on Port C

+1yes

js wrote:
ALL GND and VCC pins must be wired up and decoupled with bypass caps including AGND and AVCC, this is not optional.

+100

 

(Emphasis mine)

David

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

You could just solder the bypass caps directly to the MCU pins, this way you don't need to be worrying about that when breadboarding, as explained here.

Also they don't take up breadboard space.

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

unless you're a beginner who doesn't know how to solder ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I did this, and I already changed, in the image the wires were for atmega32, and I took the picture before having switched to atmega8535 ..

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

Thanks frog_jr, I see this, and I already changed, but remains the same..

 

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

How on earth do you expect people to help you when you post inaccurate/out-of-date information?!

 

angry

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, start over, show us what you ACTUALLY have wired up, taking note of the suggestions above.   We will not be able to help you if you post one thing but then change to something else!

 

Jim

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

I already changed and it's still the same, the photo was made with atmega8535, but the links were for the previous one that was atmega32..

 

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

But the code and schematic show the LCD connected to port A, the pic shows it connected to port C.   So how can the code drive the LCD connected to the wrong port?

When asked, you said the schematic and the actual hardware where the same, they are not.   Now, where do you think the problem is?

 

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

Is the back light LED connected?

 

edit: (I'm assuming you already corrected your wiring and connected the LCD to port A)

Last Edited: Thu. May 25, 2017 - 02:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm an old technician, concert led televisions, soldering for me ceased to be novelty for at least 40 years ..lol... this kind of problem never happened, it is rare that I have these problems, I asked for help to see if anyone had already I will review everything again, the software and the hardware and see what can be happening, I return with news, thank you all ...

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

Yes, it's working ok, thanks..

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

So, since you have TV repair experience, I suppose you have an oscilloscope, have you checked if the signals are present in the data pins?

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

CarlosConde wrote:

Yes, it's working ok, thanks..

Glad you got it working, come back again if you get stuck with another problem.

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

Ok I will and return, thanks..

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

It did not work, I just replied to friend El Tangas about the back light ...

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

CarlosConde wrote:
I just replied to friend El Tangas about the back light ...

So make that clear by using the 'Quote' button to quote the specific person & point you're replying to ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I already changed and it's still the same, the photo was made with atmega8535, but the links were for the previous one that was atmega32..

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

Brian Fairchild wrote:

awneil wrote:

CarlosConde wrote:
the circuit and the schematic in the proteus are the same...

No - it is now quite clear that they are not!!

 

That^^^^^

 

 

@OP...to start with, and it's not the only error, your schematic shows the LCD connected to Port A but on the breadboard it's on Port C.

 

 

I already changed and it's still the same, the photo was made with atmega8535, but the links were for the previous one that was atmega32..

 

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

awneil wrote:

CarlosConde wrote:
I just replied to friend El Tangas about the back light ...

So make that clear by using the 'Quote' button to quote the specific person & point you're replying to ...

 

 

Sorry, I will, thanks..

 

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

It's generally not useful to quote the entire post - just give enough context to show what you're replying to or commenting on.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, if we are sure of one thing today,  it is that your wiring or fuses are at fault...

 

 

The only change I made to your code was to move the lcd_puts() call to outside the while(1) loop.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

Last Edited: Thu. May 25, 2017 - 04:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

Well, if we are sure of one thing today  it's that your wiring is at fault...

 

 

The only change I made to your code was to move the lcd_puts() call to outside the while(1) loop.

 

 

Thanks, I'll do it and go back..

 

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

I've lost track -- have we verified the row of black boxes?  I.e., has the contrast circuit and level been shown to be correct?

 

https://www.avrfreaks.net/forum/b...

theusch wrote:
Adjust the contrast. You don't say the size of the display. A 2-line moderate-width character LCD that is uninitialized shows black boxes on the top line, and not on the bottom. Adjust your contrast until you see this. Remember I said "uninitialized". Hold your AVR in reset at power-up to enforce that.

...and the rest of that thread, and similar ones...

https://www.avrfreaks.net/comment...

https://www.avrfreaks.net/forum/l...

...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Thu. May 25, 2017 - 08:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Another thing:  Character LCDs start up much slower than an AVR.  Delay some milliseconds after startup before attempting character LCD init.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Finally guys, the pie is ready, the problem was the lcd, I bought 2 and these with defect, I can now continue the code, thanks for your help, I'm available if anybody need....

 

 

 

 

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

That protoboard is an awful setup. I see no bypass capacitors. The crystal should be as close to the appropriate uC pins as possible. Those jumper wires are causing you trouble. Actually, I see the bypass caps are by the crystal. They should be as close to the power pins as possible. I have heard protoboards described as "slabs of trouble". It does no surprise me the circuit does not work.

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

Someguy22 wrote:
Actually, I see the bypass caps are by the crystal.

I think it's more likely that those ones are supposed to be the crystal "burden" capacitors ?

 

Though they're probably pretty pointless on a solderless breadboard - as the usual few pF will be completely swamped by the breadboard.

 

I have heard protoboards described as "slabs of trouble".

laugh

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. May 26, 2017 - 05:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lol... It's is true, I configured with internal rc oscillator and the problem persisted, only after committing another lcd the thing worked...