Newbie Looking for WinAVR to Codevision sourcecode translate

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

Hi...
Can somebody please help me to translate this WinAVR code to Codevision code?
I can't find the header file for the Codevision that used in WinAVR, so I stuck with it...
I got that code from my senior friend, and I still learning to make it works...
Thanks,

BTW here is the WinAVR code:


/*****************************************************************************************
 *  File Name : AVRDotMatrix.c
 *
 *  Created on: Jul 25, 2011
 *      Author: MicroGyro
 *  File Description: Learning Running Text with Atmega8
 ******************************************************************************************/

#include "avr/io.h"
#include "util/delay.h"
#include "avr/pgmspace.h"
#include "string.h"
#include "dotmatrix.h"

/*****************************************************************************************
 * Variable & RAM Mapping
 *****************************************************************************************/
unsigned char text_buffer[100]; //Character to display max. 100
unsigned char display_buffer[700];//100 character need 100*5 character
unsigned int text_length, col_len;
unsigned char scroll_speed;
unsigned int col_count;

/*****************************************************************************************
 * Function Prototype
 *****************************************************************************************/
void toggle_ctr();
void fill_display_buffer();
void show_display();

/*****************************************************************************************
 * Shift register control
 *****************************************************************************************/
void toggle_ctr()
{
	ST_CP_Hi;
	ST_CP_Lo;
	SH_CP_Hi;
	SH_CP_Lo;
}

/*****************************************************************************************
 * Fill display buffer, read text to display, get text data from table, save to display buffer
 *****************************************************************************************/
void fill_display_buffer()
{
	unsigned int x,c,i;
	unsigned int digit;
	unsigned char str_temp;

	c = 0;
	 for(digit=0;digit4)
	  {
		c=0;
		for (r=1;rcol_len) col_count = 0;
	  }
	 else
	  {
	   for(col_count=0;col_count

I don't know why I'm still doing this hobby

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

I suspect that you have another file(s) in your project alled "dotmatrix.c" and "dotmatrix.h".

Otherwise, the edits are pretty straightforward.


remove

e.g.

#include 
#include 
#include 
#define DELAY_US(us)		delay_us(us)
#define DELAY_MS(ms)		delay_ms(ms)
#define _BV(x)			(1<<(x))
#define PGM_P  			char flash *
#define PROGMEM			flash
#define PSTR(x)			x
#define pgm_read_byte(x)	(*((uint8_t flash *)(x)))
#define pgm_read_word(x)	(*((uint16_t flash *)(x)))

If you had posted the full code, I could have checked it compiled.

David.

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

AFAICS the ONLY thing you need to change in that is the _delay_ms() calls to be delay_ms().

Of course you haven't shown the local header files.

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

david.prentice wrote:
I suspect that you have another file(s) in your project alled "dotmatrix.c" and "dotmatrix.h".

Otherwise, the edits are pretty straightforward.


remove

e.g.

#include 
#include 
#include 
#define DELAY_US(us)		delay_us(us)
#define DELAY_MS(ms)		delay_ms(ms)
#define _BV(x)			(1<<(x))
#define PGM_P  			char flash *
#define PROGMEM			flash
#define PSTR(x)			x
#define pgm_read_byte(x)	(*((uint8_t flash *)(x)))
#define pgm_read_word(x)	(*((uint16_t flash *)(x)))

If you had posted the full code, I could have checked it compiled.

David.

Thanks David for your reply...
I asked my friend for the "dotmatrix.c" and 'dotmatrix.h" files, but it's seems only the "dotmatrix.h" file and a hex file left... It's about 2 years ago project... he don't know where to find it now...
I've tried the schematics in proteus with the hex file and it works fine, but I can't do anything with it...

I don't know how to attached the proteus and hex files here?

Here is the dotmatix.h file:


#ifndef DOTMATRIX_H_
#define DOTMATRIX_H_

#include "avr/pgmspace.h"
#include "avr/io.h"

#define SH_CP_Hi PORTC |= (1<<1)
#define SH_CP_Lo PORTC &=~(1<<1)
#define ST_CP_Hi PORTC |= (1<<2)
#define ST_CP_Lo PORTC &= ~(1<<2)
#define DS_Hi    PORTC |= (1<<0)
#define DS_Lo    PORTC &= ~(1<<0)
#define DATA_PORT PORTB

const char text_data[] PROGMEM ={
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0,
0 , 0 , 95 , 0 , 0,
0 , 7 , 0 , 7 , 0,
20 , 127 , 20 , 127 , 20,
36 , 42 , 127 , 42 , 18,
39 , 21 , 107 , 84 , 114,
54 , 73 , 86 , 32 , 80,
0 , 0 , 11 , 7 , 0,
0 , 28 , 34 , 65 , 0,
0 , 65 , 34 , 28 , 0,
42 , 28 , 127 , 28 , 42,
8 , 8 , 62 , 8 , 8,
0 , 88 , 56 , 0 , 0,
8 , 8 , 8 , 8 , 8,
0 , 96 , 96 , 0 , 0,
32 , 16 , 8 , 4 , 2,
62 , 81 , 73 , 69 , 62,
0 , 66 , 127 , 64 , 0,
114 , 73 , 73 , 73 , 70,
34 , 65 , 73 , 73 , 54,
24 , 20 , 18 , 127 , 16,
39 , 69 , 69 , 69 , 57,
60 , 74 , 73 , 73 , 48,
1 , 113 , 9 , 5 , 3,
54 , 73 , 73 , 73 , 54,
6 , 73 , 73 , 41 , 30,
0 , 54 , 54 , 0 , 0,
0 , 91 , 59 , 0 , 0,
8 , 20 , 34 , 65 , 0,
20 , 20 , 20 , 20 , 20,
0 , 65 , 34 , 20 , 8,
2 , 1 , 81 , 9 , 6,
50 , 73 , 121 , 65 , 62,
124 , 18 , 17 , 18 , 124,
65 , 127 , 73 , 73 , 62,
62 , 65 , 65 , 65 , 34,
65 , 127 , 65 , 65 , 62,
127 , 73 , 73 , 65 , 65,
127 , 9 , 9 , 1 , 1,
62 , 65 , 73 , 73 , 58,
127 , 8 , 8 , 8 , 127,
0 , 65 , 127 , 65 , 0,
32 , 64 , 65 , 63 , 1,
127 , 8 , 20 , 34 , 65,
127 , 64 , 64 , 64 , 64,
127 , 2 , 12 , 2 , 127,
127 , 2 , 4 , 8 , 127,
62 , 65 , 65 , 65 , 62,
127 , 9 , 9 , 9 , 6,
62 , 65 , 65 , 33 , 94,
127 , 9 , 25 , 41 , 70,
38 , 73 , 73 , 73 , 50,
1 , 1 , 127 , 1 , 1,
63 , 64 , 64 , 64 , 63,
7 , 24 , 96 , 24 , 7,
127 , 32 , 24 , 32 , 127,
99 , 20 , 8 , 20 , 99,
3 , 4 , 120 , 4 , 3,
97 , 81 , 73 , 69 , 67,
0 , 127 , 65 , 65 , 0,
2 , 4 , 8 , 16 , 32,
0 , 65 , 65 , 127 , 0,
4 , 2 , 1 , 2 , 4,
64 , 64 , 64 , 64 , 64,
0 , 0 , 7 , 11 , 0,
32 , 84 , 84 , 84 , 56,
127 , 40 , 68 , 68 , 56,
0 , 56 , 68 , 68 , 68,
56 , 68 , 68 , 40 , 127,
56 , 84 , 84 , 84 , 24,
8 , 126 , 9 , 9 , 2,
8 , 84 , 84 , 84 , 60,
127 , 16 , 8 , 8 , 112,
0 , 68 , 125 , 0 , 0,
32 , 64 , 68 , 61 , 0,
0 , 127 , 16 , 40 , 68,
0 , 65 , 127 , 64 , 0,
124 , 4 , 120 , 4 , 120,
124 , 8 , 4 , 4 , 120,
56 , 68 , 68 , 68 , 56,
124 , 20 , 20 , 20 , 8,
8 , 20 , 20 , 20 , 124,
124 , 8 , 4 , 4 , 8,
72 , 84 , 84 , 84 , 36,
0 , 4 , 63 , 68 , 68,
60 , 64 , 64 , 32 , 124,
28 , 32 , 64 , 32 , 28,
60 , 64 , 60 , 64 , 60,
68 , 40 , 16 , 40 , 68,
12 , 80 , 80 , 80 , 60,
68 , 100 , 84 , 76 , 68,
0 , 8 , 54 , 65 , 0,
0 , 0 , 119 , 0 , 0,
0 , 65 , 54 , 8 , 0,
2 , 1 , 2 , 4 , 2,
42 , 85 , 42 , 85 , 42};
#endif /* DOTMATRIX_H_ */

I don't know why I'm still doing this hobby

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

I've tried to compile the code and there's an error said "need array size"...
And it's pointing at the header file "dotmatrix.h" L15 which is:

const char text_data[] PROGMEM ={ 

What is that means?

I don't know why I'm still doing this hobby

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

Quote:
I asked my friend for the "dotmatrix.c" and 'dotmatrix.h" files, but it's seems only the "dotmatrix.h" file and a hex file left
You will NOT be able to build this project without all of the sources.
Quote:
What is that means?
CodeVision uses a different way to do that.

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

I have compiled the source. No way could it have run on a Mega8.
Only a Mega16 has enough SRAM memory.

#if defined(__CODEVISIONAVR__)
#include 
#include 
#include 
#define DELAY_US(us)      delay_us(us)
#define _delay_ms(ms)      delay_ms(ms)
#define _BV(x)         (1<<(x))
#define PGM_P           char flash *
#define PROGMEM         flash
#define PSTR(x)         x
#define pgm_read_byte(x)   (*((uint8_t flash *)(x)))
#define pgm_read_word(x)   (*((uint16_t flash *)(x))) 
#else
#include "avr/io.h"
#include "util/delay.h"
#include "avr/pgmspace.h"
#endif
...
void main()    // .kbv
...

dotmatrix.h

//#include "avr/pgmspace.h"  //.kbv
//#include "avr/io.h"        //.kbv
...
//const char text_data[] PROGMEM ={ //.kbv
char PROGMEM text_data[] ={	//.kbv
...

I can see no reason for your massive array sizes:

unsigned char text_buffer[100]; //Character to display max. 100
unsigned char display_buffer[700];//100 character need 100*5 character

reduce these and it will fit in a Mega8

David.

Last Edited: Mon. Jul 25, 2011 - 01:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gregsmithcts wrote:
Quote:
I asked my friend for the "dotmatrix.c" and 'dotmatrix.h" files, but it's seems only the "dotmatrix.h" file and a hex file left
You will NOT be able to build this project without all of the sources.
Quote:
What is that means?
CodeVision uses a different way to do that.

:shock: :roll:
OMG
:shock: :roll:

So how am I suppose to learn to build a moving text project? :roll: :roll: :roll:

I don't know why I'm still doing this hobby

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

Quote:
So how am I suppose to learn to build a moving text project?

Perhaps you have all the source(s) you need. i.e. there is no "dotmatrix.c" ;)

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

David:
Thanks, that means I got the wrong code to fit atmega8, and I don't know why the array was so much... That was the code that I got and I want to learn for this project...
Well... I guess I've some homeworks to do before actually build the hardware... :)

gregsmithcts:
yeah... that's what I'm trying to do... to get the "real code" :)

I don't know why I'm still doing this hobby

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

I threw away my dot-matrix printer a couple of years ago.

They all contain fonts in ROM. So I can see little sense in using an AVR to send patterns of dots.

Yes, it speeds things up to write a full horizontal line of bit-patterns, but you can always re-seek to part of the line.

Anyway, my last printer had a pretty big internal buffer. You just poke bytes at the i/f all the time that it does not say it is BUSY.

In fact I think that I wrote a 'print text in landscape' mode program some years ago that created and downloaded a landscape font to the printer. You only had to 'print' the letters from columns rather than rows.

David.

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

Quote:

So I can see little sense in using an AVR to send patterns of dots.

Does the font in ROM support Kanji or Sanscrit or Mandarin or Aramaic ... ?

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

I'm not sure, but I think you guys are assuming this is for a printer? Judging by the OP and some comments in the code, I think he's looking to build one of those scrolling LED displays.

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

gregsmithcts:
yeah you are right... It's not for a printer... just moving text on 40x8 dot matrix led project... :)

I don't know why I'm still doing this hobby

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

If the output device is 40x8 then there is absolutely no need for enormous buffers.
A 7x5 font is only going to have 7 letters on view at any time. So you only need to build 7 bit-patterns for the hardware to multiplex.

You probably like to work with a 'wider' buffer so you can scroll left and right easily.

So a mega8 with 512 bytes of SRAM would be fine. You possibly store messages in eeprom too, but use the SRAM for display.

David.

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

David:
Thanks, I have to figure it out how it works... that's why I start with the code that seems a "wrong" code to
learn... :(

Here is the schematics I captured:

Attachment(s): 

I don't know why I'm still doing this hobby

Last Edited: Tue. Jul 26, 2011 - 11:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's stange the other image couldn't show up???

I don't know why I'm still doing this hobby

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

Your image tags are in the wrong order in the previous post. /img .... img should be img ... /img.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

You can edit any of your posts to correct the URL or IMG tags.

Your JPEGs are too small for me to read, but I am guessing that you are putting the row data on the mega8, and clocking the columns via shift registers.

You can compile your software for a mega8 if you use text_buffer[100] and display_buffer[500]. Note that you need to set the 'data stack' to 80 or so.

David.

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

David:
Thanks, that's right... mega8 for the row and shift register for the column...
I've tried to compile the code using WinAVR, and put it in the proteus... but the row part just sit down and do nothing... the column part running around as it can be seen in the virtual scope...
Still working on it...

I don't know why I'm still doing this hobby

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

It compiles with WinAvr too.

I presume that you have a full licence to use Proteus via your school.

Proteus should be equally happy with a CodeVision COFF file or a GCC ELF file.
The difficult part is drawing the Proteus schematic.

I presume that someone else has the code running on real hardware. I have never even looked at the code. I simply added the CodeVision conditional macros an compiled.

I have no Proteus licence, nor any desire to build a lot of hardware.

If you are worried about a bug in the program, you would need to show some Proteus screenshots.

David.

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

david.prentice wrote:
It compiles with WinAvr too.
I presume that someone else has the code running on real hardware.

yeah... you are right... that's why I used that code and schematic to start to... but no luck till now.. :(

Quote:

If you are worried about a bug in the program, you would need to show some Proteus screenshots.

It didn't even "run" or show "a dot"...
I posted above the screenshot of proteus schematics, but no "display" at all because nothing to display when I played the sim...

I don't know why I'm still doing this hobby

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

Finally... I could make it display "fix text" with edited code in Codevision compiler...
Still more code to deal with... @_@
Here's my progress...
http://www.youtube.com/watch?v=Z54FqOEMzWQ

I don't know why I'm still doing this hobby

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

Your video showed it working.

There appeared to be the odd pause or glitch.

This could be Proteus.

What was your original problem?

David.

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

David:
yeah you are right... the sim didn't run in real time...
My original problem was the original code supposed to display "any text or word" that we "type it in the code"... but nothing happened when it played in the sim... and I didn't know how to fix it... because no error showed when it compiled... (and I'm not good in WinAVR)
I just made "some text code" to displayed some text... it was not supposed to work that way... just "type" the text or word we want and it will be displayed... not "made" the "text code" one by one...
I just trial and error at the code to make the display working... but i didn't know how to make the "original idea of the code" work as it supposed to...

I don't know why I'm still doing this hobby

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

Simulators are not always that good at simulating a Terminal.

I will take a look after I have been out for a walk with my dog.

David.

Edit. I have had a swift look at the code.
1. it makes no attempt to receive any user input.
2. it does the display in the foreground code. i.e. not interrupts.

You can easily add support for a UART and connect to a Terminal. Then you can type letters on your keyboard.

You can use interrupts to send the data to the display. e.g. have a regular 2ms timer IRQ. In the ISR() you increment the row, enable the appropriate row, and send the 5 bytes of column data via SPI to the shift registers, latch them.

Your ISR() need only take about 50us to do all that. Since you have 1950us before the next IRQ, you would not even notice it.

Your foreground code would watch the UART, process any special effects etc. The ISR() displays whatever dots you have put in the display_buffer[].

It looks quite fun. I wish I had Proteus!

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

David:
Thanks a lot David... I'll try it...

Now I had the answer that "that code" only displayed the "text" coded in the dotmatrix.h... not displayed any text we put it in... that's the original problem...
It's time to get rid of that code and try to make it as you said... :)

Proteus helped a lot to realizing my ideas about building microcontroller projects... I'm still a newbie... So it's easier for me to figure out whats wrong with my codes... especially when working with servo pulses or PWM... Yeah that's really fun... :)

I hope I can post my progress soon... :)
And I hope you didn't get bored with my questions... :)

I don't know why I'm still doing this hobby

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

MicroGyro wrote:
David:
Thanks, I have to figure it out how it works... that's why I start with the code that seems a "wrong" code to
learn... :(

Here is the schematics I captured:

I would dearly like to read your schematic. It is far too small on my PC screen.

I adapted your prog to display a circle or a space per 'LED' on a Terminal since I have no Proteus. It scrolls away nicely.

However your prog is designed to send out 8 bits of row data to a PORT, then the row data for the next column etc.

Your hardware 'looks' as if you would send 40 bits of column data to the '595s as five 8-bit spi. Then do the same for the next row ...
Yet your prog is not organised this way at all.

How did you get your working video?

David.

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

MicroGyro wrote:
That's stange the other image couldn't show up???

This is the "zoom in" of that schematics I posted above... (it's supposed to be 640x480 size, but you can save it and zoom it inside windows viewer)...

Maybe I should use "label" for that many wire than complete wiring like that... (but it's easier for me to look that way :) )

I've captured that video after I "confused" by the code, and I figured out the "part" of the code that used to display the 8 bit... and that was the result...

I've captured my codevision source code in that video too... (pause to read the code :) )

Anyway... here's the source code I edited:


Chip type           : ATmega8
Program type        : Application
Clock frequency     : 4,000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/

#include 
#include 
#include 
#include 

#define SH_CP_Hi (PORTC.1=1)
#define SH_CP_Lo (PORTC.1=0)
#define ST_CP_Hi (PORTC.2=1)
#define ST_CP_Lo (PORTC.2=0)
#define DATA_PORT (PORTB)
#define DS_Hi (PORTC.0=1)
#define DS_Lo (PORTC.0=0)

unsigned int text_length=7;  // start moving
unsigned int col_len=100;   // number of col shift to outleft
unsigned char scroll_speed=2;
unsigned int col_count;
//unsigned char display_buffer[300];

// Declare your global variables here

unsigned char display_buffer[160] = { 
                                    0b00000000,  // blank
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    0b00000000,
                                    
                                    0b00000000,  // *
                                    0b00001000,
                                    0b00101010,
                                    0b00010100,
                                    0b01100011,
                                    0b00010100,
                                    0b00101010,
                                    0b00001000,
                                    
                                    0b00000000,  // A
                                    0b01111100,
                                    0b00010010,
                                    0b00010001,
                                    0b00010010,
                                    0b01111100,
                                    
                                    0b00000000,  // V
                                    0b00011111,
                                    0b00100000,
                                    0b01000000,
                                    0b00100000,
                                    0b00011111,
                                                                        
                                    0b00000000,  // R
                                    0b01111111,
                                    0b00001001,
                                    0b00011001,
                                    0b00101001,
                                    0b01000110,
                                    
                                    0b00000000,  // *
                                    0b00001000,
                                    0b00101010,
                                    0b00010100,
                                    0b01100011,
                                    0b00010100,
                                    0b00101010,
                                    0b00001000,
                                    0b00000000,
                                    
                                    0b00000000,  // F
                                    0b01111111,
                                    0b00001001,
                                    0b00001001,
                                    0b00001001,
                                    0b00000001,
                                    
                                    0b00000000,  // r
                                    0b01111100,
                                    0b00001000,
                                    0b00000100,
                                    0b00000100,
                                    0b00001000,
                                    
                                    0b00000000,  // e
                                    0b00111000,
                                    0b01010100,
                                    0b01010100,
                                    0b01010100,
                                    0b00011000,
                                                                        
                                    0b00000000,  // a
                                    0b00100000,
                                    0b01010100,
                                    0b01010100,
                                    0b01010100,
                                    0b01111000,
                                    
                                    0b00000000,  // k
                                    0b01111111,
                                    0b00010000,
                                    0b00101000,
                                    0b01000100,
                                                                       
                                    0b00000000,  // s
                                    0b01001000,
                                    0b01010100,
                                    0b01010100,
                                    0b01010100,
                                    0b00100000
                                                                     
                                   };
   
void toggle_ctr()
        {       
        ST_CP_Hi;
	ST_CP_Lo;
        SH_CP_Hi;
	SH_CP_Lo;
        }

void show_display()
{
	unsigned int x,c,i,r;
	unsigned int mychar;

	 if (text_length>6) // text moving left
	  {
		c=0;
		for (r=1;rcol_len) col_count = 0;
	   }
	 else // text stay not moving left
	  {
	   for(col_count=0;col_count

Then you just run the "show_display" function... whoalaa... that's it... :)

I want to build the 40x8 LED matrix to see the hardware result... but it have to wait until the code "fixed"... or else this project useless... :(

My goal is, I can edit the display text (via keyboard maybe) and save it in the Mega8 for self running...

I don't know why I'm still doing this hobby

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

It is very simple to change the text.

    char str1[] = "  Hello, I making running text using ATMEGA8.";
    ...
    strcpy(text_buffer, str1);
    text_length = strlen(str1);
    col_len = text_length * 6;
    fill_display_buffer();
    ...

Once you have added a UART, you can use a terminal.

    printf("enter text:");
    gets(text_buffer, 100);
    text_length = strlen(text_buffer);   // .kbv edited
    col_len = text_length * 6;
    fill_display_buffer();
    ...

Obviously you can create a function that sets the global variables and fills the display_buffer[] in one go.

Your Proteus simulation (that I still cannot read) is a good example of something that will not work in real life. Single step the Proteus simulation, and you will see one column being illuminated at any one time.

For an average 4mA current in a single LED, you need to have 160mA for 1/40 of the frame period. Typical LED matrix have a maximum peak current of 100mA. The HC595 has a maximum o/p current of 35mA. If you have all 8 LEDs in a column lit, you have a peak current of 1280mA.

If you multiplex 40 LEDs with a 1/8 period, each HC595 o/p supplies 32mA peak. The row driver supplies 1280mA if all 40 LEDs in a row are lit.

However this means that you put the row data into the display_buffer rather than the column data.

David.

Last Edited: Sat. Jul 30, 2011 - 06:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
It is very simple to change the text.

    char str1[] = "  Hello, I making running text using ATMEGA8.";
    ...
    strcpy(text_buffer, str1);
    text_length = strlen(str1);
    col_len = text_length * 6;
    fill_display_buffer();
    ...

Once you have added a UART, you can use a terminal.

    printf("enter text:");
    gets(text_buffer, 100);
    text_length = strlen(str1);
    col_len = text_length * 6;
    fill_display_buffer();
    ...

Obviously you can create a function that sets the global variables and fills the display_buffer[] in one go.


That means I have to learn UART first... I haven't make any UART code... :)

Quote:

Your Proteus simulation (that I still cannot read) is a good example of something that will not work in real life. Single step the Proteus simulation, and you will see one column being illuminated at any one time.

The schematics was too large for single screen... If you really need it I'll make it using label rather than complex wire... (and hope it will fit one screen)

Quote:

For an average 4mA current in a single LED, you need to have 160mA for 1/40 of the frame period. Typical LED matrix have a maximum peak current of 100mA. The HC595 has a maximum o/p current of 35mA. If you have all 8 LEDs in a column lit, you have a peak current of 1280mA.

If you multiplex 40 LEDs with a 1/8 period, each HC595 o/p supplies 32mA peak. The row driver supplies 1280mA if all 40 LEDs in a row are lit.


I thought the real hardware must be using buffer or switch TR for each row and column side... and it using 1.5A of switching regulator supply if I'm not wrong...

Quote:

However this means that you put the row data into the display_buffer rather than the column data.

David.


I thought that's the way it works... the column data was single bit only right? the row data was 8 bit...

I don't know why I'm still doing this hobby

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

If you use the code as currently organised, you would need 40 column drivers as well as your existing transistor row drivers. As you see from my maths, they need to handle a big current too (1.5A). And buy non-standard LED matrix. (or seriously limit the average LED intensity)

In practice a 1/8 multiplex is easy to do, and does not involve horrific currents. A 1/40 multiplex needs a very short period because you still need the whole 'frame' to be re-drawn 25 times a second.

The hardware that you have in the Proteus schematic can be used in the 'sensible' 1/8 multiplex manner. The HC595 can manage the currents within spec. The LED matrix is in spec.

Yes. You will need to learn how to use the UART. Generally 'hello world' to a Terminal is one's first project.

When you have done some practice with the UART, I will post you code that drives your hardware in 1/8 mode. You will be able to see it work in Proteus.

Personally, I would use the ATmega8's SPI pins for the HC595s. And I would use PORTC and PORTD for the row pins. It does not really matter for Proteus. You just alter the schematic with a mouse. Re-wiring a breadboard is fairly easy too. If you are soldering, you need to choose your pins first, cos it is hard work to change afterwards.

David.

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

I had made my dotmatrix displaying about 90 characters long if I used mega8... and 200 characters long with mega32...

What I couldn't figure out was " I compiled and used the same code with WinAVR several times and it didn't "work" at all"...
I tried to use AVR Studio 4 to compiled the same code (with 1 warning but it build), and I put it in the Proteus, and it "work" !!!
After that I pasted the code in CVAVR with minor adjustment(took me few days to figure it out, actually this was the first reason I posted this thread), and it can "work" too...
So I decided to re-install the WinAVR, but I haven't try it again...

Now I'm learning how to use SPI pins for the registers with PORTC and PORTD as rows... :wink:

I forgot the UART things... sorry... :oops:

I don't know why I'm still doing this hobby